diff options
Diffstat (limited to 'src/IOL.Helpers/DateTimeHelpers.cs')
| -rw-r--r-- | src/IOL.Helpers/DateTimeHelpers.cs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/IOL.Helpers/DateTimeHelpers.cs b/src/IOL.Helpers/DateTimeHelpers.cs new file mode 100644 index 0000000..07e951e --- /dev/null +++ b/src/IOL.Helpers/DateTimeHelpers.cs @@ -0,0 +1,22 @@ +using System; + +namespace IOL.Helpers +{ + public static class DateTimeHelpers + { + public static DateTime ToTimeZoneId(this DateTime value, string timeZoneId) { + try { + var cstZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); + return TimeZoneInfo.ConvertTimeFromUtc(value, cstZone); + } catch (TimeZoneNotFoundException) { + Console.WriteLine("The registry does not define the " + timeZoneId + " zone."); + return default; + } catch (InvalidTimeZoneException) { + Console.WriteLine("Registry data on the " + timeZoneId + " zone has been corrupted."); + return default; + } + } + + public static DateTime ToOsloTimeZone(this DateTime value) => ToTimeZoneId(value, "Europe/Oslo"); + } +}
\ No newline at end of file |
