1

I'm trying to replicate the functionality of the Windows function GetTimeZoneInformation, which populates a TIME_ZONE_INFORMATION structure, using CoreFoundation. I've made a function that turns a CFAbsoluteTime along with a CFTimeZoneRef into the equivalent of a SYSTEMTIME, but there are a few other things I can't quite figure out. For example:

  • StandardDate and DaylightDate: I've used the CFTimeZoneGetNextDaylightSavingTimeTransition function to find the next transition, and CFTimeZoneIsDaylightSavingTime to determine which transition this is, but since TIME_ZONE_INFORMATION requires both dates, how would I find the transition after the next transition?
  • Similarly, DaylightBias - I can use CFTimeZoneGetDaylightSavingTimeOffset to find the offset if we're currently in DST, but this value goes to zero if we're not currently in DST. I know it's pretty much always -60, but I'd like this function to stay completely faithful to the Windows function.

Does anyone know a good solution for this?

benwad
  • 6,414
  • 10
  • 59
  • 93
  • Can you use managed code? [.Net's `TimeZoneInfo` class](http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx?cs-lang=cpp) has everything set up quite well. Wait a sec, I see you tagged OSX, but you are talking about windows stuff? I'm confused. Please clarify. – Matt Johnson-Pint Feb 22 '13 at 16:18
  • Also, Windows uses the Microsoft Timezone database, which is completely different than the IANA/Olson database used by the rest of the world (unix, linux, mac osx). You will probably have a hard time making it conform. I know little about osx programming, but I found [this reference](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimeZone_Class/Reference/Reference.html#//apple_ref/occ/cl/NSTimeZone) which may help you do it the mac way properly. – Matt Johnson-Pint Feb 22 '13 at 16:26
  • I'm porting something from Windows to Mac, so need to make it conform to the standard. I think I've come up with something pretty solid (I'll post an answer when I've tested a bit more), but it's going to be hard to cover all the edge cases. Thanks for the heads up about the timezone database - I didn't realise that Windows used a different one! Talk about reinventing the wheel... – benwad Feb 22 '13 at 16:48
  • Yep. It's a sore point for interoperability. If the program you are porting runs entirely on the mac, I would use the stuff that comes built in with osx - including their time zones. If you need to interop with windows machines, then you will need some code to map between them. One way mappings from Windows to IANA/Olson are in the CLDR [here](http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml). Going the other direction is nearly impossible. Others have [tried](http://stackoverflow.com/questions/8372537/converting-olson-tzid-to-windows-time-zone), but its a hack. – Matt Johnson-Pint Feb 22 '13 at 17:05

0 Answers0