feat:#22 refactor to cache room schedule and webworker config

This commit is contained in:
survellow
2024-08-02 23:55:58 +02:00
parent e4bde20397
commit 4fcfa76e1c
14 changed files with 164 additions and 83 deletions

View File

@@ -16,15 +16,41 @@
package functions
import "time"
import (
"time"
)
const START_OF_SUMMER_SEMESTER_MONTH = time.April
const START_OF_WINTER_SEMESTER_MONTH = time.October
// GetCurrentSemesterString returns the current semester as string
// if current month is between 10 and 03 -> winter semester "ws"
func GetCurrentSemesterString() string {
if time.Now().Month() >= 10 || time.Now().Month() <= 3 {
if now := time.Now(); isBeforeSummerSemester(now) || isAfterSummerSemester(now) {
return "ws"
} else {
return "ss"
}
}
// GetSemesterStart gibt das Startdatum des aktuellen Semesters zurück
func GetSemesterStart(date time.Time) time.Time {
if isBeforeSummerSemester(date) {
return time.Date(date.Year()-1, START_OF_WINTER_SEMESTER_MONTH, 1, 0, 0, 0, 0, date.Location())
} else if isAfterSummerSemester(date) {
return time.Date(date.Year(), START_OF_WINTER_SEMESTER_MONTH, 1, 0, 0, 0, 0, date.Location())
} else {
return time.Date(date.Year(), START_OF_SUMMER_SEMESTER_MONTH, 1, 0, 0, 0, 0, date.Location())
}
}
// 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
}
// Check if the given date is after the end of summer semester
func isAfterSummerSemester(date time.Time) bool {
return date.Month() >= START_OF_WINTER_SEMESTER_MONTH
}