Fix timestamp to date conversion for the case where timestamp uses a double
authorThomas G. Lockhart <[email protected]>
Sat, 1 Jun 2002 15:52:15 +0000 (15:52 +0000)
committerThomas G. Lockhart <[email protected]>
Sat, 1 Jun 2002 15:52:15 +0000 (15:52 +0000)
 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.

src/backend/utils/adt/date.c

index 76b6bf80c09d880387608a340e10df1dd13178a0..75e29e0923c4984c1d0fa30d6d6b5917ae3ab0fd 100644 (file)
@@ -308,22 +308,16 @@ timestamp_date(PG_FUNCTION_ARGS)
 {
        Timestamp       timestamp = PG_GETARG_TIMESTAMP(0);
        DateADT         result;
-#if 0
-       struct tm       tt,
-                          *tm = &tt;
-       fsec_t          fsec;
-#endif
 
        if (TIMESTAMP_NOT_FINITE(timestamp))
                PG_RETURN_NULL();
 
-#if 0
-       if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
-               elog(ERROR, "Unable to convert timestamp to date");
-
-       result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
-#else
+#ifdef HAVE_INT64_TIMESTAMP
+       /* Microseconds to days */
        result = (timestamp / INT64CONST(86400000000));
+#else
+       /* Seconds to days */
+       result = (timestamp / 86400.0);
 #endif
 
        PG_RETURN_DATEADT(result);