Skip to content

Commit dab355a

Browse files
Use overloads to avoid breaking change from 5.x (#129)
1 parent 9a6ffe0 commit dab355a

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

src/TimeZoneConverter/TZConvert.cs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static IReadOnlyDictionary<string, IReadOnlyCollection<string>> GetIanaTi
8282
.OrderBy(zone => zone)
8383
.ToList().AsReadOnly()));
8484
}
85-
85+
8686
// Converting to windows and back has the reduction effect we are looking for
8787
return new ReadOnlyDictionary<string, IReadOnlyCollection<string>>(
8888
IanaTerritoryZones.ToDictionary(
@@ -127,6 +127,24 @@ public static bool TryIanaToWindows(string ianaTimeZoneName, [MaybeNullWhen(fals
127127
return IanaMap.TryGetValue(ianaTimeZoneName, out windowsTimeZoneId!);
128128
}
129129

130+
/// <summary>
131+
/// Converts a Windows time zone ID to an equivalent IANA time zone name.
132+
/// </summary>
133+
/// <param name="windowsTimeZoneId">The Windows time zone ID to convert.</param>
134+
/// <param name="territoryCode">
135+
/// An optional two-letter ISO Country/Region code, used to get a a specific mapping.
136+
/// Defaults to "001" if not specified, which means to get the "golden zone" - the one that is most prevalent.
137+
/// </param>
138+
/// <returns>An IANA time zone name.</returns>
139+
/// <exception cref="InvalidTimeZoneException">
140+
/// Thrown if the input string was not recognized or has no equivalent IANA
141+
/// zone.
142+
/// </exception>
143+
public static string WindowsToIana(string windowsTimeZoneId, string territoryCode = "001")
144+
{
145+
return WindowsToIana(windowsTimeZoneId, territoryCode, LinkResolution.Default);
146+
}
147+
130148
/// <summary>
131149
/// Converts a Windows time zone ID to an equivalent IANA time zone name.
132150
/// </summary>
@@ -156,10 +174,7 @@ public static string WindowsToIana(string windowsTimeZoneId, LinkResolution link
156174
/// Thrown if the input string was not recognized or has no equivalent IANA
157175
/// zone.
158176
/// </exception>
159-
public static string WindowsToIana(
160-
string windowsTimeZoneId,
161-
string territoryCode = "001",
162-
LinkResolution linkResolutionMode = LinkResolution.Default)
177+
public static string WindowsToIana(string windowsTimeZoneId, string territoryCode, LinkResolution linkResolutionMode)
163178
{
164179
if (TryWindowsToIana(windowsTimeZoneId, territoryCode, out var ianaTimeZoneName, linkResolutionMode))
165180
{
@@ -169,6 +184,20 @@ public static string WindowsToIana(
169184
throw new InvalidTimeZoneException(
170185
$"\"{windowsTimeZoneId}\" was not recognized as a valid Windows time zone ID.");
171186
}
187+
188+
/// <summary>
189+
/// Attempts to convert a Windows time zone ID to an equivalent IANA time zone name.
190+
/// Uses the "golden zone" - the one that is the most prevalent.
191+
/// </summary>
192+
/// <param name="windowsTimeZoneId">The Windows time zone ID to convert.</param>
193+
/// <param name="ianaTimeZoneName">An IANA time zone name.</param>
194+
/// <returns><c>true</c> if successful, <c>false</c> otherwise.</returns>
195+
public static bool TryWindowsToIana(
196+
string windowsTimeZoneId,
197+
[MaybeNullWhen(false)] out string ianaTimeZoneName)
198+
{
199+
return TryWindowsToIana(windowsTimeZoneId, "001", out ianaTimeZoneName, LinkResolution.Default);
200+
}
172201

173202
/// <summary>
174203
/// Attempts to convert a Windows time zone ID to an equivalent IANA time zone name.
@@ -181,11 +210,29 @@ public static string WindowsToIana(
181210
public static bool TryWindowsToIana(
182211
string windowsTimeZoneId,
183212
[MaybeNullWhen(false)] out string ianaTimeZoneName,
184-
LinkResolution linkResolutionMode = LinkResolution.Default)
213+
LinkResolution linkResolutionMode)
185214
{
186215
return TryWindowsToIana(windowsTimeZoneId, "001", out ianaTimeZoneName, linkResolutionMode);
187216
}
188217

218+
/// <summary>
219+
/// Attempts to convert a Windows time zone ID to an equivalent IANA time zone name.
220+
/// </summary>
221+
/// <param name="windowsTimeZoneId">The Windows time zone ID to convert.</param>
222+
/// <param name="territoryCode">
223+
/// An optional two-letter ISO Country/Region code, used to get a a specific mapping.
224+
/// Defaults to "001" if not specified, which means to get the "golden zone" - the one that is most prevalent.
225+
/// </param>
226+
/// <param name="ianaTimeZoneName">An IANA time zone name.</param>
227+
/// <returns><c>true</c> if successful, <c>false</c> otherwise.</returns>
228+
public static bool TryWindowsToIana(
229+
string windowsTimeZoneId,
230+
string territoryCode,
231+
[MaybeNullWhen(false)] out string ianaTimeZoneName)
232+
{
233+
return TryWindowsToIana(windowsTimeZoneId, territoryCode, out ianaTimeZoneName, LinkResolution.Default);
234+
}
235+
189236
/// <summary>
190237
/// Attempts to convert a Windows time zone ID to an equivalent IANA time zone name.
191238
/// </summary>
@@ -201,7 +248,7 @@ public static bool TryWindowsToIana(
201248
string windowsTimeZoneId,
202249
string territoryCode,
203250
[MaybeNullWhen(false)] out string ianaTimeZoneName,
204-
LinkResolution linkResolutionMode = LinkResolution.Default)
251+
LinkResolution linkResolutionMode)
205252
{
206253
// try first with the given region
207254
var found = WindowsMap.TryGetValue($"{territoryCode}|{windowsTimeZoneId}", out var ianaId);

src/TimeZoneConverter/TimeZoneConverter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageTags>timezone;time;zone;time zone;iana;tzdb;olson;timezoneinfo,rails</PackageTags>
99
<PackageProjectUrl>https://github.com/mattjohnsonpint/TimeZoneConverter</PackageProjectUrl>
1010
<PackageLicenseExpression>MIT</PackageLicenseExpression>
11-
<Version>6.0.0</Version>
11+
<Version>6.0.1</Version>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)