On Fri, 16 Sep 2011, Richard Hipp wrote:

time(0) should give you UTC directly.  No need to convert.

This is the common implementation, but not required by any standard. Most OSes do it this way, but POSIX and C99 do only require that time_t be an integer or real type (so it could be a double) and the epoch is not specified.

So if you want to write utterly portable code:

- get the time_t value
- use gmtime() to get a 'struct tm' value representing UTC
- calculate the # of seconds since 1970-01-01T00:00+0:00 from this
  representation, which except for counting leap years is simple enough.

The downside is that this code is not reentrant.

Using strftime("%s", ...) does not work either, "%s" is non-standard (it's not even part of POSIX).

Isn't writing fully portable C code wonderful?

BTW: I would not blame anyone for ignoring this issue....

Gé
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to