diff --git a/backend/service/functions/semester.go b/backend/service/functions/semester.go index 442855e..d6a6e6d 100644 --- a/backend/service/functions/semester.go +++ b/backend/service/functions/semester.go @@ -45,6 +45,11 @@ func GetSemesterStart(date time.Time) time.Time { } } +// Check if is in last month of semester +func IsLastMonthOfSemester(date time.Time) bool { + return date.Month() == START_OF_WINTER_SEMESTER_MONTH-1 || date.Month() == START_OF_SUMMER_SEMESTER_MONTH-1 +} + // Check if the given date is before the start of summer semester func isBeforeSummerSemester(date time.Time) bool { return date.Month() < START_OF_SUMMER_SEMESTER_MONTH diff --git a/backend/service/room/roomService.go b/backend/service/room/roomService.go index 67619db..d2f18b5 100644 --- a/backend/service/room/roomService.go +++ b/backend/service/room/roomService.go @@ -74,6 +74,10 @@ func GetRoomOccupancyList(app *pocketbase.PocketBase, granularity int) (model.Ro fromTime := functions.GetSemesterStart(now) toTime := functions.GetSemesterStart(now.AddDate(0, 6, 0)) + if functions.IsLastMonthOfSemester(now) { + toTime = functions.GetSemesterStart(now.AddDate(1, 0, 0)) + } + // calculate the number of blocks for the given time range and granularity timeDifference := toTime.Sub(fromTime) numberOfBlocks := int(math.Ceil(timeDifference.Minutes() / float64(granularity)))