runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Creating custom TimeZoneInfo from existing TimeZoneInfo in Ubuntu fails

Open stkash opened this issue 7 years ago • 1 comments

I was trying to create custom time zones from the time zones returned by TimeZoneInfo.GetSystemTimeZones() in Ubuntu. I got "System.InvalidTimeZoneException: The elements of the AdjustmentRule array must be in chronological order and must not overlap." exception.

This is the simplified version of my code:

IList<TimeZoneInfo> customТimeZones = new List<TimeZoneInfo>();
foreach (var timezone in TimeZoneInfo.GetSystemTimeZones())
{
	customТimeZones.Add(
		TimeZoneInfo.CreateCustomTimeZone(
			timezone.Id,
			timezone.BaseUtcOffset,
			timezone.DisplayName,
			timezone.DisplayName,
			timezone.DaylightName,
			timezone.GetAdjustmentRules()));
}

I see two potential problems:

  1. In Windows AdjustmentRule.DateStart of the next rule is always one day after AdjustmentRule.DateEnd of the last rule. In Ubuntu they are the same. Windows: Mountain Standard Time Windows

Ubuntu: Mountain Standard Time Ubuntu1

  1. Some of the rules in Ubuntu are messy. For example, "America/Phoenix" has 12 adjustment rules, but there is no continuity after zone with DateEnd = {1/1/1944 12:00:00 AM}. Next zones overlap each other: Mountain Standard Time Ubuntu

stkash avatar Oct 08 '19 19:10 stkash

This is duplicate of https://github.com/dotnet/corefx/issues/17120 so closing this one. If you adding more comments related to this issue, please added it to the linked issue instead. Thanks for reporting the issue.

tarekgh avatar Oct 08 '19 20:10 tarekgh