Hi all,

I'm looking into QTBUG-49008 and need to work out how diverse
implementations of mktime handle DST transitions: at one end of the year
there's a gap (where 1:59 is followed by 3:00), at the other end there's
a duplicated hour (where 2:59 is followed by a reprise of 2:00 in
Europe, or 1:59 by 1:00 in the USA, IIUC).  While we still need to work
out what behaviour *we* want to give, implementing it is going to depend
on knowing what the platform mktime gives us to work with.

I know glibc's behaviour (2.19-22), although confirmation of it from
elsewhere and version variation may be worth knowing.  We have a kludge
for MS-Win that suggests what it does (actually quite sensible, though
different to GNU), but I'd be glad of confirmation.  The 'net suggests
FreeBSD may even treat some of it as errors; I may need to follow up on
that, and on Mac.  So I wrote a simple test program.

If you're willing to compile and run the attached simple C program,
please let me know its output and your platform's details - ideally
off-list - I'll give a summary in a few days' time.  Those not in Europe
shall need to amend the data in two statics at the top of the file
(there are comments to guide you) to hit when your DST transitions are.
(I'd also be glad to know what those are, if you include a diff.)

        Eddy.
#include <time.h>
#include <stdio.h>

/* Europe switches between a Sunday's 2 and 3 am in March and October.
 * If you're elsewhere, please look up your local details and amend these two
 * statics appropriately.  Years are off by 1900 (2015 is 115), months are off
 * by 1 (Jan = 0, Dec = 11). <configure-me> */
static const struct tm spring = {
    0, 30, /* half past the hour */
    2, /* the hour that gets skipped */
    29, 2, 115, /* 2015-03-29; a Sunday */
    0 /* static: 0-fill all remaining fields */
};
static const struct tm autumn = {
    0, 30, /* half past the hour */
    2, /* (1 in the USA) the hour that gets repeated */
    25, 9, 115, /* 2015-10-25; a Sunday */
    0 /* static: 0-fill all remaining fields */
};
/* </configure-me> Pass -Wno-missing-field-initializers (or its equivalent) to
 * your compiler, if enabling warnings; ANSI C '89 specified that all
 * unspecified fields of a static get 0-filled. */

static void report(time_t got) {
    if (got == (time_t) -1) puts("Rejected.");
    else printf("Accepted: %ld\n", (long) got);
}

static void study(const struct tm *when) {
    char datebuffer[52]; /* twice what asctime_r() asks for */
    struct tm test = *when;
    printf("Initial: %s\n", asctime_r(&test, datebuffer));

    test.tm_isdst = -1;
    report(mktime(&test));
    printf("Ignorant of DST (-> %d): %s", test.tm_isdst, asctime_r(&test, datebuffer));
    puts(""); /* Blank line */

    test = *when;
    test.tm_isdst = 0;
    report(mktime(&test));
    printf("Claiming no DST (-> %d): %s", test.tm_isdst, asctime_r(&test, datebuffer));
    puts(""); /* Blank line */

    test = *when;
    test.tm_isdst = 1;
    report(mktime(&test));
    printf("Claiming DST (-> %d): %s", test.tm_isdst, asctime_r(&test, datebuffer));
}

int main(void) {
    tzset(); /* Just to be entirely sure it *does* get called. */
    puts("Testing spring forward");
    study(&spring);
    puts("\n\nTesting fall backward");
    study(&autumn);
}
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to