New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to time zone conversions due to MS updates. #2598
Conversation
Okay. It looks like the autotester is still out-of-date, so I restored the time zones that aren't really supposed to be around anymore. Hopefully, the tests will pass now. |
Drat. Now, it's failing because the windows auto-tester boxes are missing the new Russian time zones. Switching the conversions back so that they don't use the new time zones would be wrong, because the new times zones are different from the old, but if the machine hasn't been updated, then it doesn't have the new ones... bleh. The TZ database's system of naming time zones after cities avoids this whole problem. Why oh why must MS keep renaming time zones like this... :( I guess that I'll have to add some sort of list of defunct conversions to try when a newer name fails so that Windows boxes that aren't properly updated don't have this problem. Though why anyone would fail to update their Windows box... |
74be821
to
aece5e6
Compare
Yay! It looks like the tests are finally passing. |
Hum... These new unittests, will they still fail whenever a change is made on windows end? |
@@ -28949,7 +28981,6 @@ string tzDatabaseNameToWindowsTZName(string tzName) @safe pure nothrow @nogc | |||
case "Africa/Banjul": return "Greenwich Standard Time"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method of using a switch statement for a lookup table results in a lot of code bloat. Please consider using an associative array literal instead, or use two parallel arrays of strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at doing that at one point and decided against it for some reason, though I can't recall why. I do remember that issues with pure
and immutable
made it a bit of a pain, but that could probably be worked around, especially since things keep getting better in that department thanks to improvements to inference and implicit conversions from pure
functions. Regardless, I don't really care which way it is beyond which is more efficient, so I'm fine with changing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a binary search lookup + 2 arrays be more appropriate?
I would expect the compiler to do something similar internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler doesn't convert this code into 2 tables. (The cases are, but not the return statements.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, that makes sense, I don't know why I thought it would do the return statements.
I didn't change the unit tests at all. And yes, they will fail most of the time when Microsoft makes a change to their time zone names. And that's on purpose, because the test that fails is making sure that the conversion from TZ database names to the Windows time zone names and vice versa are up-to-date. That's not going to change. Unfortunately though, it usually gets caught because one of the D developers who uses Windows runs into the test failures after a windows update, and since I use Linux almost exclusively, I'm not one of them. The autotester never catches it, because for some reason, those boxes aren't getting updated. What I should probably do is start making an effort to track the updates that Microsoft does and watch for updates to the time zone info so that I can catch it faster. Or maybe I could write a script to grab the xml file with the mappings on a regular basis and compare it so that it can alert me... In either case, I should do a better job of anticipating it so that it causes fewer problems, but without those tests, we wouldn't catch when MS makes the updates, and the code would be wrong. |
Ah, nevermind, I read the code all wrong. Carry on then :) |
I'm not sure it's a good idea to remove time zones based on windows updates. We have no control over which updates the user has applied, and I wouldn't want someone using XP which receives no updates to have to deal with this. Can the function which translates the sane names to the windows names return an array of possible names, and then have the function which looks up the timezone metadata try them in order? Or is there some mechanism to look up what version of the name database the OS is using? Looking around the net, I see that there is possibly an alternative mechanism of just processing all the time zones in the registry and then using the id (which I'm assuming doesn't change?). The time zones are also localized, so a non-english version of Windows will have the localized names. Has anyone tested this on a non-english version of Windows? For reference: http://stackoverflow.com/questions/4967903/linux-windows-timezone-mapping |
Well, this PR doesn't remove any, if nothing else, because the autotester hasn't been properly updated, so that would break it. And I don't know if I've ever actually removed any because of that. Certainly I didn't this time or the last time. But the fact that a machine might not be properly updated (e.g. and an XP box can't be at this point) definitely poses a problem, particularly for new time zones, since it won't have the correct information. That's why this PR makes it so that
Well, returning an array would break the API regardless of whether that would theoretically be a good approach or not. Also, even if we did return an array, there's the problem that some of those values would then be outright incorrect on an up-to-date system because of actual changes to the time zone or time zone information beyond the name - e.g. if they switched time zones for an area but the old one is still used for other areas (though I suppose that the approach could be taken that the earlier in the array a value is, the more likely it is to be correct). So, I don't know if the array approach would be a good idea or not. But since it would break the API, we're kind of stuck unless we create new function names and evolve the API that way (though I'm willing to bet that the amount of code that would be broken by outright changing the functions to return arrays would be very small, since the few that use the functionality likely do so via And considering that these updates are done via patches which show up as separately installed packages rather than it being tied to the version of Windows, I don't know how you could look up what version of the TZ info a Windows box is using. Honestly, while I think that being able to give a TZ database name like So, I actually wonder if the correct approach after this fix would be to simply deprecate
The ID is what we're using. It's the English name. And |
@@ -29306,7 +29338,7 @@ string tzDatabaseNameToWindowsTZName(string tzName) @safe pure nothrow @nogc | |||
case "Europe/Prague": return "Central Europe Standard Time"; | |||
case "Europe/Riga": return "FLE Standard Time"; | |||
case "Europe/Rome": return "W. Europe Standard Time"; | |||
case "Europe/Samara": return "Russian Standard Time"; | |||
case "Europe/Samara": return "Russia Time Zone 3"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For instance, this looks like you have removed "Russian Standard Time."
I think this means on an older system, someone trying to specify Europe/Samara, would get the wrong id (or no id?). Am I not understanding this correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still there. Other conversions use it. And that's why I added the bit in TimeZone.getTimeZone
where it attempts the older conversion if a newer time zone name isn't on the system. That's the whole point of the new (private) _getOldName
function.
yeah, I looked in the registry. There is no numerical unchanging ID. What a sucky system! However, I did notice in the parent reg key for time zones, (\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones), there is a value called TzVersion, with an identifier. No idea if this is documented anywhere, but maybe this could be the "database version" of the time zones? |
This might be the right answer. The likely process for using time zone ids is to:
All without the program having any idea what the ids actually mean. Another nicety would be to be able to look up all time zones that have certain properties. I.e. give me all time zones that are UTC-5 hours. |
This would work with just |
In any case, if the current changes are acceptable, this should probably be merged sooner rather than later so that folks like Walter aren't having the unit tests fail on their local boxes. We can look at redoing the switch statement and/or deprecating these conversion functions in a separate PR. |
Not sure why the FreeBSD 32 bit failed, had a weird "timeout" message. I deprecated the test so it can be re-run. |
It's a regular failure on FreeBSD 32 release. It's relatively new though. @braddr : Any idea what is causing this system to hang? |
Well, given the current state of affairs, I can't see anything wrong with this PR. I think as a future direction, we should distance ourselves from arbitrary OS decisions. I would be OK with deprecating the posix to windows time zone translation. |
re: freebsd hang: https://issues.dlang.org/show_bug.cgi?id=13416 |
Auto-merge toggled on |
Update to time zone conversions due to MS updates.
Yep, this should merely fix the current state. Whether we want to redo the API or the implementation at some other point is a different story. |
Microsoft updated Windows' time zone information again, creating time zones, renaming them, etc. So, the semi-official conversions between those and the TZ database need to be updated. If the autotesters are up-to-date, then this may fail on the first go round, and I'll have to readd some of the now defunct time zones, but what's here at the moment should be what's on an up-to-date Windows box.