mattjohnsonpint/TimeZoneConverter

Inconsistent daylight savings flag when running on Linux containers

lanegoolsby opened this issue · 1 comments

I am seeing inconsistent daylight savings flags for MST when using TzConvert on Linux vs Windows.

The following code produces a True for zoneInfo.SupportsDaylightSavingTime on Linux but False (the correct value) on Windows.

        internal static TimeZone MapTimeZone(float latitude, float longitude)
        {
            var zone = TimeZoneLookup.GetTimeZone(latitude, longitude);
            var zoneInfo = TZConvert.GetTimeZoneInfo(zone.Result);

            return new TimeZone
            {
                DaylightSavingsIndicator = zoneInfo.SupportsDaylightSavingTime,
                Name = zoneInfo.DisplayName,
                StandardUtcOffset = zoneInfo.BaseUtcOffset.Hours.ToString(),
                TxDatabaseName = zoneInfo.StandardName
            };
        }

Attached is a reproduction of the issue. TzIssue.zip

Run the app through the IDE debugger and you'll see this:
image

But if you run it using Docker (docker build -t tzissue . && docker run tzissue) you'll get this:
image

Hi. I don't own TimeZoneInfo. That is part of .NET itself. If you feel there's a problem with it, you can log an issue at https://github.com/dotnet/runtime/issues.

That said, there's no promise that time zones on Windows are the same as they are on Linux. In fact, they are quite different because they have underlying different data sources.

Also, looking at your code:

  • SupportsDaylightSavingTime just means that there are any adjustment rules for the time zone. You probably wanted IsDaylightSavingTime instead, which will need a specific timestamp as input.
  • You shouldn't take Hours out of the BaseUtcOffset. There are several time zones that aren't in terms of whole hours.
  • You likely wanted GetUtcOffset instead of BaseUtcOffset, though hard to tell without context.
  • The StandardName can be localized. You likely wanted an Id instead, which is not localized.