shoc-backend/SeaHaven.Services/Helpers/WorkOrderBoardApptTimeParser.cs
Arthur Bassi d040832b87 feat(work-orders): isolate phase 2 inline edit with optimistic concurrency
Deliver PATCH board field updates and drop phases 3-7 code from the branch while keeping phase 0/1 dependencies required to build and test.
2026-07-07 11:26:13 -03:00

57 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace SeaHaven.Services.Helpers
{
public static class WorkOrderBoardApptTimeParser
{
public static bool TryParse(string? value, out TimeSpan? start, out TimeSpan? end, out string? error)
{
start = null;
end = null;
error = null;
if (string.IsNullOrWhiteSpace(value))
return true;
var trimmed = value.Trim();
var parts = trimmed.Split(new[] { '–', '—', '-' }, StringSplitOptions.RemoveEmptyEntries)
.Select(p => p.Trim())
.Where(p => !string.IsNullOrEmpty(p))
.ToArray();
if (parts.Length == 1)
{
if (!TimeSpan.TryParse(parts[0], out var single))
{
error = "Invalid appointment time format.";
return false;
}
start = single;
return true;
}
if (parts.Length == 2)
{
if (!TimeSpan.TryParse(parts[0], out var startTime) || !TimeSpan.TryParse(parts[1], out var endTime))
{
error = "Invalid appointment time range format.";
return false;
}
start = startTime;
end = endTime;
return true;
}
error = "Invalid appointment time format.";
return false;
}
public static DateTime? CombineDateAndTime(DateTime? date, TimeSpan? time)
{
if (!date.HasValue || !time.HasValue)
return date;
return date.Value.Date.Add(time.Value);
}
}
}