*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#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);
#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);
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);
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);
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;
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;
#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;
#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;
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
&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
}
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;
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
}
{
int sec;
- fval *= 86400;
+ fval *= SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
{
int sec;
- fval *= (7 * 86400);
+ fval *= (7 * SECS_PER_DAY);
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
{
int sec;
- fval *= (30 * 86400);
+ fval *= (30 * SECS_PER_DAY);
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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
{
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:
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);
#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))
#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
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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))
if (time < 0)
{
- time += 86400;
+ time += SECS_PER_DAY;
date -=1;
}
#endif
*/
#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)
(*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));
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);
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);
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);
#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
* 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 $
*
*-------------------------------------------------------------------------
*/
#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.
#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;
} 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.
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 ((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)
#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;
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)
{
int sec;
- fval *= 86400;
+ fval *= SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
{
int sec;
- fval *= (7 * 86400);
+ fval *= (7 * SECS_PER_DAY);
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
{
int sec;
- fval *= (30 * 86400);
+ fval *= (30 * SECS_PER_DAY);
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
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
#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);
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);
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));
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);
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
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)
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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;