Stephan,

'mktime' converts localtime, it's not designed to do what you want it to do. Setting is_dst just sets the assumption about whether DST is in effect. Setting it to -1 makes the routine look it up. I don't know what happens in that one 'ambiguous' hour each year.

   http://pubs.opengroup.org/onlinepubs/7908799/xsh/mktime.html

(FreeBSD added a 'timegm' routine to their library, but it's not portable.)

This may work:

long UnixTime(time_t now)
{
     struct tm *p = gmtime(&now);
     int y = p->tm_year+1900;
     long days = 365l * y + y/4 - y/100 + y/400 + p->tm_yday - 719527l;
     return (((days*24) + p->tm_hour) * 60 + p->tm_min) * 60 + p->tm_sec;
}

There's an alternative formula here:

http://pubs.opengroup.org/onlinepubs/007904875/basedefs/xbd_chap04.html#tag_04_14

long UnixTime(time_t now)
{
     struct tm *p = gmtime(&now);
     return p->tm_sec + p->tm_min*60l + p->tm_hour*3600l + p->tm_yday*86400l
          + (p->tm_year-70)*31536000l + ((p->tm_year-69)/4)*86400l
          - ((p->tm_year-1)/100)*86400l + ((p->tm_year+299)/400)*86400l;
}


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