I have this routine that calculates the seconds-to-date for a struct tm. On Linux my implementation using mktime works fine, but mktime on windows VS2003/.NET 1.1 returns -1 for pre-epoch datetimes.
How do I calculate meaningful time_t values (i.e.
value + secondsToEpoch == secondsToDatetime
) from a for pre-epoch dates, using ANSI C++ only (no boost, Qt either)?
Thanks for your help.
Looking at a couple of mktime sources on the net, they all look pretty portable so you ought to be able to grab one and just put it in your source, paying attention to legal requirements, of course.
That said, I think you have to look for the right one. What dates are you working with? If you’re working with pre-1970 dates, there’s a good chance you’re going to need a 64-bit time_t.
There are also some weird calendar changes very early on that might be a concern, e.g., the switch to the Gregorian calendar.