*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#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
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;
{
#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
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;
* 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
* 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
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);
#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
#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
{
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
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
{
#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
#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;
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;
#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
#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
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);
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
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
{
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)
PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
- tz = -(zone->time / INT64CONST(1000000));
+ tz = -(zone->time / USECS_PER_SEC);
#else
tz = -(zone->time);
#endif
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)
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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
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,
#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 ||
#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 ||
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
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#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);
#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
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));
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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;
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
}
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);
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);
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;
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;
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
}
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 */
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
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;
if (HasCTZSet && (tzp != NULL))
{
#ifdef HAVE_INT64_TIMESTAMP
- dt -= CTimeZone * INT64CONST(1000000);
+ dt -= CTimeZone * USECS_PER_SEC;
#else
dt -= CTimeZone;
#endif
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)
{
* 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 +
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) ||
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);
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)
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
dt2local(Timestamp dt, int tz)
{
#ifdef HAVE_INT64_TIMESTAMP
- dt -= (tz * INT64CONST(1000000));
+ dt -= (tz * USECS_PER_SEC);
#else
dt -= tz;
dt = JROUND(dt);
#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);
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);
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);
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;
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;
PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
- tz = zone->time / INT64CONST(1000000);
+ tz = zone->time / USECS_PER_SEC;
#else
tz = zone->time;
#endif
PointerGetDatum(zone))))));
#ifdef HAVE_INT64_TIMESTAMP
- tz = -(zone->time / INT64CONST(1000000));
+ tz = -(zone->time / USECS_PER_SEC);
#else
tz = -(zone->time);
#endif
* 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 $
*
*-------------------------------------------------------------------------
*/
#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.
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
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));
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))
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