More macro cleanups for date/time.
authorBruce Momjian
Mon, 23 May 2005 21:54:02 +0000 (21:54 +0000)
committerBruce Momjian
Mon, 23 May 2005 21:54:02 +0000 (21:54 +0000)
src/backend/utils/adt/date.c
src/backend/utils/adt/datetime.c
src/backend/utils/adt/nabstime.c
src/backend/utils/adt/timestamp.c
src/include/utils/timestamp.h
src/interfaces/ecpg/pgtypeslib/datetime.c
src/interfaces/ecpg/pgtypeslib/dt.h
src/interfaces/ecpg/pgtypeslib/dt_common.c
src/interfaces/ecpg/pgtypeslib/interval.c
src/interfaces/ecpg/pgtypeslib/timestamp.c
src/timezone/pgtz.c

index 3a0f6b7969fc819b41d1c2034013e5ed45c4c7ee..11bca4f000cde70ea2c21a21559419d6d17f737a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.106 2005/05/23 18:56:55 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.107 2005/05/23 21:54:01 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1339,8 +1339,8 @@ timestamp_time(PG_FUNCTION_ARGS)
 #ifdef HAVE_INT64_TIMESTAMP
 
    /*
-    * Could also do this with time = (timestamp / 86400000000 *
-    * 86400000000) - timestamp;
+    * Could also do this with time = (timestamp / USECS_PER_DAY *
+    * USECS_PER_DAY) - timestamp;
     */
    result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
               * USECS_PER_SEC) + fsec);
@@ -1376,8 +1376,8 @@ timestamptz_time(PG_FUNCTION_ARGS)
 #ifdef HAVE_INT64_TIMESTAMP
 
    /*
-    * Could also do this with time = (timestamp / 86400000000 *
-    * 86400000000) - timestamp;
+    * Could also do this with time = (timestamp / USECS_PER_DAY *
+    * USECS_PER_DAY) - timestamp;
     */
    result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
               * USECS_PER_SEC) + fsec);
@@ -1498,7 +1498,7 @@ time_pl_interval(PG_FUNCTION_ARGS)
    result = (time + span->time);
    TMODULO(result, time1, (double)SECS_PER_DAY);
    if (result < 0)
-       result += 86400;
+       result += SECS_PER_DAY;
 #endif
 
    PG_RETURN_TIMEADT(result);
@@ -1525,7 +1525,7 @@ time_mi_interval(PG_FUNCTION_ARGS)
    result = (time - span->time);
    TMODULO(result, time1, (double)SECS_PER_DAY);
    if (result < 0)
-       result += 86400;
+       result += SECS_PER_DAY;
 #endif
 
    PG_RETURN_TIMEADT(result);
@@ -2033,7 +2033,7 @@ timetz_pl_interval(PG_FUNCTION_ARGS)
    result->time = (time->time + span->time);
    TMODULO(result->time, time1.time, (double)SECS_PER_DAY);
    if (result->time < 0)
-       result->time += 86400;
+       result->time += SECS_PER_DAY;
 #endif
 
    result->zone = time->zone;
@@ -2066,7 +2066,7 @@ timetz_mi_interval(PG_FUNCTION_ARGS)
    result->time = (time->time - span->time);
    TMODULO(result->time, time1.time, (double)SECS_PER_DAY);
    if (result->time < 0)
-       result->time += 86400;
+       result->time += SECS_PER_DAY;
 #endif
 
    result->zone = time->zone;
@@ -2504,9 +2504,9 @@ timetz_zone(PG_FUNCTION_ARGS)
 #else
        result->time = time->time + (time->zone - tz);
        while (result->time < 0)
-           result->time += 86400;
-       while (result->time >= 86400)
-           result->time -= 86400;
+           result->time += SECS_PER_DAY;
+       while (result->time >= SECS_PER_DAY)
+           result->time -= SECS_PER_DAY;
 #endif
 
        result->zone = tz;
@@ -2558,9 +2558,9 @@ timetz_izone(PG_FUNCTION_ARGS)
 #else
    result->time = time->time + (time->zone - tz);
    while (result->time < 0)
-       result->time += 86400;
-   while (result->time >= 86400)
-       result->time -= 86400;
+       result->time += SECS_PER_DAY;
+   while (result->time >= SECS_PER_DAY)
+       result->time -= SECS_PER_DAY;
 #endif
 
    result->zone = tz;
index a1e570f1c85ef0082f028f78722560c7c2b5c7bc..d911fb891cf3e940132402645103893033a39cd0 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.142 2005/05/23 18:56:55 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.143 2005/05/23 21:54:01 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1214,7 +1214,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
                                        &tm->tm_hour, &tm->tm_min,
                                        &tm->tm_sec, fsec);
 #else
-                               dt2time(time * 86400, &tm->tm_hour,
+                               dt2time(time * SECS_PER_DAY, &tm->tm_hour,
                                        &tm->tm_min, &tm->tm_sec, fsec);
 #endif
                            }
@@ -1611,8 +1611,8 @@ DetermineLocalTimeZone(struct pg_tm * tm)
        goto overflow;
    date = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - UNIX_EPOCH_JDATE;
 
-   day = ((pg_time_t) date) *86400;
-   if (day / 86400 != date)
+   day = ((pg_time_t) date) *SECS_PER_DAY;
+   if (day / SECS_PER_DAY != date)
        goto overflow;
    sec = tm->tm_sec + (tm->tm_min + tm->tm_hour * 60) * 60;
    mytime = day + sec;
@@ -1972,7 +1972,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
                                dt2time(time * USECS_PER_DAY,
                                        &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
 #else
-                               dt2time(time * 86400,
+                               dt2time(time * SECS_PER_DAY,
                                        &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
 #endif
                            }
@@ -3099,7 +3099,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
                        {
                            int         sec;
 
-                           fval *= 86400;
+                           fval *= SECS_PER_DAY;
                            sec = fval;
                            tm->tm_sec += sec;
 #ifdef HAVE_INT64_TIMESTAMP
@@ -3117,7 +3117,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
                        {
                            int         sec;
 
-                           fval *= (7 * 86400);
+                           fval *= (7 * SECS_PER_DAY);
                            sec = fval;
                            tm->tm_sec += sec;
 #ifdef HAVE_INT64_TIMESTAMP
@@ -3135,7 +3135,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
                        {
                            int         sec;
 
-                           fval *= (30 * 86400);
+                           fval *= (30 * SECS_PER_DAY);
                            sec = fval;
                            tm->tm_sec += sec;
 #ifdef HAVE_INT64_TIMESTAMP
index 9a164a3e1ea1178d2ffd8d8c52ca86ed1ca7c903..1ed6321fd0f3a53be4ee527534cf12b9fec6f054 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.129 2005/05/23 18:56:55 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.130 2005/05/23 21:54:02 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -129,10 +129,10 @@ AbsoluteTimeUsecToTimestampTz(AbsoluteTime sec, int usec)
    TimestampTz result;
 
 #ifdef HAVE_INT64_TIMESTAMP
-   result = ((sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400))
+   result = ((sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY))
              * USECS_PER_SEC) + usec;
 #else
-   result = sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400)
+   result = sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)
        + (usec / 1000000.0);
 #endif
 
@@ -730,7 +730,7 @@ reltimein(PG_FUNCTION_ARGS)
    {
        case DTK_DELTA:
            result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec);
-           result += ((tm->tm_year * 36525 * 864) + (((tm->tm_mon * 30) + tm->tm_mday) * 86400));
+           result += ((tm->tm_year * 36525 * 864) + (((tm->tm_mon * 30) + tm->tm_mday) * SECS_PER_DAY));
            break;
 
        default:
@@ -795,7 +795,7 @@ reltime2tm(RelativeTime time, struct pg_tm * tm)
 
    FMODULO(dtime, tm->tm_year, 31557600);
    FMODULO(dtime, tm->tm_mon, 2592000);
-   FMODULO(dtime, tm->tm_mday, 86400);
+   FMODULO(dtime, tm->tm_mday, SECS_PER_DAY);
    FMODULO(dtime, tm->tm_hour, 3600);
    FMODULO(dtime, tm->tm_min, 60);
    FMODULO(dtime, tm->tm_sec, 1);
@@ -947,10 +947,10 @@ interval_reltime(PG_FUNCTION_ARGS)
 
 #ifdef HAVE_INT64_TIMESTAMP
    span = ((((INT64CONST(365250000) * year) + (INT64CONST(30000000) * month))
-            * INT64CONST(86400)) + interval->time);
+            * INT64CONST(SECS_PER_DAY)) + interval->time);
    span /= USECS_PER_SEC;
 #else
