Re: bug in date_part() function in 6.5.2, 7.0.2

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>, analyst(at)sibinet(dot)ru, pgsql-bugs(at)postgresql(dot)org
Subject: Re: bug in date_part() function in 6.5.2, 7.0.2
Date: 2000-09-07 14:22:41
Message-ID: 39B7A4B1.7AB01185@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> >> Looks to me like an off-by-one kind of problem in deciding which
> >> timezone applies to midnight of a transition day.
> > The date->timestamp conversion code gets this right, so you might want
> > to look at that.
> Au contraire: the cited examples appear to prove that the
> date->timestamp conversion code gets this *wrong*. Or did
> you miss the point of
> regression=# select '2000-04-02'::date::timestamp;
> ?column?
> ------------------------
> 2000-04-01 23:00:00-05
> (1 row)

*sigh* Well, of course I missed the point. Thanks for clarifying that ;)

OK, the situation is coming back to me now. The conversion is done in
steps:

1) Check that the date is likely to be within the Unix system time
range. Otherwise, do all conversions/calculations in UTC.

2) Convert to an integer "Unix system time".

3) Rotate by 12 hours (to UTC noon!). This is supposed to ensure that we
stay in the correct day after conversion to local time *no matter what
time zone we are actually in*, but is likely the problem in this edge
case.

4) Call localtime() to fill in the fields of a tm structure. This is how
I get ahold of the time zone (which is not known before this step). For
this DST edge case, the time zone is off by one hour :(

5) Copy the fields from the result of the call to localtime() into a new
tm structure, with zeros for time fields.

6) Call tm2timestamp(), which recalculates an internal UTC-based
timestamp value based on the current contents of the tm structure.

It *may* be possible to run through some of these steps *twice*, to
verify that the conversion to/from the tm structure including time zone
info gives a result on an even day boundary. But it sounds expensive.

Comments and suggestions are appreciated...

- Thomas

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message pgsql-bugs 2000-09-07 15:56:30 Select from array slices doesn't work
Previous Message Sean Kelly 2000-09-07 12:28:09 Re: How to connect to a remote database