digitalmars.D - Using the TZ Database with Windows
- Jake (8/8) Dec 10 2014 Hello,
- Jonathan M Davis via Digitalmars-d (33/41) Jan 11 2015 I really need to catch up on reading posts in the newsgroup, or I would ...
Hello, I'm doing some research with D concerning time zones and I need to be able to handle a single time zone style on both Windows and Linux. That pretty much leaves me with the IANA Time Zone Database. Has anyone around here dealt with compiling the data files for the tz database on Windows? Or is there some easy way to do it for D?
Dec 10 2014
On Wednesday, December 10, 2014 17:21:01 Jake via Digitalmars-d wrote:Hello, I'm doing some research with D concerning time zones and I need to be able to handle a single time zone style on both Windows and Linux. That pretty much leaves me with the IANA Time Zone Database. Has anyone around here dealt with compiling the data files for the tz database on Windows? Or is there some easy way to do it for D?I really need to catch up on reading posts in the newsgroup, or I would have seen this a month ago. Sorry about that. In any case, std.datetime.PosixTimeZone supports reading from the TZ database time zone files directly. So, as long as you have those files on Windows, you can use PosixTimeZone on there just as easily as you do on Linux. So, instead of doing auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles"); you'd do auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles", pathToTZFiles); and you can do something like version(Posix) auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles"); else version(Windows) auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles", pathToTZFiles); or version(Posix) auto pathToTZFiles = PosixTimeZone.defaultTZDatabaseDir; else version(Windows) auto pathToTZFiles = "My path on Windows"; auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles", pathToTZFiles); differentiate between Windows and the POSIX systems. In either caes, you can then do stuff like auto st = Clock.currTime(tz); or auto st = SysTime(/* whatever my arguments are */, tz); to get a SysTime with that time zone. Regardless, you should be able to just take the binary files from Linux and use them directly on Windows without compiling anything. I'd like to add support for just reading them from a tar.gz or .zip file rather than forcing you to put them all in a directory on Windows, but I've never gotten around to it. - Jonathan M Davis
Jan 11 2015