-   span = (((((double) 365.25 * year) + ((double) 30 * month)) * 86400) + interval->time);
+   span = (((((double) 365.25 * year) + ((double) 30 * month)) * SECS_PER_DAY) + interval->time);
 #endif
 
    if ((span < INT_MIN) || (span > INT_MAX))
@@ -986,13 +986,13 @@ reltime_interval(PG_FUNCTION_ARGS)
 #ifdef HAVE_INT64_TIMESTAMP
            year = (reltime / (36525 * 864));
            reltime -= (year * (36525 * 864));
-           month = (reltime / (30 * 86400));
-           reltime -= (month * (30 * 86400));
+           month = (reltime / (30 * SECS_PER_DAY));
+           reltime -= (month * (30 * SECS_PER_DAY));
 
            result->time = (reltime * USECS_PER_SEC);
 #else
            TMODULO(reltime, year, (36525 * 864));
-           TMODULO(reltime, month, (30 * 86400));
+           TMODULO(reltime, month, (30 * SECS_PER_DAY));
 
            result->time = reltime;
 #endif
index b5c782e78c3caff907a638f2501b534c28203a02..573ef6e058219cb55a73a1cb261e6d501bf0cc4d 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.121 2005/05/23 18:56:55 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.122 2005/05/23 21:54:02 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -699,7 +699,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
                                USECS_PER_DAY;
 
 #else
-           interval->time = ((int) (interval->time / 86400)) * 86400;
+           interval->time = ((int) (interval->time / SECS_PER_DAY)) * SECS_PER_DAY;
 #endif
        }
        else if (range == INTERVAL_MASK(HOUR))
@@ -1021,7 +1021,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
 
    if (time < 0)
    {
-       time += 86400;
+       time += SECS_PER_DAY;
        date -=1;
    }
 #endif
@@ -1074,10 +1074,10 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
     */
 #ifdef HAVE_INT64_TIMESTAMP
    dt = (dt - *fsec) / USECS_PER_SEC +
-       (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400;
+       (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY;
 #else
    dt = rint(dt - *fsec +
-             (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400);
+             (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY);
 #endif
    utime = (pg_time_t) dt;
    if ((Timestamp) utime == dt)
@@ -1151,7 +1151,7 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
        (*result >= 0 && date < 0))
        return -1;
 #else
-   *result = date * 86400 + time;
+   *result = date * SECS_PER_DAY + time;
 #endif
    if (tzp != NULL)
        *result = dt2local(*result, -(*tzp));
@@ -1621,9 +1621,9 @@ interval_cmp_internal(Interval *interval1, Interval *interval2)
        span2 += interval2->month * INT64CONST(30) * USECS_PER_DAY;
 #else
    if (interval1->month != 0)
-       span1 += interval1->month * (30.0 * 86400);
+       span1 += interval1->month * (30.0 * SECS_PER_DAY);
    if (interval2->month != 0)
-       span2 += interval2->month * (30.0 * 86400);
+       span2 += interval2->month * (30.0 * SECS_PER_DAY);
 #endif
 
    return ((span1 < span2) ? -1 : (span1 > span2) ? 1 : 0);
@@ -2166,7 +2166,7 @@ interval_mul(PG_FUNCTION_ARGS)
    result->month = rint(months);
    result->time = JROUND(span1->time * factor);
    /* evaluate fractional months as 30 days */
-   result->time += JROUND((months - result->month) * 30 * 86400);
+   result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY);
 #endif
 
    PG_RETURN_INTERVAL_P(result);
@@ -2211,7 +2211,7 @@ interval_div(PG_FUNCTION_ARGS)
    result->month = rint(months);
    result->time = JROUND(span->time / factor);
    /* evaluate fractional months as 30 days */
-   result->time += JROUND((months - result->month) * 30 * 86400);
+   result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY);
 #endif
 
    PG_RETURN_INTERVAL_P(result);
@@ -3788,8 +3788,8 @@ interval_part(PG_FUNCTION_ARGS)
 #endif
        if (interval->month != 0)
        {
-           result += (365.25 * 86400) * (interval->month / 12);
-           result += (30.0 * 86400) * (interval->month % 12);
+           result += (365.25 * SECS_PER_DAY) * (interval->month / 12);
+           result += (30.0 * SECS_PER_DAY) * (interval->month % 12);
        }
    }
    else
index 57d1e64f789227e523122a1a191f9d280ea5f594..743d58ac9690148e10622b505a7ddc5f7120062d 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.41 2005/05/23 18:56:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.42 2005/05/23 21:54:02 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -60,10 +60,12 @@ typedef struct
 #define MAX_INTERVAL_PRECISION 6
 
 #define SECS_PER_DAY   86400
+#ifdef HAVE_INT64_TIMESTAMP
 #define USECS_PER_DAY  INT64CONST(86400000000)
 #define USECS_PER_HOUR INT64CONST(3600000000)
 #define USECS_PER_MINUTE INT64CONST(60000000)
 #define USECS_PER_SEC  INT64CONST(1000000)
+#endif
 
 /*
  * Macros for fmgr-callable functions.
index 30781d734f58325c6703cb32dd9250dfacc9cd39..cda4e5aab8e67a82d3aba9559c9a71127ef19411 100644 (file)
@@ -22,10 +22,10 @@ PGTYPESdate_from_timestamp(timestamp dt)
 
 #ifdef HAVE_INT64_TIMESTAMP
        /* Microseconds to days */
-           dDate = (dt / INT64CONST(86400000000));
+           dDate = (dt / USECS_PER_DAY);
 #else
        /* Seconds to days */
-           dDate = (dt / 86400.0);
+           dDate = (dt / (double)SECS_PER_DAY);
 #endif
 
    return dDate;
index e000ec4411c70ce4262c9a5c009d2a3a8de66372..53108a85bf4fcc3c0f8e343a5a256777a9516f9c 100644 (file)
@@ -216,6 +216,14 @@ do { \
 } while(0)
 #endif
 
