Skip to content

Commit 47f14e7

Browse files
committed
Repair 7.3 breakage in timestamp-to-date conversion for dates before 2000.
1 parent 2d9a001 commit 47f14e7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/backend/utils/adt/date.c

Lines changed: 8 additions & 8 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.84 2003/07/17 00:55:37 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.85 2003/07/24 00:21:26 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -348,17 +348,17 @@ timestamp_date(PG_FUNCTION_ARGS)
348348
{
349349
Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
350350
DateADT result;
351+
struct tm tt,
352+
*tm = &tt;
353+
double fsec;
351354

352355
if (TIMESTAMP_NOT_FINITE(timestamp))
353356
PG_RETURN_NULL();
354357

355-
#ifdef HAVE_INT64_TIMESTAMP
356-
/* Microseconds to days */
357-
result = (timestamp / INT64CONST(86400000000));
358-
#else
359-
/* Seconds to days */
360-
result = (timestamp / 86400.0);
361-
#endif
358+
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
359+
elog(ERROR, "Unable to convert timestamp to date");
360+
361+
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
362362

363363
PG_RETURN_DATEADT(result);
364364
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy