Commit 5ebaae80 authored by Bruce Momjian's avatar Bruce Momjian

Add datetime macros for constants, for clarity:

#define SECS_PER_DAY  86400
#define USECS_PER_DAY INT64CONST(86400000000)
#define USECS_PER_HOUR    INT64CONST(3600000000)
#define USECS_PER_MINUTE INT64CONST(60000000)
#define USECS_PER_SEC INT64CONST(1000000)
parent 33d0d4ce
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.141 2005/05/23 17:13:14 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.142 2005/05/23 18:56:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1210,7 +1210,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tmask |= DTK_TIME_M;
#ifdef HAVE_INT64_TIMESTAMP
dt2time(time * INT64CONST(86400000000),
dt2time(time * USECS_PER_DAY,
&tm->tm_hour, &tm->tm_min,
&tm->tm_sec, fsec);
#else
......@@ -1969,7 +1969,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
tmask |= DTK_TIME_M;
#ifdef HAVE_INT64_TIMESTAMP
dt2time(time * INT64CONST(86400000000),
dt2time(time * USECS_PER_DAY,
&tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
#else
dt2time(time * 86400,
......@@ -2193,7 +2193,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
#ifdef HAVE_INT64_TIMESTAMP
if (tm->tm_hour < 0 || tm->tm_hour > 23 || tm->tm_min < 0 ||
tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 ||
*fsec < INT64CONST(0) || *fsec >= INT64CONST(1000000))
*fsec < INT64CONST(0) || *fsec >= USECS_PER_SEC)
return DTERR_FIELD_OVERFLOW;
#else
if (tm->tm_hour < 0 || tm->tm_hour > 23 || tm->tm_min < 0 ||
......@@ -2447,7 +2447,7 @@ DecodeTime(char *str, int fmask, int *tmask, struct pg_tm * tm, fsec_t *fsec)
#ifdef HAVE_INT64_TIMESTAMP
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
tm->tm_sec < 0 || tm->tm_sec > 60 || *fsec < INT64CONST(0) ||
*fsec >= INT64CONST(1000000))
*fsec >= USECS_PER_SEC)
return DTERR_FIELD_OVERFLOW;
#else
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
......@@ -3222,8 +3222,8 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
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
......
......@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.128 2005/04/19 03:13:59 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.129 2005/05/23 18:56:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -130,7 +130,7 @@ AbsoluteTimeUsecToTimestampTz(AbsoluteTime sec, int usec)
#ifdef HAVE_INT64_TIMESTAMP
result = ((sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400))
* INT64CONST(1000000)) + usec;
* USECS_PER_SEC) + usec;
#else
result = sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400)
+ (usec / 1000000.0);
......@@ -948,7 +948,7 @@ interval_reltime(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
span = ((((INT64CONST(365250000) * year) + (INT64CONST(30000000) * month))
* INT64CONST(86400)) + interval->time);
span /= INT64CONST(1000000);
span /= USECS_PER_SEC;
#else
span = (((((double) 365.25 * year) + ((double) 30 * month)) * 86400) + interval->time);
#endif
......@@ -989,7 +989,7 @@ reltime_interval(PG_FUNCTION_ARGS)
month = (reltime / (30 * 86400));
reltime -= (month * (30 * 86400));
result->time = (reltime * INT64CONST(1000000));
result->time = (reltime * USECS_PER_SEC);
#else
TMODULO(reltime, year, (36525 * 864));
TMODULO(reltime, month, (30 * 86400));
......
This diff is collapsed.
......@@ -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.40 2004/12/31 22:03:46 pgsql Exp $
* $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.41 2005/05/23 18:56:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -59,6 +59,11 @@ typedef struct
#define MAX_TIMESTAMP_PRECISION 6
#define MAX_INTERVAL_PRECISION 6
#define SECS_PER_DAY 86400
#define USECS_PER_DAY INT64CONST(86400000000)
#define USECS_PER_HOUR INT64CONST(3600000000)
#define USECS_PER_MINUTE INT64CONST(60000000)
#define USECS_PER_SEC INT64CONST(1000000)
/*
* Macros for fmgr-callable functions.
......
......@@ -2255,7 +2255,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tmask |= DTK_TIME_M;
#ifdef HAVE_INT64_TIMESTAMP
dt2time((time * INT64CONST(86400000000)), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
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);
#endif
......
......@@ -700,8 +700,8 @@ interval2tm(interval span, struct tm * tm, fsec_t *fsec)
time = span.time;
#ifdef HAVE_INT64_TIMESTAMP
tm->tm_mday = (time / INT64CONST(86400000000));
time -= (tm->tm_mday * INT64CONST(86400000000));
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));
......
......@@ -69,9 +69,9 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp *result)
dDate = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
#ifdef HAVE_INT64_TIMESTAMP
*result = (dDate * INT64CONST(86400000000)) + time;
*result = (dDate * USECS_PER_DAY) + time;
/* check for major overflow */
if ((*result - time) / INT64CONST(86400000000) != dDate)
if ((*result - time) / USECS_PER_DAY != dDate)
return -1;
/* check for just-barely overflow (okay except time-of-day wraps) */
if ((*result < 0) ? (dDate >= 0) : (dDate < 0))
......@@ -163,11 +163,11 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
time = dt;
#ifdef HAVE_INT64_TIMESTAMP
TMODULO(time, dDate, INT64CONST(86400000000));
TMODULO(time, dDate, USECS_PER_DAY);
if (time < INT64CONST(0))
{
time += INT64CONST(86400000000);
time += USECS_PER_DAY;
dDate -= 1;
}
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment