Skip to content

Commit 17adf80

Browse files
author
Thomas G. Lockhart
committed
Fix timestamp to date conversion for the case where timestamp uses a double
precision storage format. Previously applied the same math as used for the 64-bit integer storage format case, which was wrong. Problem introduced recently when the 64-bit storage format was implemented.
1 parent 606db06 commit 17adf80

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/backend/utils/adt/date.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.66 2002/04/21 19:48:12 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.67 2002/06/01 15:52:15 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -308,22 +308,16 @@ timestamp_date(PG_FUNCTION_ARGS)
308308
{
309309
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
310310
DateADT result;
311-
#if 0
312-
struct tm tt,
313-
*tm = &tt;
314-
fsec_t fsec;
315-
#endif
316311

317312
if (TIMESTAMP_NOT_FINITE(timestamp))
318313
PG_RETURN_NULL();
319314

320-
#if 0
321-
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
322-
elog(ERROR, "Unable to convert timestamp to date");
323-
324-
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
325-
#else
315+
#ifdef HAVE_INT64_TIMESTAMP
316+
/* Microseconds to days */
326317
result = (timestamp / INT64CONST(86400000000));
318+
#else
319+
/* Seconds to days */
320+
result = (timestamp / 86400.0);
327321
#endif
328322

329323
PG_RETURN_DATEADT(result);

0 commit comments

Comments
 (0)