-1

GetTimeZoneInformation fills up a TIME_ZONE_INFO struct with all sorts of useful information.

Except it doesn't actually tell me if the current local time zone is in daylight savings or not.

For that matter, I'm in New York and the StandardBias and DaylightBias both say the same thing as the Bias.

What's going on?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
stu
  • 8,461
  • 18
  • 74
  • 112
  • You could check the current date against the StandardDate and DaylightDate fields to tell whether the TZ is currently in Standard or Daylight. – Logicrat Aug 16 '16 at 15:08

1 Answers1

4

The return code of GetTimeZoneInformation contains the information you want.

According to MSDN:

If the function succeeds, it returns one of the following values.

TIME_ZONE_ID_UNKNOWN
0
Daylight saving time is not used in the current time zone, because there are no transition dates or automatic adjustment for daylight saving time is disabled.

TIME_ZONE_ID_STANDARD
1
The system is operating in the range covered by the StandardDate member of the TIME_ZONE_INFORMATION structure.

TIME_ZONE_ID_DAYLIGHT
2
The system is operating in the range covered by the DaylightDate member of the TIME_ZONE_INFORMATION structure.

If the function fails for other reasons, such as an out of memory error, it returns TIME_ZONE_ID_INVALID. To get extended error information, call GetLastError.

Make sure you check the return code to ensure the information you are receiving is indeed valid.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
user4581301
  • 33,082
  • 7
  • 33
  • 54
  • yes indeed, how did I miss that. :-) Thanks. While I've got an expert... any way to get anything resembling the olson city name out of windows? I need to make a libical timezone object which needs an olsen city name, and I can't see how to get it out of windows. – stu Aug 17 '16 at 13:00
  • @stu No expert here. Never had to do this, and a quick perusal of the literature dug up by google doesn't show any out-of-the-box or easy way to do it. I also don't see a mapping in `boost::locale`, but I might be out of date. Looks like you should ask another question. – user4581301 Aug 17 '16 at 16:20
  • Thanks. I've done lots of looking. I think windows doesn't do olsen, and what it does do, is probably not enough for me to find in the libical timezone database... – stu Aug 17 '16 at 19:12