Fix month selection (#53)

* Clear old shifts when switching

* Start with monday
This commit is contained in:
Claudio Schaad 2025-09-27 11:34:21 +02:00 committed by GitHub
parent a341a5fec0
commit 6f73aca3f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -310,6 +310,8 @@ namespace ShiftScheduler.Client.Pages
private async Task ReloadTransportDataForSchedule()
{
SelectedShiftsWithTransport.Clear();
foreach (var kvp in SelectedSchedule)
{
var day = kvp.Key;

View file

@ -23,9 +23,11 @@ public record MonthAndYear(int Month, int Year)
public IReadOnlyList<DateTime> DaysInMonth()
{
return Enumerable.Range(1, DateTime.DaysInMonth(Year, Month))
var dayList = Enumerable.Range(1, DateTime.DaysInMonth(Year, Month))
.Select(d => new DateTime(Year, Month, d))
.ToList();
return EnsureStartsOnMonday(dayList);
}
public IReadOnlyDictionary<int, List<DateTime>> GetWeeksInMonth()
@ -36,4 +38,23 @@ public record MonthAndYear(int Month, int Year)
.ToDictionary(d => d.Key, d => d.ToList());
return weeks;
}
static List<DateTime> EnsureStartsOnMonday(List<DateTime> dates)
{
var firstDate = dates.First();
if (firstDate.DayOfWeek == DayOfWeek.Monday)
return dates;
var result = new List<DateTime>();
var prependDate = firstDate.AddDays(-1);
while (prependDate.DayOfWeek != DayOfWeek.Monday)
{
result.Insert(0, prependDate);
prependDate = prependDate.AddDays(-1);
}
result.Insert(0, prependDate);
result.AddRange(dates);
return result;
}
}