Skip to content

Commit

Permalink
Expose extension methods as public (#125)
Browse files Browse the repository at this point in the history
+ Log exception too
  • Loading branch information
aaron-hardin committed Feb 21, 2024
1 parent c161b8e commit c874758
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class TimeZoneInformationExtensionMethods
/// If <see cref="DateTime.Kind"/> is set to <see cref="DateTimeKind.Unspecified"/> then this method does nothing.
/// If <see cref="DateTime.Kind"/> is set to <see cref="DateTimeKind.Utc"/> then the datetime is altered to take into the <paramref name="timeZoneInfo"/>.
/// </returns>
internal static DateTime EnsureLocalTime(this TimeZoneInformation timeZoneInfo, DateTime input)
public static DateTime EnsureLocalTime(this TimeZoneInformation timeZoneInfo, DateTime input)
{
// Sanity.
if (string.IsNullOrWhiteSpace(timeZoneInfo?.StandardName))
Expand All @@ -49,8 +49,13 @@ internal static DateTime EnsureLocalTime(this TimeZoneInformation timeZoneInfo,
var output = input.Add(tzi.GetUtcOffset(input));
return DateTime.SpecifyKind(output, DateTimeKind.Local);
}
catch
catch (Exception ex)
{
Logger?.Error
(
ex,
$"Error converting to local time. It will be used as-is."
);
return input;
}
}
Expand All @@ -68,7 +73,7 @@ internal static DateTime EnsureLocalTime(this TimeZoneInformation timeZoneInfo,
/// If <see cref="DateTime.Kind"/> is set to <see cref="DateTimeKind.Unspecified"/> then this method does nothing.
/// If <see cref="DateTime.Kind"/> is set to <see cref="DateTimeKind.Utc"/> then the datetime is altered to take into the <paramref name="timeZoneInfo"/>.
/// </returns>
internal static DateTime EnsureUTCTime(this TimeZoneInformation timeZoneInfo, DateTime input)
public static DateTime EnsureUTCTime(this TimeZoneInformation timeZoneInfo, DateTime input)
{
// Sanity.
if (string.IsNullOrWhiteSpace(timeZoneInfo?.StandardName))
Expand All @@ -95,8 +100,13 @@ internal static DateTime EnsureUTCTime(this TimeZoneInformation timeZoneInfo, Da
var output = input.Subtract(tzi.GetUtcOffset(input));
return DateTime.SpecifyKind(output, DateTimeKind.Local);
}
catch
catch (Exception ex)
{
Logger?.Error
(
ex,
$"Error converting to UTC time. It will be used as-is."
);
return input;
}
}
Expand Down

0 comments on commit c874758

Please sign in to comment.