runtime
runtime copied to clipboard
Creating custom TimeZoneInfo from existing TimeZoneInfo in Ubuntu fails
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:
- In Windows
AdjustmentRule.DateStartof the next rule is always one day afterAdjustmentRule.DateEndof the last rule. In Ubuntu they are the same. Windows:
Ubuntu:

- 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:

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.