Files
LehrerApp/LehrerApp.Core/Services/SchoolYearService.cs
T
2026-06-19 00:42:00 +02:00

23 lines
787 B
C#

namespace LehrerApp.Core.Services;
public class SchoolYearService
{
public string CurrentSchoolYear()
{
var now = DateTime.Today;
return FormatSchoolYear(now.Month >= 8 ? now.Year : now.Year - 1);
}
public string FormatSchoolYear(int startYear) =>
$"{startYear}/{(startYear + 1) % 100:D2}";
public DateOnly SchoolYearStart(string sy) =>
new(int.Parse(sy.Split('/')[0]), 8, 1);
public DateOnly SchoolYearEnd(string sy) =>
new(int.Parse(sy.Split('/')[0]) + 1, 7, 31);
public List<string> RecentSchoolYears(int count = 5)
{
var now = DateTime.Today;
var cur = now.Month >= 8 ? now.Year : now.Year - 1;
return Enumerable.Range(0, count).Select(i => FormatSchoolYear(cur - i)).ToList();
}
}