feat(udt-011): TimeProviderArgentinaExtensions.GetArgentinaToday cross-platform

This commit is contained in:
2026-04-18 09:43:35 -03:00
parent 03d51d4310
commit 4e70b0f847

View File

@@ -0,0 +1,45 @@
namespace SIGCM2.Application.Common;
/// <summary>
/// Extension methods for <see cref="TimeProvider"/> that expose Argentina-localized
/// date helpers. Handles the UTC-3 offset cross-platform (IANA / Windows TZ IDs).
///
/// UDT-011: Cat2 fields (VigenciaDesde, etc.) must use civil Argentine date, never
/// raw UTC, to avoid date-creep during the 22:0023:59 window.
/// </summary>
public static class TimeProviderArgentinaExtensions
{
// IANA TZ id — Linux / macOS / .NET 8+ on Windows with ICU
public const string ArgentinaTimeZoneId = "America/Argentina/Buenos_Aires";
// Windows built-in TZ id — fallback for environments without ICU
public const string ArgentinaTimeZoneIdWindows = "Argentina Standard Time";
private static readonly TimeZoneInfo ArgentinaTz = LoadArgentinaTz();
/// <summary>
/// Returns today's civil date in Argentina timezone, computed from the
/// <see cref="TimeProvider"/> UTC clock.
/// Safe in tests via <c>FakeTimeProvider</c>; safe in production via
/// <c>TimeProvider.System</c>.
/// </summary>
public static DateOnly GetArgentinaToday(this TimeProvider timeProvider)
{
var utcNow = timeProvider.GetUtcNow();
var argentinaNow = TimeZoneInfo.ConvertTime(utcNow, ArgentinaTz);
return DateOnly.FromDateTime(argentinaNow.DateTime);
}
private static TimeZoneInfo LoadArgentinaTz()
{
try
{
return TimeZoneInfo.FindSystemTimeZoneById(ArgentinaTimeZoneId);
}
catch (TimeZoneNotFoundException)
{
// Windows without ICU: fall back to built-in Windows TZ name
return TimeZoneInfo.FindSystemTimeZoneById(ArgentinaTimeZoneIdWindows);
}
}
}