2026-07-07 10:10:06 -03:00
|
|
|
namespace SeaHaven.Services.Helpers
|
|
|
|
|
{
|
|
|
|
|
public static class WorkOrderOperationalWeek
|
|
|
|
|
{
|
|
|
|
|
public static DateOnly GetMondayOfWeek(DateOnly date)
|
|
|
|
|
{
|
|
|
|
|
var daysFromMonday = ((int)date.DayOfWeek + 6) % 7;
|
|
|
|
|
return date.AddDays(-daysFromMonday);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DateOnly GetPreviousOperationalWeekStart(DateTime utcNow)
|
|
|
|
|
=> GetMondayOfWeek(DateOnly.FromDateTime(utcNow)).AddDays(-7);
|
|
|
|
|
|
|
|
|
|
public static DateOnly GetOperationalWeekEnd(DateOnly weekStartMonday)
|
|
|
|
|
=> weekStartMonday.AddDays(4);
|
|
|
|
|
|
|
|
|
|
public static string BuildWeekCorrelationId(DateOnly sourceWeekStart)
|
|
|
|
|
=> $"week:{sourceWeekStart:yyyy-MM-dd}";
|
2026-07-09 10:06:36 -03:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a validation error message when the week window is invalid; otherwise null.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string? ValidateWeekWindow(DateOnly weekStart, DateOnly weekEnd)
|
|
|
|
|
{
|
|
|
|
|
if (weekEnd < weekStart)
|
|
|
|
|
return "weekEnd must be on or after weekStart.";
|
|
|
|
|
|
|
|
|
|
var spanDays = weekEnd.DayNumber - weekStart.DayNumber;
|
|
|
|
|
if (spanDays > 6)
|
|
|
|
|
return "Week window cannot exceed 7 days.";
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-07-07 10:10:06 -03:00
|
|
|
}
|
|
|
|
|
}
|