mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-07 04:09:17 +02:00
feat:#22 refactor to cache room schedule and webworker config
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user