public static void ExportTimeZonesToDesktopFile() { var timeZones = TimeZoneInfo.GetSystemTimeZones(); var result = timeZones.Select(TimeZoneDto.FromDotNet).ToList(); var contents = XmlHelpers.SerializeToXml(result); var targetFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop), "timezone.xml"); File.WriteAllText(targetFile, contents); } public static DateTime TweakDateTimeForSqlSvr(DateTime input) { var minDate = new DateTime(1900, 1, 1); if (input.Date != DateTime.MinValue.Date) return input; return minDate + input.TimeOfDay; } public class TimeZoneDto { public static TimeZoneDto FromDotNet(System.TimeZoneInfo a) { var tz = new TimeZoneDto { BaseUtcOffset = (int)a.BaseUtcOffset.TotalMinutes, DaylightName = a.DaylightName, DisplayName = a.DisplayName, DotNetId = a.Id, StandardName = a.StandardName, SupportsDst = a.SupportsDaylightSavingTime, AdjustmentRules = a.GetAdjustmentRules().Select(AdjustmentRuleDto.FromDotNet).ToList() }; return tz; } public int BaseUtcOffset { get; set; } public string DaylightName { get; set; } public string DisplayName { get; set; } public string DotNetId { get; set; } public string StandardName { get; set; } public bool SupportsDst { get; set; } public List<AdjustmentRuleDto> AdjustmentRules { get; set; } } public class AdjustmentRuleDto { public static AdjustmentRuleDto FromDotNet(System.TimeZoneInfo.AdjustmentRule a) { var result = new AdjustmentRuleDto { DateEnd = TweakDateTimeForSqlSvr(a.DateEnd), DateStart = TweakDateTimeForSqlSvr(a.DateStart), DaylightDelta = (int)a.DaylightDelta.TotalMinutes, DstEnd = TransitionTimeDto.FromDotNet(a.DaylightTransitionEnd), DstStart = TransitionTimeDto.FromDotNet(a.DaylightTransitionStart) }; return result; } public DateTime DateEnd { get; set; } public DateTime DateStart { get; set; } public int DaylightDelta { get; set; } public TransitionTimeDto DstEnd { get; set; } public TransitionTimeDto DstStart { get; set; } } public class TransitionTimeDto { public static TransitionTimeDto FromDotNet(System.TimeZoneInfo.TransitionTime a) { var result = new TransitionTimeDto { Day = a.Day, DayOfWeek = a.DayOfWeek, IsFixedDateRule = a.IsFixedDateRule, Month = a.Month, TimeOfDay = a.TimeOfDay, Week = a.Week }; return result; } public int Day { get; set; } public System.DayOfWeek DayOfWeek { get; set; } public bool IsFixedDateRule { get; set; } public int Month { get; set; } public DateTime TimeOfDay { get; set; } public int Week { get; set; } }