forked from admin/VolcanicAgenticCore
23 lines
1.0 KiB
C#
23 lines
1.0 KiB
C#
using System.Globalization;
|
|
|
|
namespace Volcanic.AgenticCore.Extensions.Scheduler;
|
|
|
|
/// <summary>Zone ids and offsets for display and <c>TZ</c> (the extension can't reference the core's <c>TimeZoneIds</c>).</summary>
|
|
internal static class ZoneNames
|
|
{
|
|
/// <summary>The IANA id (converting a Windows id), or null for an unnamed <c>Local</c> zone.</summary>
|
|
public static string? Iana(TimeZoneInfo zone)
|
|
{
|
|
if (string.Equals(zone.Id, "Local", StringComparison.OrdinalIgnoreCase)) return null;
|
|
if (zone.HasIanaId) return zone.Id;
|
|
return TimeZoneInfo.TryConvertWindowsIdToIanaId(zone.Id, out var iana) ? iana : null;
|
|
}
|
|
|
|
/// <summary>The IANA id when there is one, else the zone's own id.</summary>
|
|
public static string Name(TimeZoneInfo zone) => Iana(zone) ?? zone.Id;
|
|
|
|
/// <summary><c>UTC+09:00</c>.</summary>
|
|
public static string Offset(TimeSpan offset) =>
|
|
(offset < TimeSpan.Zero ? "UTC-" : "UTC+") + offset.Duration().ToString(@"hh\:mm", CultureInfo.InvariantCulture);
|
|
}
|