diff --git a/Client/Pages/Index.razor b/Client/Pages/Index.razor index f48207f..d19b76e 100644 --- a/Client/Pages/Index.razor +++ b/Client/Pages/Index.razor @@ -3,8 +3,8 @@
- - + +
@@ -46,9 +46,9 @@ else
- @foreach (var week in GetWeeksInMonth()) + @foreach (var week in SelectedDate.GetWeeksInMonth()) { - @foreach (var day in week) + @foreach (var day in week.Value) {
@@ -84,10 +84,10 @@ else @if (SelectedSchedule.ContainsKey(day)) {
- @GetShiftTimes(day) + @GetShiftTimes(day)
- @GetTransportSummary(day) + @GetTransportSummary(day)
}
@@ -133,10 +133,10 @@ else @if (SelectedSchedule.ContainsKey(day)) {
- @GetShiftTimes(day) + @GetShiftTimes(day)
- @GetTransportSummary(day) + @GetTransportSummary(day)
}
@@ -146,5 +146,5 @@ else } + OnClose="HideConfiguration" + OnConfigurationChanged="OnConfigurationChanged" /> diff --git a/Client/Pages/MonthAndYear.cs b/Client/Pages/MonthAndYear.cs index 0d76c99..6fe1996 100644 --- a/Client/Pages/MonthAndYear.cs +++ b/Client/Pages/MonthAndYear.cs @@ -1,8 +1,11 @@ -namespace ShiftScheduler.Client.Pages; +using System.Globalization; + +namespace ShiftScheduler.Client.Pages; public record MonthAndYear(int Month, int Year) { - public static MonthAndYear Current() => new MonthAndYear(DateTime.Now.Month, DateTime.Now.Year); + public static MonthAndYear Current() => new (DateTime.Now.Month, DateTime.Now.Year); + public static MonthAndYear Next() { var today = DateTime.Today; @@ -10,13 +13,27 @@ public record MonthAndYear(int Month, int Year) var year = today.Month == 12 ? today.Year + 1 : today.Year; return new MonthAndYear(nextMonth, year); } + + public static string CurrentMonthName => Current().ToDateTime.ToString("MMMM"); + public static string NextMonthName => Next().ToDateTime.ToString("MMMM"); - public string Title => new DateTime(Year, Month, 1).ToString("MMMM yyyy"); + public string Title => ToDateTime.ToString("MMMM yyyy"); + private DateTime ToDateTime => new DateTime(Year, Month, 1); + public IReadOnlyList DaysInMonth() { return Enumerable.Range(1, DateTime.DaysInMonth(Year, Month)) .Select(d => new DateTime(Year, Month, d)) .ToList(); } + + public IReadOnlyDictionary> GetWeeksInMonth() + { + var days = DaysInMonth(); + var weeks = days + .GroupBy(d => CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(d, CalendarWeekRule.FirstDay, DayOfWeek.Monday)) + .ToDictionary(d => d.Key, d => d.ToList()); + return weeks; + } } \ No newline at end of file