Bug 13319 – tzDatabaseNameToWindowsTZName should return null on failure rather than throw

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-18T06:57:00Z
Last change time
2014-08-19T00:13:00Z
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2014-08-18T06:57:40Z
Currently, tzDatabaseNameToWindowsTZName and windowsTZNameToTZDatabaseName throw on failure. In most cases, this is fine, because the common usage is likely to be something like auto tz = WindowsTimeZone.getTimeZone(tzDatabaseNameToWindowsTZName("America/Los_Angeles")); and having that throw on failure is what we want, particularly since it'll probably be fed immediately into the constructor for SysTime. However, in the case where you're trying to check conversions, the fact that it throws is actually very annoying. So, I propose changing it so that they return null no failure, and then getTimeZone would throw instead (because it was given null for the timezone name). So, the normal use case would just get a different error message on failure. The only place that I can think of where this change might break code is in checking for whether a particular time zone conversion exists, because right now, it would check for whether an exception is thrown, and after this, it would have to check for null. So, such code could conceivably break, but such code is also likely very, very rare. So, I woludn't expect much code breakage, and hopefully the few folks who would be affected would see the changelog and change their code. But if they didn't, they'd probably still end up calling getTimeZone with the result at some point and get an exception, since it would be extremely rare for anyone to need those conversions for something else. So, it's a risk, but I think that it's small enough that it's acceptable.
Comment #1 by github-bugzilla — 2014-08-19T00:06:55Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/3a5a11038d83a16b7294cc1db4444a7e34c4a0df Issue# 13319. Make tzDatabaseNameToWindowsTZName return null on failure.