mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 06:03:12 +00:00
Return BadRequest for invalid board week window, remove duplicate unused board types, fix POC null guard, and document appt precedence and UTC Phase 1 assumptions.
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
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}";
|
|
|
|
/// <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;
|
|
}
|
|
}
|
|
}
|