C Code for draft-newman-datetime-00.txt

Chris Newman Chris.Newman at innosoft.com
Wed Jan 15 18:47:53 UTC 1997


On Wed, 15 Jan 1997, Markus G. Kuhn wrote:
> I have done a sample implementation of the draft-newman-datetime-00.txt
> ISO 8601 profile with the modifications suggested by Paul and myself
> already included. So far, this is only the write routine, the parser will 
> follow later.

Thank you.  This is a good start and is definitely needed.  Although I
don't agree with all the suggested changes.

> I have some doubts whether this code will handle the local time form
> correctly during both DST switch hours.  Does anyone know a nicer
> solution for determining the UTC offset of local time with portable
> library functions reliably? (May be, something like "utm.tm_isdst =
> ltm.tm_isdst" before mktime() is still necessary?)

Your code won't work right across the timezone shift.  I suggest punting 
on difftime and doing something like this (which assumes no more than a 24
hour difference between local time and UTC).

    offset = local.tm_yday - gmt.tm_yday;
    if (offset > 1) {
        offset = -24;
    } else if (offset < -1) {
        offset = 24;
    } else {
        offset *= 24;
    }
    offset += local.tm_hour - gmt.tm_hour;
    offset *= 60;
    offset += local.tm_min - gmt.tm_min;

> Well-engineered ISO C example code that can easily be included in new
> applications will certainly make the ISO 8601 profile RFC more popular
> and should definitely be added.

I agree.  Although it should be in an appendix with appropriate
disclaimer.




More information about the tz mailing list