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

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Lockhart <lockhart@alumni.caltech.edu>
Cc: Karel Zak <zakkr@zf.jcu.cz>, analyst@sibinet.ru, pgsql-bugs@postgresql.org
Date: 2000-09-08T14:09:00Z
Lists: 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