1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-28 11:44:57 +03:00

Repair 7.3 breakage in timestamp-to-date conversion for dates before 2000.

This commit is contained in:
Tom Lane
2003-07-24 00:21:31 +00:00
parent 83bc9b9d2e
commit fa67e2ce4f

View File

@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.73.2.5 2003/06/16 18:56:53 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.73.2.6 2003/07/24 00:21:31 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -319,17 +319,17 @@ timestamp_date(PG_FUNCTION_ARGS)
{ {
Timestamp timestamp = PG_GETARG_TIMESTAMP(0); Timestamp timestamp = PG_GETARG_TIMESTAMP(0);
DateADT result; DateADT result;
struct tm tt,
*tm = &tt;
double fsec;
if (TIMESTAMP_NOT_FINITE(timestamp)) if (TIMESTAMP_NOT_FINITE(timestamp))
PG_RETURN_NULL(); PG_RETURN_NULL();
#ifdef HAVE_INT64_TIMESTAMP if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
/* Microseconds to days */ elog(ERROR, "Unable to convert timestamp to date");
result = (timestamp / INT64CONST(86400000000));
#else result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
/* Seconds to days */
result = (timestamp / 86400.0);
#endif
PG_RETURN_DATEADT(result); PG_RETURN_DATEADT(result);
} }