TimeZoneInfo.ConvertTimeFromUtc returns incorrect result

Neshta

I have a very strange behaviour with TimeZoneInfo.ConvertTimeFromUtc. How do you think what this returns?

var date = new DateTime(2000, 1, 1, 12, 0, 0);
var dest = TimeZoneInfo.FindSystemTimeZoneById("Belarus Standard Time");
TimeZoneInfo.ConvertTimeFromUtc(date, dest);

Belarus Standard Time is UTC+3. And I expect {01.01.2000 15:00:00}. But I see the next: enter image description here

WAT?

This worked correctly some days ago. But today I have run unit tests and noticed this. Before running the tests I installed Visual Studio 2015. What could happen and why? How to fix it?

PS: It works correctly on another machine.

Matt Johnson-Pint

Actually, the conversion is correct.

While it's true that Belarus currently has a time zone that is UTC+3 all year, it has only been that way since 2012.

Prior to that, its standard offset was UTC+2, and it observed a daylight time (aka "summer time") offset of UTC+3 from the last Sunday in March through the last Sunday in October. This change was enacted by remaining on summer time in 2011 and staying there permanently, rather than falling back.

You can see the history of changes here.

When you use the "Belarus Standard Time" time zone, the information for this zone is pulled from the data in the Windows registry at the following location:

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Belarus Standard Time

There you will see the basic information, and a subkey called Dynamic DST that contains the year-over-year changes. You'll notice that Windows has three entries for this zone:

  • One for 2010 and prior, which alternates between standard time and daylight time
  • One for 2011 which makes the single change to daylight time without returning to standard time
  • One for 2012 and greater, which is fixed at standard time with the new base offset

Note that this is a simplification of the full IANA TZDB entry of "Europe/Minsk", which tracks other changes in 1992 and prior. Windows doesn't know about those changes, so if you are going to be working with historical dates with this time zone, you should consider using Noda Time instead of TimeZoneInfo, as Noda Time has support for the TZDB time zones.

Also, note that since the data is modeled in Windows as 2011 and prior having a different base offset than the 2012 and forward rule, then it is impacted by the issue described in KB2012229. The status section of that article is outdated, as the issue was resolved with .NET 4.6. Even if you are targeting .NET 3.5 through .NET 4.5.2, if .NET 4.6 is installed on the machine at all, then it will behave correctly. If .NET 4.6 is not installed on the machine, it will apply the wrong base offset for Belarus to years 2011, 2010, and prior. (This is why SonerGönül got the time of 15:00 mentioned in the question comments.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TimeZoneInfo.ConvertTimeFromUtc returns strange output for 1972 year

TimeZoneInfo ConvertTimeFromUtc discrepancies during utc date change

How to use TimeZoneInfo.ConvertTimeFromUtc in linq to sql?

TimeZoneInfo.ConvertTimeFromUtc returned wrong DateTime

MySQL MAX returns incorrect result

TimeZoneInfo.ConvertTimeFromUTC produce different output then TimeZone.BaseUTCOffset

'TimeZoneInfo' does not contain a definition for 'ConvertTimeFromUtc' (DNX Core 5.0)

TimeZoneInfo.ConvertTimeFromUtc is not converting old dates to then daylight saving time

TimeZoneInfo.ConvertTimeFromUtc is not correctly applying DST on a deployed Azure Webjob

File.isFile() returns incorrect result?

Gremlin using select in hasId returns incorrect result

lambdified sympy expression returns incorrect result

getting an array from webservice returns an incorrect result

removing rows without returns incorrect result

Kadane algorithm implementation returns incorrect result

PL/pgSQL function returns incorrect bitwise result

Azure pipeline powershell script returns incorrect result

MarkLogic Query By Example returns incorrect result

Array formula with SUM Function returns incorrect result

Google Maps Autocomplete Place returns incorrect result

in MySQL, MAX() command returns an incorrect result

wcslen() returns incorrect result when pragma pack used

Count of multiple items in one MySQL query returns an incorrect result

Fetch DPI from JPEG without library returns incorrect result

numpy.square returns incorrect result for sparse matrices

GROUP BY on column alias with NULLs returns incorrect result in MySQL

Eloquent ORM 5.1 query returns incorrect result (compared to plain SQL)

IoT Hub device twin query returns incorrect result on lastActivityTime property

JavaScript requesting JSON info. returns incorrect result