ShiftScheduler/Client/Pages/MonthAndYear.cs
Copilot 1493c459bd
Implement responsive mobile/desktop UI layout for shift scheduler (#38)
* Initial plan

* Implement responsive mobile/desktop UI layout

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>

* Clean up demo files and finalize mobile UI implementation

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>

* Fix desktop calendar week grouping to properly start weeks on Monday and end on Sunday

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>

* Remove button for shift delete

* Fix desktop week grouping to start weeks on Monday instead of grouping consecutive days

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>

* UI improvements

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
2025-08-29 20:41:25 +02:00

39 lines
No EOL
1.3 KiB
C#

using System.Globalization;
namespace ShiftScheduler.Client.Pages;
public record MonthAndYear(int Month, int Year)
{
public static MonthAndYear Current() => new (DateTime.Now.Month, DateTime.Now.Year);
public static MonthAndYear Next()
{
var today = DateTime.Today;
var nextMonth = today.Month == 12 ? 1 : today.Month + 1;
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 => ToDateTime.ToString("MMMM yyyy");
private DateTime ToDateTime => new DateTime(Year, Month, 1);
public IReadOnlyList<DateTime> DaysInMonth()
{
return Enumerable.Range(1, DateTime.DaysInMonth(Year, Month))
.Select(d => new DateTime(Year, Month, d))
.ToList();
}
public IReadOnlyDictionary<int, List<DateTime>> 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;
}
}