+#define SECS_PER_DAY   86400
+#ifdef HAVE_INT64_TIMESTAMP
+#define USECS_PER_DAY  INT64CONST(86400000000)
+#define USECS_PER_HOUR INT64CONST(3600000000)
+#define USECS_PER_MINUTE INT64CONST(60000000)
+#define USECS_PER_SEC  INT64CONST(1000000)
+#endif
+
 /*
  * Date/time validation
  * Include check for leap year.
index 91a8d611b390b4e7aaa246de4a7655194e6f3aa0..f516d281d457ded8967984c85f771aba80895bae 100644 (file)
@@ -1246,12 +1246,12 @@ dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
 
    time = jd;
 #ifdef HAVE_INT64_TIMESTAMP
-   *hour = (time / INT64CONST(3600000000));
-   time -= ((*hour) * INT64CONST(3600000000));
-   *min = (time / INT64CONST(60000000));
-   time -= ((*min) * INT64CONST(60000000));
-   *sec = (time / INT64CONST(1000000));
-   *fsec = (time - (*sec * INT64CONST(1000000)));
+   *hour = (time / USECS_PER_HOUR);
+   time -= ((*hour) * USECS_PER_HOUR);
+   *min = (time / USECS_PER_MINUTE);
+   time -= ((*min) * USECS_PER_MINUTE);
+   *sec = (time / USECS_PER_SEC);
+   *fsec = (time - (*sec * USECS_PER_SEC));
 #else
    *hour = (time / 3600);
    time -= ((*hour) * 3600);
@@ -1675,7 +1675,7 @@ DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
    if ((tm->tm_hour < 0)
        || (tm->tm_min < 0) || (tm->tm_min > 59)
        || (tm->tm_sec < 0) || (tm->tm_sec > 59)
-       || (*fsec >= INT64CONST(1000000)))
+       || (*fsec >= USECS_PER_SEC))
        return -1;
 #else
    if ((tm->tm_hour < 0)
@@ -2257,7 +2257,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
 #ifdef HAVE_INT64_TIMESTAMP
                                dt2time((time * USECS_PER_DAY), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
 #else
-                               dt2time((time * 86400), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
+                               dt2time((time * SECS_PER_DAY), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
 #endif
                            }
                            break;
index eb18e6ce9127bfd9d0c258d44d6f0a3b0141398c..3c09071ce796cb531e2a56f106c694c982a27cc1 100644 (file)
@@ -88,7 +88,7 @@ DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
    if ((tm->tm_hour < 0)
        || (tm->tm_min < 0) || (tm->tm_min > 59)
        || (tm->tm_sec < 0) || (tm->tm_sec > 59)
-       || (*fsec >= INT64CONST(1000000)))
+       || (*fsec >= USECS_PER_SEC))
        return -1;
 #else
    if ((tm->tm_hour < 0)
@@ -296,7 +296,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fse
                        {
                            int         sec;
 
-                           fval *= 86400;
+                           fval *= SECS_PER_DAY;
                            sec = fval;
                            tm->tm_sec += sec;
 #ifdef HAVE_INT64_TIMESTAMP
@@ -314,7 +314,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fse
                        {
                            int         sec;
 
-                           fval *= (7 * 86400);
+                           fval *= (7 * SECS_PER_DAY);
                            sec = fval;
                            tm->tm_sec += sec;
 #ifdef HAVE_INT64_TIMESTAMP
@@ -332,7 +332,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fse
                        {
                            int         sec;
 
-                           fval *= (30 * 86400);
+                           fval *= (30 * SECS_PER_DAY);
                            sec = fval;
                            tm->tm_sec += sec;
 #ifdef HAVE_INT64_TIMESTAMP
@@ -419,8 +419,8 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fse
        int         sec;
 
 #ifdef HAVE_INT64_TIMESTAMP
-       sec = (*fsec / INT64CONST(1000000));
-       *fsec -= (sec * INT64CONST(1000000));
+       sec = (*fsec / USECS_PER_SEC);
+       *fsec -= (sec * USECS_PER_SEC);
 #else
        TMODULO(*fsec, sec, 1e0);
 #endif
@@ -702,14 +702,14 @@ interval2tm(interval span, struct tm * tm, fsec_t *fsec)
 #ifdef HAVE_INT64_TIMESTAMP
    tm->tm_mday = (time / USECS_PER_DAY);
    time -= (tm->tm_mday * USECS_PER_DAY);
-   tm->tm_hour = (time / INT64CONST(3600000000));
-   time -= (tm->tm_hour * INT64CONST(3600000000));
-   tm->tm_min = (time / INT64CONST(60000000));
-   time -= (tm->tm_min * INT64CONST(60000000));
-   tm->tm_sec = (time / INT64CONST(1000000));
-   *fsec = (time - (tm->tm_sec * INT64CONST(1000000)));
+   tm->tm_hour = (time / USECS_PER_HOUR);
+   time -= (tm->tm_hour * USECS_PER_HOUR);
+   tm->tm_min = (time / USECS_PER_MINUTE);
+   time -= (tm->tm_min * USECS_PER_MINUTE);
+   tm->tm_sec = (time / USECS_PER_SEC);
+   *fsec = (time - (tm->tm_sec * USECS_PER_SEC));
 #else
-   TMODULO(time, tm->tm_mday, 86400e0);
+   TMODULO(time, tm->tm_mday, (double)SECS_PER_DAY);
    TMODULO(time, tm->tm_hour, 3600e0);
    TMODULO(time, tm->tm_min, 60e0);
    TMODULO(time, tm->tm_sec, 1e0);
@@ -727,7 +727,7 @@ tm2interval(struct tm * tm, fsec_t fsec, interval *span)
    span->time = ((((((((tm->tm_mday * INT64CONST(24))
                        + tm->tm_hour) * INT64CONST(60))
                      + tm->tm_min) * INT64CONST(60))
-                   + tm->tm_sec) * INT64CONST(1000000)) + fsec);
+                   + tm->tm_sec) * USECS_PER_SEC) + fsec);
 #else
    span->time = ((((((tm->tm_mday * 24.0)
                      + tm->tm_hour) * 60.0)
index 971a4175174b88b0bcb3b76e4e8e821b7169370c..836ae62e9048d3e0a7c6c453ba8b4add6e3415dd 100644 (file)
@@ -20,7 +20,7 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int
 static int64
 time2t(const int hour, const int min, const int sec, const fsec_t fsec)
 {
-   return ((((((hour * 60) + min) * 60) + sec) * INT64CONST(1000000)) + fsec);
+   return ((((((hour * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec);
 }  /* time2t() */
 
 #else
