Re: Bug #630: date/time storage problem: timestamp parsed

From: Sean Chittenden <sean(at)chittenden(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Thomas Lockhart <lockhart(at)fourpalms(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug #630: date/time storage problem: timestamp parsed
Date: 2002-04-14 21:15:34
Message-ID: 20020414141534.Z34216@ninja1.internal
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> Ugh, I'm too tired to file a gdb report:
>
> 1490 t = mktime(tmp);
> (gdb)
> 1491 fprintf(stderr, "%p\n", t);
> (gdb) print t
> $7 = -1
>
> Good call Tom. ... I'm going to file a PR w/ FreeBSD.

The FreeBSD folk are absolutely adamant about having mktime() no
compensate for deadzones between DST shifts and they insist that the
application handle this. Someone's off looking at how other OS'es
handle this, but this could be an arduous battle on that front. <:~)

> I know the attached patch is something of a hack, but it works. I'm
> not totally wild about altering the original time object, but I
> don't know that I have a choice in this case. Does anyone switch
> timezones and only adjust their clocks by anything other than 60min?
> I seem to recall that happening in a few places, but the patch isn't
> any worse than where we are now. ::shrug:: This look like an okay
> patch?

Are there any objections to the following? Instead of returning 0 or
utc, I could have it raise an error. Would that be acceptable? -sc

> Index: src/backend/utils/adt/datetime.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/datetime.c,v
> retrieving revision 1.88
> diff -u -r1.88 datetime.c
> --- src/backend/utils/adt/datetime.c 2002/02/25 16:17:04 1.88
> +++ src/backend/utils/adt/datetime.c 2002/04/10 06:12:45
> @@ -1439,6 +1439,7 @@
> DetermineLocalTimeZone(struct tm * tm)
> {
> int tz;
> + time_t t;
>
> if (HasCTZSet)
> tz = CTimeZone;
> @@ -1463,7 +1464,23 @@
> /* indicate timezone unknown */
> tmp->tm_isdst = -1;
>
> - mktime(tmp);
> + t = mktime(tmp);
> + if (t == -1)
> + {
> + /* Bump time up by an hour to see if time was an
> + * invalid time during a daylight savings switch */
> + tmp->tm_hour += 1;
> + t = mktime(tmp);
> +
> + /* Assume UTC if mktime() still fails.
> + *
> + * If mktime() was successful with the adjusted time,
> + * adjust the real time object. */
> + if (t == -1)
> + return 0;
> + else
> + tm->tm_hour += 1;
> + }
>
> tm->tm_isdst = tmp->tm_isdst;
>

--
Sean Chittenden

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2002-04-14 23:04:11 Re: Bug #597: ResultSet.next() throws NullPointerException
Previous Message Tom Lane 2002-04-14 17:37:18 Re: 7.2 crash...