This one has been stumping me for a good minute now. I am working on a program that is written in C++ that I need to be able to send times encoded in ISO8601 between two different servers. The major stickler here seems to be Windows.
Thus far, I have ported over strptime()
from NetBSD in order to easily read a date/time string off the wire and turn it into a tm*
. However, I am totally stumped when it comes to correctly turning it into a localized tm*
so I can then display this time to the user in their local timezone using strftime()
. A naive approach would be to simply take the difference between localtime(time(0))
and gmtime(time(0))
, but this wouldn't be consistent for an arbitrary date where daylight savings time is involved.
The approach I've been taking so far is to use only POSIX date and time functions and to write Windows shims when necessary (done for strptime()
so far, and timegm()
perhaps in the future if necessary). I would prefer to keep doing that, but the simple fact is that the tm*
struct in Windows is missing some fields that Linux and OSX do, so I might not have a choice but to write non-portable code that is guarded by #if WIN32
. I also would really prefer not to have to pull in boost for this.