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)
This commit is contained in:
Bruce Momjian 2005-05-23 18:56:55 +00:00
parent 33d0d4ce96
commit 5ebaae801c
8 changed files with 146 additions and 141 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.105 2005/04/23 22:53:05 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.106 2005/05/23 18:56:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -281,11 +281,11 @@ date_mii(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
/* date is days since 2000, timestamp is microseconds since same... */
#define date2timestamp(dateVal) \
((Timestamp) ((dateVal) * INT64CONST(86400000000)))
((Timestamp) ((dateVal) * USECS_PER_DAY))
#else
/* date is days since 2000, timestamp is seconds since same... */
#define date2timestamp(dateVal) \
((Timestamp) ((dateVal) * 86400.0))
((Timestamp) ((dateVal) * (double)SECS_PER_DAY))
#endif
static TimestampTz
@ -305,10 +305,10 @@ date2timestamptz(DateADT dateVal)
tz = DetermineLocalTimeZone(tm);
#ifdef HAVE_INT64_TIMESTAMP
result = (dateVal * INT64CONST(86400000000))
+ (tz * INT64CONST(1000000));
result = (dateVal * USECS_PER_DAY)
+ (tz * USECS_PER_SEC);
#else
result = dateVal * 86400.0 + tz;
result = dateVal * (double)SECS_PER_DAY + tz;
#endif
return result;
@ -922,7 +922,7 @@ tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
*result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
* INT64CONST(1000000)) + fsec);
* USECS_PER_SEC) + fsec);
#else
*result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
#endif
@ -938,12 +938,12 @@ static int
time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
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));
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);
time -= (tm->tm_sec * USECS_PER_SEC);
*fsec = time;
#else
double trem;
@ -1343,7 +1343,7 @@ timestamp_time(PG_FUNCTION_ARGS)
* 86400000000) - timestamp;
*/
result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
* INT64CONST(1000000)) + fsec);
* USECS_PER_SEC) + fsec);
#else
result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
#endif
@ -1380,7 +1380,7 @@ timestamptz_time(PG_FUNCTION_ARGS)
* 86400000000) - timestamp;
*/
result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
* INT64CONST(1000000)) + fsec);
* USECS_PER_SEC) + fsec);
#else
result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
#endif
@ -1440,20 +1440,20 @@ interval_time(PG_FUNCTION_ARGS)
int64 days;
result = span->time;
if (result >= INT64CONST(86400000000))
if (result >= USECS_PER_DAY)
{
days = result / INT64CONST(86400000000);
result -= days * INT64CONST(86400000000);
days = result / USECS_PER_DAY;
result -= days * USECS_PER_DAY;
}
else if (result < 0)
{
days = (-result + INT64CONST(86400000000) - 1) / INT64CONST(86400000000);
result += days * INT64CONST(86400000000);
days = (-result + USECS_PER_DAY - 1) / USECS_PER_DAY;
result += days * USECS_PER_DAY;
}
#else
result = span->time;
if (result >= 86400e0 || result < 0)
result -= floor(result / 86400e0) * 86400e0;
if (result >= (double)SECS_PER_DAY || result < 0)
result -= floor(result / (double)SECS_PER_DAY) * (double)SECS_PER_DAY;
#endif
PG_RETURN_TIMEADT(result);
@ -1489,14 +1489,14 @@ time_pl_interval(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
result = (time + span->time);
result -= (result / INT64CONST(86400000000) * INT64CONST(86400000000));
result -= (result / USECS_PER_DAY * USECS_PER_DAY);
if (result < INT64CONST(0))
result += INT64CONST(86400000000);
result += USECS_PER_DAY;
#else
TimeADT time1;
result = (time + span->time);
TMODULO(result, time1, 86400e0);
TMODULO(result, time1, (double)SECS_PER_DAY);
if (result < 0)
result += 86400;
#endif
@ -1516,14 +1516,14 @@ time_mi_interval(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
result = (time - span->time);
result -= (result / INT64CONST(86400000000) * INT64CONST(86400000000));
result -= (result / USECS_PER_DAY * USECS_PER_DAY);
if (result < INT64CONST(0))
result += INT64CONST(86400000000);
result += USECS_PER_DAY;
#else
TimeADT time1;
result = (time - span->time);
TMODULO(result, time1, 86400e0);
TMODULO(result, time1, (double)SECS_PER_DAY);
if (result < 0)
result += 86400;
#endif
@ -1624,7 +1624,7 @@ time_part(PG_FUNCTION_ARGS)
{
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
result = ((tm->tm_sec * INT64CONST(1000000)) + fsec);
result = ((tm->tm_sec * USECS_PER_SEC) + fsec);
#else
result = ((tm->tm_sec + fsec) * 1000000);
#endif
@ -1641,7 +1641,7 @@ time_part(PG_FUNCTION_ARGS)
case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
result = (tm->tm_sec + (fsec / INT64CONST(1000000)));
result = (tm->tm_sec + (fsec / USECS_PER_SEC));
#else
result = (tm->tm_sec + fsec);
#endif
@ -1709,7 +1709,7 @@ tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
result->time = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
* INT64CONST(1000000)) + fsec);
* USECS_PER_SEC) + fsec);
#else
result->time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
#endif
@ -1823,12 +1823,12 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
#ifdef HAVE_INT64_TIMESTAMP
int64 trem = time->time;
tm->tm_hour = (trem / INT64CONST(3600000000));
trem -= (tm->tm_hour * INT64CONST(3600000000));
tm->tm_min = (trem / INT64CONST(60000000));
trem -= (tm->tm_min * INT64CONST(60000000));
tm->tm_sec = (trem / INT64CONST(1000000));
*fsec = (trem - (tm->tm_sec * INT64CONST(1000000)));
tm->tm_hour = (trem / USECS_PER_HOUR);
trem -= (tm->tm_hour * USECS_PER_HOUR);
tm->tm_min = (trem / USECS_PER_MINUTE);
trem -= (tm->tm_min * USECS_PER_MINUTE);
tm->tm_sec = (trem / USECS_PER_SEC);
*fsec = (trem - (tm->tm_sec * USECS_PER_SEC));
#else
double trem = time->time;
@ -1874,8 +1874,8 @@ timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
int64 t1,
t2;
t1 = time1->time + (time1->zone * INT64CONST(1000000));
t2 = time2->time + (time2->zone * INT64CONST(1000000));
t1 = time1->time + (time1->zone * USECS_PER_SEC);
t2 = time2->time + (time2->zone * USECS_PER_SEC);
#else
double t1,
t2;
@ -2026,12 +2026,12 @@ timetz_pl_interval(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
result->time = (time->time + span->time);
result->time -= (result->time / INT64CONST(86400000000) * INT64CONST(86400000000));
result->time -= (result->time / USECS_PER_DAY * USECS_PER_DAY);
if (result->time < INT64CONST(0))
result->time += INT64CONST(86400000000);
result->time += USECS_PER_DAY;
#else
result->time = (time->time + span->time);
TMODULO(result->time, time1.time, 86400e0);
TMODULO(result->time, time1.time, (double)SECS_PER_DAY);
if (result->time < 0)
result->time += 86400;
#endif
@ -2059,12 +2059,12 @@ timetz_mi_interval(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
result->time = (time->time - span->time);
result->time -= (result->time / INT64CONST(86400000000) * INT64CONST(86400000000));
result->time -= (result->time / USECS_PER_DAY * USECS_PER_DAY);
if (result->time < INT64CONST(0))
result->time += INT64CONST(86400000000);
result->time += USECS_PER_DAY;
#else
result->time = (time->time - span->time);
TMODULO(result->time, time1.time, 86400e0);
TMODULO(result->time, time1.time, (double)SECS_PER_DAY);
if (result->time < 0)
result->time += 86400;
#endif
@ -2281,10 +2281,10 @@ datetimetz_timestamptz(PG_FUNCTION_ARGS)
TimestampTz result;
#ifdef HAVE_INT64_TIMESTAMP
result = (((date *INT64CONST(86400000000)) +time->time)
+ (time->zone * INT64CONST(1000000)));
result = (((date *USECS_PER_DAY) +time->time)
+ (time->zone * USECS_PER_SEC));
#else
result = (((date *86400.0) +time->time) + time->zone);
result = (((date *(double)SECS_PER_DAY) +time->time) + time->zone);
#endif
PG_RETURN_TIMESTAMP(result);
@ -2400,7 +2400,7 @@ timetz_part(PG_FUNCTION_ARGS)
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
result = ((tm->tm_sec * INT64CONST(1000000)) + fsec);
result = ((tm->tm_sec * USECS_PER_SEC) + fsec);
#else
result = ((tm->tm_sec + fsec) * 1000000);
#endif
@ -2417,7 +2417,7 @@ timetz_part(PG_FUNCTION_ARGS)
case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
result = (tm->tm_sec + (fsec / INT64CONST(1000000)));
result = (tm->tm_sec + (fsec / USECS_PER_SEC));
#else
result = (tm->tm_sec + fsec);
#endif
@ -2496,11 +2496,11 @@ timetz_zone(PG_FUNCTION_ARGS)
{
tz = val * 60;
#ifdef HAVE_INT64_TIMESTAMP
result->time = time->time + ((time->zone - tz) * INT64CONST(1000000));
result->time = time->time + ((time->zone - tz) * USECS_PER_SEC);
while (result->time < INT64CONST(0))
result->time += INT64CONST(86400000000);
while (result->time >= INT64CONST(86400000000))
result->time -= INT64CONST(86400000000);
result->time += USECS_PER_DAY;
while (result->time >= USECS_PER_DAY)
result->time -= USECS_PER_DAY;
#else
result->time = time->time + (time->zone - tz);
while (result->time < 0)
@ -2542,7 +2542,7 @@ timetz_izone(PG_FUNCTION_ARGS)
PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
tz = -(zone->time / INT64CONST(1000000));
tz = -(zone->time / USECS_PER_SEC);
#else
tz = -(zone->time);
#endif
@ -2550,11 +2550,11 @@ timetz_izone(PG_FUNCTION_ARGS)
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
#ifdef HAVE_INT64_TIMESTAMP
result->time = time->time + ((time->zone - tz) * INT64CONST(1000000));
result->time = time->time + ((time->zone - tz) * USECS_PER_SEC);
while (result->time < INT64CONST(0))
result->time += INT64CONST(86400000000);
while (result->time >= INT64CONST(86400000000))
result->time -= INT64CONST(86400000000);
result->time += USECS_PER_DAY;
while (result->time >= USECS_PER_DAY)
result->time -= USECS_PER_DAY;
#else
result->time = time->time + (time->zone - tz);
while (result->time < 0)

View File

@ -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

View File

@ -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));

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.120 2005/05/23 17:13:14 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.121 2005/05/23 18:56:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -695,8 +695,8 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
interval->time = ((int) (interval->time / INT64CONST(86400000000))) *
INT64CONST(86400000000);
interval->time = ((int) (interval->time / USECS_PER_DAY)) *
USECS_PER_DAY;
#else
interval->time = ((int) (interval->time / 86400)) * 86400;
@ -714,13 +714,13 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
day = interval->time / INT64CONST(86400000000);
interval->time -= day * INT64CONST(86400000000);
interval->time = (interval->time / INT64CONST(3600000000)) *
INT64CONST(3600000000);
day = interval->time / USECS_PER_DAY;
interval->time -= day * USECS_PER_DAY;
interval->time = (interval->time / USECS_PER_HOUR) *
USECS_PER_HOUR;
#else
TMODULO(interval->time, day, 86400.0);
TMODULO(interval->time, day, (double)SECS_PER_DAY);
interval->time = ((int) (interval->time / 3600)) * 3600.0;
#endif
}
@ -736,10 +736,10 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
hour = interval->time / INT64CONST(3600000000);
interval->time -= hour * INT64CONST(3600000000);
interval->time = (interval->time / INT64CONST(60000000)) *
INT64CONST(60000000);
hour = interval->time / USECS_PER_HOUR;
interval->time -= hour * USECS_PER_HOUR;
interval->time = (interval->time / USECS_PER_MINUTE) *
USECS_PER_MINUTE;
#else
TMODULO(interval->time, hour, 3600.0);
@ -758,8 +758,8 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
minute = interval->time / INT64CONST(60000000);
interval->time -= minute * INT64CONST(60000000);
minute = interval->time / USECS_PER_MINUTE;
interval->time -= minute * USECS_PER_MINUTE;
#else
TMODULO(interval->time, minute, 60.0);
@ -773,8 +773,8 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
interval->time = (interval->time / INT64CONST(3600000000)) *
INT64CONST(3600000000);
interval->time = (interval->time / USECS_PER_HOUR) *
USECS_PER_HOUR;
#else
interval->time = ((int) (interval->time / 3600)) * 3600;
@ -788,8 +788,8 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
interval->time = (interval->time / INT64CONST(60000000)) *
INT64CONST(60000000);
interval->time = (interval->time / USECS_PER_MINUTE) *
USECS_PER_MINUTE;
#else
interval->time = ((int) (interval->time / 60)) * 60;
@ -816,13 +816,13 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
day = (interval->time / INT64CONST(86400000000));
interval->time -= day * INT64CONST(86400000000);
interval->time = (interval->time / INT64CONST(60000000)) *
INT64CONST(60000000);
day = (interval->time / USECS_PER_DAY);
interval->time -= day * USECS_PER_DAY;
interval->time = (interval->time / USECS_PER_MINUTE) *
USECS_PER_MINUTE;
#else
TMODULO(interval->time, day, 86400.0);
TMODULO(interval->time, day, (double)SECS_PER_DAY);
interval->time = ((int) (interval->time / 60)) * 60;
#endif
}
@ -841,11 +841,11 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
day = interval->time / INT64CONST(86400000000);
interval->time -= day * INT64CONST(86400000000);
day = interval->time / USECS_PER_DAY;
interval->time -= day * USECS_PER_DAY;
#else
TMODULO(interval->time, day, 86400.0);
TMODULO(interval->time, day, (double)SECS_PER_DAY);
#endif
}
/* MINUTE TO SECOND */
@ -862,8 +862,8 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->month = 0;
#ifdef HAVE_INT64_TIMESTAMP
hour = interval->time / INT64CONST(3600000000);
interval->time -= hour * INT64CONST(3600000000);
hour = interval->time / USECS_PER_HOUR;
interval->time -= hour * USECS_PER_HOUR;
#else
TMODULO(interval->time, hour, 3600.0);
#endif
@ -958,12 +958,12 @@ 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));
*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;
@ -1001,7 +1001,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
if (HasCTZSet && (tzp != NULL))
{
#ifdef HAVE_INT64_TIMESTAMP
dt -= CTimeZone * INT64CONST(1000000);
dt -= CTimeZone * USECS_PER_SEC;
#else
dt -= CTimeZone;
#endif
@ -1009,15 +1009,15 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
time = dt;
#ifdef HAVE_INT64_TIMESTAMP
TMODULO(time, date, INT64CONST(86400000000));
TMODULO(time, date, USECS_PER_DAY);
if (time < INT64CONST(0))
{
time += INT64CONST(86400000000);
time += USECS_PER_DAY;
date -= 1;
}
#else
TMODULO(time, date, 86400e0);
TMODULO(time, date, (double)SECS_PER_DAY);
if (time < 0)
{
@ -1073,7 +1073,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
* pg_time_t, so it should behave sanely on machines without int64.
*/
#ifdef HAVE_INT64_TIMESTAMP
dt = (dt - *fsec) / INT64CONST(1000000) +
dt = (dt - *fsec) / USECS_PER_SEC +
(POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400;
#else
dt = rint(dt - *fsec +
@ -1142,9 +1142,9 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
#ifdef HAVE_INT64_TIMESTAMP
*result = date * INT64CONST(86400000000) + time;
*result = date * USECS_PER_DAY + time;
/* check for major overflow */
if ((*result - time) / INT64CONST(86400000000) != date)
if ((*result - time) / USECS_PER_DAY != date)
return -1;
/* check for just-barely overflow (okay except time-of-day wraps) */
if ((*result < 0 && date >= 0) ||
@ -1188,16 +1188,16 @@ interval2tm(Interval span, struct pg_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_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_mday = (time / USECS_PER_DAY);
time -= (tm->tm_mday * USECS_PER_DAY);
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);
@ -1215,7 +1215,7 @@ tm2interval(struct pg_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)
@ -1231,7 +1231,7 @@ tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
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
@ -1246,7 +1246,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);
@ -1616,9 +1616,9 @@ interval_cmp_internal(Interval *interval1, Interval *interval2)
#ifdef HAVE_INT64_TIMESTAMP
if (interval1->month != 0)
span1 += interval1->month * INT64CONST(30) * INT64CONST(86400000000);
span1 += interval1->month * INT64CONST(30) * USECS_PER_DAY;
if (interval2->month != 0)
span2 += interval2->month * INT64CONST(30) * INT64CONST(86400000000);
span2 += interval2->month * INT64CONST(30) * USECS_PER_DAY;
#else
if (interval1->month != 0)
span1 += interval1->month * (30.0 * 86400);
@ -2161,7 +2161,7 @@ interval_mul(PG_FUNCTION_ARGS)
result->month = months;
result->time = (span1->time * factor);
result->time += (months - result->month) * INT64CONST(30) *
INT64CONST(86400000000);
USECS_PER_DAY;
#else
result->month = rint(months);
result->time = JROUND(span1->time * factor);
@ -2205,7 +2205,7 @@ interval_div(PG_FUNCTION_ARGS)
result->time = (span->time / factor);
/* evaluate fractional months as 30 days */
result->time += ((span->month - (result->month * factor)) *
INT64CONST(30) * INT64CONST(86400000000)) / factor;
INT64CONST(30) * USECS_PER_DAY) / factor;
#else
months = span->month / factor;
result->month = rint(months);
@ -3375,10 +3375,10 @@ timestamp_part(PG_FUNCTION_ARGS)
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
#ifdef HAVE_INT64_TIMESTAMP
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
tm->tm_sec + (fsec / 1000000e0)) / 86400e0;
tm->tm_sec + (fsec / 1000000e0)) / (double)SECS_PER_DAY;
#else
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
tm->tm_sec + fsec) / 86400e0;
tm->tm_sec + fsec) / (double)SECS_PER_DAY;
#endif
break;
@ -3603,10 +3603,10 @@ timestamptz_part(PG_FUNCTION_ARGS)
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
#ifdef HAVE_INT64_TIMESTAMP
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
tm->tm_sec + (fsec / 1000000e0)) / 86400e0;
tm->tm_sec + (fsec / 1000000e0)) / (double)SECS_PER_DAY;
#else
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
tm->tm_sec + fsec) / 86400e0;
tm->tm_sec + fsec) / (double)SECS_PER_DAY;
#endif
break;
@ -3872,7 +3872,7 @@ timestamp_izone(PG_FUNCTION_ARGS)
PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
tz = zone->time / INT64CONST(1000000);
tz = zone->time / USECS_PER_SEC;
#else
tz = zone->time;
#endif
@ -4021,7 +4021,7 @@ timestamptz_izone(PG_FUNCTION_ARGS)
PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
tz = -(zone->time / INT64CONST(1000000));
tz = -(zone->time / USECS_PER_SEC);
#else
tz = -(zone->time);
#endif

View 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.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.

View File

@ -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

View File

@ -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));

View File

@ -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