Handling Date and Time with Timezone awareness correctly in .NET

Problem statement

The TimezoneInfo class and most important methods

  • ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo sourceTimeZone)
  • DateTime ConvertTimeFromUtc( DateTime dateTime, TimeZoneInfo destinationTimeZone)
  • Fallacy of DateTime.ToUniversalTime(): GIST

Using DateTimeOffset to encapsulate both the date/time and the UTC offset of the timezone in question

Write tests to ensure your conversions of date time from and to UTC work as expected, and run the tests with host set to different time zones. (a host running in Sydney timezone vs a host running in UTC)