namespace SIGCM2.Application.Common;
///
/// Extension methods for 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:00–23:59 window.
///
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();
///
/// Returns today's civil date in Argentina timezone, computed from the
/// UTC clock.
/// Safe in tests via FakeTimeProvider; safe in production via
/// TimeProvider.System.
///
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);
}
}
}