Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions libraries/AdaptiveExpressions/TimeZoneConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.IO;
using System.Reflection;

Expand All @@ -18,8 +18,13 @@ namespace AdaptiveExpressions
/// </summary>
public static class TimeZoneConverter
{
private static IDictionary<string, string> ianaToWindowsMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static IDictionary<string, string> windowsToIanaMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static ConcurrentDictionary<string, string> ianaToWindowsMap = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static ConcurrentDictionary<string, string> windowsToIanaMap = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

static TimeZoneConverter()
{
LoadData();
}

/// <summary>
/// convert IANA timezone format to windows timezone format.
Expand All @@ -28,7 +33,6 @@ public static class TimeZoneConverter
/// <returns>windows timezone format.</returns>
public static string IanaToWindows(string ianaTimeZoneId)
{
LoadData();
if (ianaToWindowsMap.ContainsKey(ianaTimeZoneId))
{
return ianaToWindowsMap[ianaTimeZoneId];
Expand All @@ -44,7 +48,6 @@ public static string IanaToWindows(string ianaTimeZoneId)
/// <returns>Iana timezone format.</returns>
public static string WindowsToIana(string windowsTimeZoneId)
{
LoadData();
if (windowsToIanaMap.ContainsKey($"001|{windowsTimeZoneId}"))
{
return windowsToIanaMap[$"001|{windowsTimeZoneId}"];
Expand All @@ -69,14 +72,14 @@ private static void LoadData()
var ianaIdList = table[2].Split(' ');
if (!windowsToIanaMap.ContainsKey($"{territory}|{windowsId}"))
{
windowsToIanaMap.Add($"{territory}|{windowsId}", ianaIdList[0]);
windowsToIanaMap.TryAdd($"{territory}|{windowsId}", ianaIdList[0]);
}

foreach (var ianaId in ianaIdList)
{
if (!ianaToWindowsMap.ContainsKey(ianaId))
{
ianaToWindowsMap.Add(ianaId, windowsId);
ianaToWindowsMap.TryAdd(ianaId, windowsId);
}
}
}
Expand Down