diff --git a/schedule.go b/schedule.go index ea25352..6dcfe06 100644 --- a/schedule.go +++ b/schedule.go @@ -29,7 +29,10 @@ type Schedule struct { // // If no course is found, the error will be of type `ErrNoCurrentCourse` func (s Schedule) CurrentCourse() (string, error) { - currentTime := time.Now() + currentTime, err := time.Parse(time.Kitchen, time.Now().Format(time.Kitchen)) + if err != nil { + return "", err + } for courseName, courseInfo := range s.Courses { startTime, err := time.Parse(time.Kitchen, courseInfo.StartTime) diff --git a/schedule_test.go b/schedule_test.go new file mode 100644 index 0000000..785fba8 --- /dev/null +++ b/schedule_test.go @@ -0,0 +1,28 @@ +package coursed + +import ( + "testing" + "time" +) + +func TestSingleCourse(t *testing.T) { + testSch := Schedule{ + Courses: map[string]CourseConfig{ + "ubw101": CourseConfig{ + StartTime: time.Now().Add(time.Minute * -5).Format(time.Kitchen), + EndTime: time.Now().Add(time.Minute * 10).Format(time.Kitchen), + Days: "MWF", + }, + }, + } + + // TODO: Fix this + cur, err := testSch.CurrentCourse() + if err != nil { + t.Errorf("Error getting current course: %v", err) + } + + if cur != "ubw101" { + t.Errorf("Expected current course to be ubw101, got %s", cur) + } +}