From 6de2ce981527b1c2c6e3cd77babacfe32cfea0f4 Mon Sep 17 00:00:00 2001 From: Nicholas Novak <34256932+NickyBoy89@users.noreply.github.com> Date: Thu, 23 Nov 2023 00:33:05 -0800 Subject: [PATCH] fix: Fixed current course lookups not working, and added a test to prevent it --- schedule.go | 5 ++++- schedule_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 schedule_test.go 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) + } +}