This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: A patch for mktime.c and tz*.c.


> 
>    From: hjl@lucon.org (H.J. Lu)
>    Date: Fri, 6 Nov 1998 11:10:23 -0800 (PST)
> 
>    Paul's change looks ok. But I still don't like guessing unless we
>    don't have a choice. For glibc 2, there is no need to guess with
>    my patch.
> 
> Unfortunately, that patch appears to have a bug similar to one that
> was in the Olson code had before 1995: it assumes that the DST offset
> never changes.
> 
> This assumption is true for POSIX.1 TZ specifications, but it's false
> for the Olson database.  For example, the first time that New Zealand
> used DST, it used a 30-minute DST offset, and (from code inspection)
> it appears that the patch will pick up this value and incorrectly
> assume that New Zealand always uses a 30-minute DST offset.
> 

I may have missed something here. My patch doesn't assume anything.
The key here is "daylight" stores the DST offset which is used to
compute DST at the given time.

As long as "daylight" is correct, I don't see how it can be a problem.
If you are saying "daylight" is not always correct in my patch, I
don't think it is too hard to make sure we always store the correct
value in it. I am enclosing a testcase here. I don't see anything
wrong.

# gcc t.c
# a.out
min: 0
hour: 23
isdst: 0
886244400
Sat Jan 31 23:00:00 1998


> This is an instance of a more general problem.  Given the current
> mktime interface, mktime _must_ guess in some cases.  For example, how
> much should mktime adjust 1989-01-01 00:00:00 with tm_isdst=1 in
> Newfoundland, which used a 2-hour DST offset in summer 1988 and a
> 1-hour DST offset in summer 1989?  There's no way for mktime to know
> whether a 2-hour or a 1-hour adjustment is correct.
> 

Since it is not speficied, there is no unique answer.


H.J.
---
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>

static
int
test (struct tm *xp, time_t expected)
{
  time_t t;

  t = mktime (xp);
  printf ("min: %d\n", xp->tm_min);
  printf ("hour: %d\n", xp->tm_hour);
  printf ("isdst: %d\n", xp->tm_isdst);
  printf ("%u\n", t);
  printf ("%s", ctime (&t));
  if (t != expected)
    return -1;
  else
    return 0;
}

static
int
set_tz(char *tzval)
{
  char *tz;
  static char buf[256];

  strcpy(buf, "TZ=");
  strcat(buf, tzval);
  putenv(buf);
  tz = getenv("TZ");
  if (tz == NULL || strcmp(tz, tzval) != 0)
    return -1;
  else
    return 0;
}

main (int argc, char **argv)
{
  struct tm x;
  time_t expected;
  int failed = 0;

  if (set_tz ("NZST-12NZDT"))
    {
      printf ("Failed to set TZ to NZST-12NZDT\n");
      return 1;
    }

  x.tm_sec = 0;
  x.tm_min = 0;
  x.tm_hour = 0;
  x.tm_mday = 1;
  x.tm_mon = 1;
  x.tm_year = 98;
  x.tm_wday = -1;
  x.tm_yday = -1;
  x.tm_isdst = 1;
  expected = -1;

  test (&x, expected);

  return failed;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]