@@ -35,7 +35,7 @@ static timestamp
 dt2local(timestamp dt, int tz)
 {
 #ifdef HAVE_INT64_TIMESTAMP
-   dt -= (tz * INT64CONST(1000000));
+   dt -= (tz * USECS_PER_SEC);
 #else
    dt -= tz;
    dt = JROUND(dt);
@@ -77,7 +77,7 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp *result)
    if ((*result < 0) ? (dDate >= 0) : (dDate < 0))
        return -1;
 #else
-   *result = ((dDate * 86400) + time);
+   *result = ((dDate * SECS_PER_DAY) + time);
 #endif
    if (tzp != NULL)
        *result = dt2local(*result, -(*tzp));
@@ -110,14 +110,14 @@ dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
    time = jd;
 
 #ifdef HAVE_INT64_TIMESTAMP
-   *hour = (time / INT64CONST(3600000000));
-   time -= ((*hour) * INT64CONST(3600000000));
-   *min = (time / INT64CONST(60000000));
-   time -= ((*min) * INT64CONST(60000000));
-   *sec = (time / INT64CONST(1000000));
-   *fsec = (time - (*sec * INT64CONST(1000000)));
-   *sec = (time / INT64CONST(1000000));
-   *fsec = (time - (*sec * INT64CONST(1000000)));
+   *hour = (time / USECS_PER_HOUR);
+   time -= ((*hour) * USECS_PER_HOUR);
+   *min = (time / USECS_PER_MINUTE);
+   time -= ((*min) * USECS_PER_MINUTE);
+   *sec = (time / USECS_PER_SEC);
+   *fsec = (time - (*sec * USECS_PER_SEC));
+   *sec = (time / USECS_PER_SEC);
+   *fsec = (time - (*sec * USECS_PER_SEC));
 #else
    *hour = (time / 3600);
    time -= ((*hour) * 3600);
@@ -171,11 +171,11 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
        dDate -= 1;
    }
 #else
-   TMODULO(time, dDate, 86400e0);
+   TMODULO(time, dDate, (double)SECS_PER_DAY);
 
    if (time < 0)
    {
-       time += 86400;
+       time += SECS_PER_DAY;
        dDate -= 1;
    }
 #endif
@@ -199,10 +199,10 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
        if (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
        {
 #ifdef HAVE_INT64_TIMESTAMP
-           utime = ((dt / INT64CONST(1000000))
-                  + ((date0 - date2j(1970, 1, 1)) * INT64CONST(86400)));
+           utime = ((dt / USECS_PER_SEC)
+                  + ((date0 - date2j(1970, 1, 1)) * INT64CONST(SECS_PER_DAY)));
 #else
-           utime = (dt + ((date0 - date2j(1970, 1, 1)) * 86400));
+           utime = (dt + ((date0 - date2j(1970, 1, 1)) * SECS_PER_DAY));
 #endif
 
 #if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
index f228ed5bacfd491e6b61d4b0049696e0b014be0e..bdf3d40407916ceded48ff67ad56a14af0cbc691 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.30 2005/04/19 03:13:59 momjian Exp $
+ *   $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.31 2005/05/23 21:54:02 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1062,7 +1062,7 @@ tz_acceptable(pg_tz *tz)
     * be GMT midnight, 2000-01-01.  Insist that the tm_sec value be zero;
     * any other result has to be due to leap seconds.
     */
-   time2000 = (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400;
+   time2000 = (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY;
    tt = pg_localtime(&time2000, tz);
    if (!tt || tt->tm_sec != 0)
        return false;