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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: bug in date_part() function in 6.5.2, 7.0.2
Дата
Msg-id 24629.968422140@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: bug in date_part() function in 6.5.2, 7.0.2  (Thomas Lockhart <lockhart@alumni.caltech.edu>)
Список 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 по дате отправления:

Предыдущее
От: Thomas Lockhart
Дата:
Сообщение: Re: bug in date_part() function in 6.5.2, 7.0.2
Следующее
От: Thomas Lockhart
Дата:
Сообщение: Re: bug in date_part() function in 6.5.2, 7.0.2