Re: bug in date_part() function in 6.5.2, 7.0.2 - Mailing list pgsql-bugs

From Tom Lane
Subject Re: bug in date_part() function in 6.5.2, 7.0.2
Date
Msg-id 24629.968422140@sss.pgh.pa.us
Whole thread Raw
In response to Re: bug in date_part() function in 6.5.2, 7.0.2  (Thomas Lockhart <lockhart@alumni.caltech.edu>)
List pgsql-bugs
Thomas Lockhart <lockhart@alumni.caltech.edu> writes:
>> Seems like you could just skip step 3 and call localtime() with fields
>> indicating midnight of the specified date.  Then use the complete
>> localtime result (don't discard any fields) and you should be OK, no?

> Pretty sure this won't work, since the complete localtime result will
> not be local midnight, which is the expected result.

Actually, now that I go back and reread the man pages, the correct
recipe is
    * fill a struct tm with y/m/d, h = m = s = 0, isdst = -1
    * call mktime() to produce a time_t
    * either use the updated struct tm (mktime() side effect),
          or convert the time_t directly to timestamp.

mktime() is an ANSI C requirement, so even though it's not as old as
localtime(), it's probably safe enough.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: bug in date_part() function in 6.5.2, 7.0.2
Next
From: Thomas Lockhart
Date:
Subject: Re: bug in date_part() function in 6.5.2, 7.0.2