//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. //Copyright (C) 2024 HTWKalender support@htwkalender.de //This program is free software: you can redistribute it and/or modify //it under the terms of the GNU Affero General Public License as published by //the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. //This program is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU Affero General Public License for more details. //You should have received a copy of the GNU Affero General Public License //along with this program. If not, see . package functions 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 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 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 } // 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 }