Commit e6b72d6a authored by Bruce Momjian's avatar Bruce Momjian

Update DAYS_PER_MONTH comment.

Add SECS_PER_YEAR and MINS_PER_HOUR macros.
parent a0407f50
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.17 2005/07/21 03:56:11 momjian Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.18 2005/07/21 18:06:12 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
* start, but the rest can change at SIGHUP. * start, but the rest can change at SIGHUP.
*/ */
bool Redirect_stderr = false; bool Redirect_stderr = false;
int Log_RotationAge = HOURS_PER_DAY * SECS_PER_MINUTE; int Log_RotationAge = HOURS_PER_DAY * MINS_PER_HOUR;
int Log_RotationSize = 10 * 1024; int Log_RotationSize = 10 * 1024;
char *Log_directory = NULL; char *Log_directory = NULL;
char *Log_filename = NULL; char *Log_filename = NULL;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.115 2005/07/21 04:41:43 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.116 2005/07/21 18:06:12 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -917,10 +917,10 @@ static int ...@@ -917,10 +917,10 @@ static int
tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result) tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
{ {
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
*result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec)
* USECS_PER_SEC) + fsec; * USECS_PER_SEC) + fsec;
#else #else
*result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec; *result = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
#endif #endif
return 0; return 0;
} }
...@@ -1347,10 +1347,10 @@ timestamp_time(PG_FUNCTION_ARGS) ...@@ -1347,10 +1347,10 @@ timestamp_time(PG_FUNCTION_ARGS)
* Could also do this with time = (timestamp / USECS_PER_DAY * * Could also do this with time = (timestamp / USECS_PER_DAY *
* USECS_PER_DAY) - timestamp; * USECS_PER_DAY) - timestamp;
*/ */
result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
USECS_PER_SEC) + fsec; USECS_PER_SEC) + fsec;
#else #else
result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec; result = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
#endif #endif
PG_RETURN_TIMEADT(result); PG_RETURN_TIMEADT(result);
...@@ -1384,10 +1384,10 @@ timestamptz_time(PG_FUNCTION_ARGS) ...@@ -1384,10 +1384,10 @@ timestamptz_time(PG_FUNCTION_ARGS)
* Could also do this with time = (timestamp / USECS_PER_DAY * * Could also do this with time = (timestamp / USECS_PER_DAY *
* USECS_PER_DAY) - timestamp; * USECS_PER_DAY) - timestamp;
*/ */
result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
USECS_PER_SEC) + fsec; USECS_PER_SEC) + fsec;
#else #else
result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec; result = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
#endif #endif
PG_RETURN_TIMEADT(result); PG_RETURN_TIMEADT(result);
...@@ -1714,10 +1714,10 @@ static int ...@@ -1714,10 +1714,10 @@ static int
tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result) tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
{ {
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result->time = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * result->time = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
USECS_PER_SEC) + fsec; USECS_PER_SEC) + fsec;
#else #else
result->time = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec; result->time = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
#endif #endif
result->zone = tz; result->zone = tz;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.154 2005/07/21 04:41:43 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.155 2005/07/21 18:06:12 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1447,7 +1447,7 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -1447,7 +1447,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 1; tm->tm_isdst = 1;
if (tzp == NULL) if (tzp == NULL)
return DTERR_BAD_FORMAT; return DTERR_BAD_FORMAT;
*tzp += val * SECS_PER_MINUTE; *tzp += val * MINS_PER_HOUR;
break; break;
case DTZ: case DTZ:
...@@ -1460,7 +1460,7 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -1460,7 +1460,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 1; tm->tm_isdst = 1;
if (tzp == NULL) if (tzp == NULL)
return DTERR_BAD_FORMAT; return DTERR_BAD_FORMAT;
*tzp = val * SECS_PER_MINUTE; *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ; ftype[i] = DTK_TZ;
break; break;
...@@ -1468,7 +1468,7 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -1468,7 +1468,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 0; tm->tm_isdst = 0;
if (tzp == NULL) if (tzp == NULL)
return DTERR_BAD_FORMAT; return DTERR_BAD_FORMAT;
*tzp = val * SECS_PER_MINUTE; *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ; ftype[i] = DTK_TZ;
break; break;
...@@ -1667,7 +1667,7 @@ DetermineLocalTimeZone(struct pg_tm * tm) ...@@ -1667,7 +1667,7 @@ DetermineLocalTimeZone(struct pg_tm * tm)
day = ((pg_time_t) date) *SECS_PER_DAY; day = ((pg_time_t) date) *SECS_PER_DAY;
if (day / SECS_PER_DAY != date) if (day / SECS_PER_DAY != date)
goto overflow; goto overflow;
sec = tm->tm_sec + (tm->tm_min + tm->tm_hour * SECS_PER_MINUTE) * SECS_PER_MINUTE; sec = tm->tm_sec + (tm->tm_min + tm->tm_hour * MINS_PER_HOUR) * SECS_PER_MINUTE;
mytime = day + sec; mytime = day + sec;
/* since sec >= 0, overflow could only be from +day to -mytime */ /* since sec >= 0, overflow could only be from +day to -mytime */
if (mytime < 0 && day > 0) if (mytime < 0 && day > 0)
...@@ -1679,7 +1679,7 @@ DetermineLocalTimeZone(struct pg_tm * tm) ...@@ -1679,7 +1679,7 @@ DetermineLocalTimeZone(struct pg_tm * tm)
* that DST boundaries can't be closer together than 48 hours, so * that DST boundaries can't be closer together than 48 hours, so
* backing up 24 hours and finding the "next" boundary will work. * backing up 24 hours and finding the "next" boundary will work.
*/ */
prevtime = mytime - (HOURS_PER_DAY * SECS_PER_MINUTE * SECS_PER_MINUTE); prevtime = mytime - SECS_PER_DAY;
if (mytime < 0 && prevtime > 0) if (mytime < 0 && prevtime > 0)
goto overflow; goto overflow;
...@@ -2167,7 +2167,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf, ...@@ -2167,7 +2167,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
tm->tm_isdst = 1; tm->tm_isdst = 1;
if (tzp == NULL) if (tzp == NULL)
return DTERR_BAD_FORMAT; return DTERR_BAD_FORMAT;
*tzp += val * SECS_PER_MINUTE; *tzp += val * MINS_PER_HOUR;
break; break;
case DTZ: case DTZ:
...@@ -2180,7 +2180,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf, ...@@ -2180,7 +2180,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
tm->tm_isdst = 1; tm->tm_isdst = 1;
if (tzp == NULL) if (tzp == NULL)
return DTERR_BAD_FORMAT; return DTERR_BAD_FORMAT;
*tzp = val * SECS_PER_MINUTE; *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ; ftype[i] = DTK_TZ;
break; break;
...@@ -2188,7 +2188,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf, ...@@ -2188,7 +2188,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
tm->tm_isdst = 0; tm->tm_isdst = 0;
if (tzp == NULL) if (tzp == NULL)
return DTERR_BAD_FORMAT; return DTERR_BAD_FORMAT;
*tzp = val * SECS_PER_MINUTE; *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ; ftype[i] = DTK_TZ;
break; break;
...@@ -2833,7 +2833,7 @@ DecodeTimezone(char *str, int *tzp) ...@@ -2833,7 +2833,7 @@ DecodeTimezone(char *str, int *tzp)
if (min < 0 || min >= 60) if (min < 0 || min >= 60)
return DTERR_TZDISP_OVERFLOW; return DTERR_TZDISP_OVERFLOW;
tz = (hr * SECS_PER_MINUTE + min) * SECS_PER_MINUTE; tz = (hr * MINS_PER_HOUR + min) * SECS_PER_MINUTE;
if (*str == '-') if (*str == '-')
tz = -tz; tz = -tz;
...@@ -2890,7 +2890,7 @@ DecodePosixTimezone(char *str, int *tzp) ...@@ -2890,7 +2890,7 @@ DecodePosixTimezone(char *str, int *tzp)
{ {
case DTZ: case DTZ:
case TZ: case TZ:
*tzp = (val * SECS_PER_MINUTE) - tz; *tzp = (val * MINS_PER_HOUR) - tz;
break; break;
default: default:
...@@ -3510,7 +3510,7 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str) ...@@ -3510,7 +3510,7 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
min; min;
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
...@@ -3583,7 +3583,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3583,7 +3583,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
if (tzp != NULL && tm->tm_isdst >= 0) if (tzp != NULL && tm->tm_isdst >= 0)
{ {
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
...@@ -3633,7 +3633,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3633,7 +3633,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
else else
{ {
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
} }
...@@ -3681,7 +3681,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3681,7 +3681,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
else else
{ {
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
} }
...@@ -3747,7 +3747,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3747,7 +3747,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
* 2001-10-19 * 2001-10-19
*/ */
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min);
} }
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.138 2005/07/21 04:41:43 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.139 2005/07/21 18:06:12 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -199,7 +199,7 @@ tm2abstime(struct pg_tm * tm, int tz) ...@@ -199,7 +199,7 @@ tm2abstime(struct pg_tm * tm, int tz)
return INVALID_ABSTIME; return INVALID_ABSTIME;
/* convert to seconds */ /* convert to seconds */
sec = tm->tm_sec + tz + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; sec = tm->tm_sec + tz + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
/* check for overflow */ /* check for overflow */
if ((day == MAX_DAYNUM && sec < 0) || if ((day == MAX_DAYNUM && sec < 0) ||
...@@ -638,8 +638,8 @@ reltimein(PG_FUNCTION_ARGS) ...@@ -638,8 +638,8 @@ reltimein(PG_FUNCTION_ARGS)
switch (dtype) switch (dtype)
{ {
case DTK_DELTA: case DTK_DELTA:
result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec; result = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec;
result += tm->tm_year * 36525 * 864 + ((tm->tm_mon * DAYS_PER_MONTH) + tm->tm_mday) * SECS_PER_DAY; result += tm->tm_year * SECS_PER_YEAR + ((tm->tm_mon * DAYS_PER_MONTH) + tm->tm_mday) * SECS_PER_DAY;
break; break;
default: default:
...@@ -884,8 +884,8 @@ reltime_interval(PG_FUNCTION_ARGS) ...@@ -884,8 +884,8 @@ reltime_interval(PG_FUNCTION_ARGS)
default: default:
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
year = reltime / (36525 * 864); year = reltime / SECS_PER_YEAR;
reltime -= year * (36525 * 864); reltime -= year * SECS_PER_YEAR;
month = reltime / (DAYS_PER_MONTH * SECS_PER_DAY); month = reltime / (DAYS_PER_MONTH * SECS_PER_DAY);
reltime -= month * (DAYS_PER_MONTH * SECS_PER_DAY); reltime -= month * (DAYS_PER_MONTH * SECS_PER_DAY);
day = reltime / SECS_PER_DAY; day = reltime / SECS_PER_DAY;
...@@ -893,7 +893,7 @@ reltime_interval(PG_FUNCTION_ARGS) ...@@ -893,7 +893,7 @@ reltime_interval(PG_FUNCTION_ARGS)
result->time = (reltime * USECS_PER_SEC); result->time = (reltime * USECS_PER_SEC);
#else #else
TMODULO(reltime, year, 36525 * 864); TMODULO(reltime, year, SECS_PER_YEAR);
TMODULO(reltime, month, DAYS_PER_MONTH * SECS_PER_DAY); TMODULO(reltime, month, DAYS_PER_MONTH * SECS_PER_DAY);
TMODULO(reltime, day, SECS_PER_DAY); TMODULO(reltime, day, SECS_PER_DAY);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.137 2005/07/21 05:18:26 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.138 2005/07/21 18:06:12 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -748,7 +748,6 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod) ...@@ -748,7 +748,6 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
interval->time -= hour * USECS_PER_HOUR; interval->time -= hour * USECS_PER_HOUR;
interval->time = (interval->time / USECS_PER_MINUTE) * interval->time = (interval->time / USECS_PER_MINUTE) *
USECS_PER_MINUTE; USECS_PER_MINUTE;
#else #else
TMODULO(interval->time, hour, (double)SECS_PER_HOUR); TMODULO(interval->time, hour, (double)SECS_PER_HOUR);
interval->time = ((int)(interval->time / SECS_PER_MINUTE)) * (double)SECS_PER_MINUTE; interval->time = ((int)(interval->time / SECS_PER_MINUTE)) * (double)SECS_PER_MINUTE;
...@@ -1212,7 +1211,7 @@ tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span) ...@@ -1212,7 +1211,7 @@ tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span)
tm->tm_min) * INT64CONST(60)) + tm->tm_min) * INT64CONST(60)) +
tm->tm_sec) * USECS_PER_SEC) + fsec; tm->tm_sec) * USECS_PER_SEC) + fsec;
#else #else
span->time = (((tm->tm_hour * (double)SECS_PER_MINUTE) + span->time = (((tm->tm_hour * (double)MINS_PER_HOUR) +
tm->tm_min) * (double)SECS_PER_MINUTE) + tm->tm_min) * (double)SECS_PER_MINUTE) +
tm->tm_sec; tm->tm_sec;
span->time = JROUND(span->time + fsec); span->time = JROUND(span->time + fsec);
...@@ -1225,14 +1224,14 @@ tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span) ...@@ -1225,14 +1224,14 @@ tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span)
static int64 static int64
time2t(const int hour, const int min, const int sec, const fsec_t fsec) time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{ {
return (((((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec; return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec;
} /* time2t() */ } /* time2t() */
#else #else
static double static double
time2t(const int hour, const int min, const int sec, const fsec_t fsec) time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{ {
return (((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec + fsec; return (((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec + fsec;
} /* time2t() */ } /* time2t() */
#endif #endif
...@@ -2475,7 +2474,7 @@ timestamp_age(PG_FUNCTION_ARGS) ...@@ -2475,7 +2474,7 @@ timestamp_age(PG_FUNCTION_ARGS)
while (tm->tm_min < 0) while (tm->tm_min < 0)
{ {
tm->tm_min += SECS_PER_MINUTE; tm->tm_min += MINS_PER_HOUR;
tm->tm_hour--; tm->tm_hour--;
} }
...@@ -2589,7 +2588,7 @@ timestamptz_age(PG_FUNCTION_ARGS) ...@@ -2589,7 +2588,7 @@ timestamptz_age(PG_FUNCTION_ARGS)
while (tm->tm_min < 0) while (tm->tm_min < 0)
{ {
tm->tm_min += SECS_PER_MINUTE; tm->tm_min += MINS_PER_HOUR;
tm->tm_hour--; tm->tm_hour--;
} }
...@@ -3492,10 +3491,10 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -3492,10 +3491,10 @@ timestamp_part(PG_FUNCTION_ARGS)
case DTK_JULIAN: case DTK_JULIAN:
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday); result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result += ((((tm->tm_hour * SECS_PER_MINUTE) + tm->tm_min) * SECS_PER_MINUTE) + result += ((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) +
tm->tm_sec + (fsec / 1000000.0)) / (double)SECS_PER_DAY; tm->tm_sec + (fsec / 1000000.0)) / (double)SECS_PER_DAY;
#else #else
result += ((((tm->tm_hour * SECS_PER_MINUTE) + tm->tm_min) * SECS_PER_MINUTE) + result += ((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) +
tm->tm_sec + fsec) / (double)SECS_PER_DAY; tm->tm_sec + fsec) / (double)SECS_PER_DAY;
#endif #endif
break; break;
...@@ -3628,8 +3627,8 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3628,8 +3627,8 @@ timestamptz_part(PG_FUNCTION_ARGS)
case DTK_TZ_MINUTE: case DTK_TZ_MINUTE:
result = -tz; result = -tz;
result /= SECS_PER_MINUTE; result /= MINS_PER_HOUR;
FMODULO(result, dummy, (double)SECS_PER_MINUTE); FMODULO(result, dummy, (double)MINS_PER_HOUR);
break; break;
case DTK_TZ_HOUR: case DTK_TZ_HOUR:
...@@ -3720,10 +3719,10 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -3720,10 +3719,10 @@ timestamptz_part(PG_FUNCTION_ARGS)
case DTK_JULIAN: case DTK_JULIAN:
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday); result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result += ((((tm->tm_hour * SECS_PER_MINUTE) + tm->tm_min) * SECS_PER_MINUTE) + result += ((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) +
tm->tm_sec + (fsec / 1000000.0)) / (double)SECS_PER_DAY; tm->tm_sec + (fsec / 1000000.0)) / (double)SECS_PER_DAY;
#else #else
result += ((((tm->tm_hour * SECS_PER_MINUTE) + tm->tm_min) * SECS_PER_MINUTE) + result += ((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) +
tm->tm_sec + fsec) / (double)SECS_PER_DAY; tm->tm_sec + fsec) / (double)SECS_PER_DAY;
#endif #endif
break; break;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.275 2005/07/21 03:56:21 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.276 2005/07/21 18:06:12 momjian Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
...@@ -1349,7 +1349,7 @@ static struct config_int ConfigureNamesInt[] = ...@@ -1349,7 +1349,7 @@ static struct config_int ConfigureNamesInt[] =
NULL NULL
}, },
&Log_RotationAge, &Log_RotationAge,
HOURS_PER_DAY * SECS_PER_MINUTE, 0, INT_MAX / SECS_PER_MINUTE, NULL, NULL HOURS_PER_DAY * MINS_PER_HOUR, 0, INT_MAX / MINS_PER_HOUR, NULL, NULL
}, },
{ {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.50 2005/07/21 15:16:27 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.51 2005/07/21 18:06:13 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -65,16 +65,22 @@ typedef struct ...@@ -65,16 +65,22 @@ typedef struct
#define MONTHS_PER_YEAR 12 #define MONTHS_PER_YEAR 12
/* /*
* DAYS_PER_MONTH is very imprecise. The more accurate value is * DAYS_PER_MONTH is very imprecise. The more accurate value is
* 365.25/12 = 30.4375, or '30 days 10:30:00'. Right now we only * 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only
* return an integral number of days, but someday perhaps we should * return an integral number of days, but someday perhaps we should
* also return a 'time' value to be used as well. * also return a 'time' value to be used as well.
*/ */
#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */ #define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */
#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */ #define HOURS_PER_DAY 24 /* assume no daylight savings time changes */
#define SECS_PER_DAY 86400 /* assumes no leap second */ /*
* This doesn't adjust for uneven daylight savings time intervals, nor
* leap seconds.
*/
#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */
#define SECS_PER_DAY 86400
#define SECS_PER_HOUR 3600 #define SECS_PER_HOUR 3600
#define SECS_PER_MINUTE 60 #define SECS_PER_MINUTE 60
#define MINS_PER_HOUR 60
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
#define USECS_PER_DAY INT64CONST(86400000000) #define USECS_PER_DAY INT64CONST(86400000000)
......
...@@ -221,16 +221,22 @@ do { \ ...@@ -221,16 +221,22 @@ do { \
#define MONTHS_PER_YEAR 12 #define MONTHS_PER_YEAR 12
/* /*
* DAYS_PER_MONTH is very imprecise. The more accurate value is * DAYS_PER_MONTH is very imprecise. The more accurate value is
* 365.25/12 = 30.4375, or '30 days 10:30:00'. Right now we only * 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only
* return an integral number of days, but someday perhaps we should * return an integral number of days, but someday perhaps we should
* also return a 'time' value to be used as well. * also return a 'time' value to be used as well.
*/ */
#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */ #define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */
#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */ #define HOURS_PER_DAY 24 /* assume no daylight savings time changes */
#define SECS_PER_DAY 86400 /* assumes no leap second */ /*
* This doesn't adjust for uneven daylight savings time intervals, nor
* leap seconds.
*/
#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */
#define SECS_PER_DAY 86400
#define SECS_PER_HOUR 3600 #define SECS_PER_HOUR 3600
#define SECS_PER_MINUTE 60 #define SECS_PER_MINUTE 60
#define MINS_PER_HOUR 60
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
#define USECS_PER_DAY INT64CONST(86400000000) #define USECS_PER_DAY INT64CONST(86400000000)
......
...@@ -814,7 +814,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha ...@@ -814,7 +814,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
if (tzp != NULL && tm->tm_isdst >= 0) if (tzp != NULL && tm->tm_isdst >= 0)
{ {
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
break; break;
...@@ -862,7 +862,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha ...@@ -862,7 +862,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
else else
{ {
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
} }
...@@ -908,7 +908,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha ...@@ -908,7 +908,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
else else
{ {
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
} }
...@@ -971,7 +971,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha ...@@ -971,7 +971,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
* 2001-10-19 * 2001-10-19
*/ */
hour = -(*tzp / SECS_PER_HOUR); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR;
sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min);
} }
} }
...@@ -1161,7 +1161,7 @@ DetermineLocalTimeZone(struct tm * tm) ...@@ -1161,7 +1161,7 @@ DetermineLocalTimeZone(struct tm * tm)
day = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - day = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) -
date2j(1970, 1, 1)); date2j(1970, 1, 1));
mysec = tm->tm_sec + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; mysec = tm->tm_sec + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
mytime = (time_t) mysec; mytime = (time_t) mysec;
/* /*
...@@ -1171,7 +1171,7 @@ DetermineLocalTimeZone(struct tm * tm) ...@@ -1171,7 +1171,7 @@ DetermineLocalTimeZone(struct tm * tm)
tmp = localtime(&mytime); tmp = localtime(&mytime);
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) - day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
date2j(1970, 1, 1)); date2j(1970, 1, 1));
locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
/* /*
* The local time offset corresponding to that GMT time is now * The local time offset corresponding to that GMT time is now
...@@ -1201,7 +1201,7 @@ DetermineLocalTimeZone(struct tm * tm) ...@@ -1201,7 +1201,7 @@ DetermineLocalTimeZone(struct tm * tm)
tmp = localtime(&mytime); tmp = localtime(&mytime);
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) - day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
date2j(1970, 1, 1)); date2j(1970, 1, 1));
locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
delta2 = mysec - locsec; delta2 = mysec - locsec;
if (delta2 != delta1) if (delta2 != delta1)
{ {
...@@ -1210,7 +1210,7 @@ DetermineLocalTimeZone(struct tm * tm) ...@@ -1210,7 +1210,7 @@ DetermineLocalTimeZone(struct tm * tm)
tmp = localtime(&mytime); tmp = localtime(&mytime);
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) - day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
date2j(1970, 1, 1)); date2j(1970, 1, 1));
locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
delta2 = mysec - locsec; delta2 = mysec - locsec;
} }
tm->tm_isdst = tmp->tm_isdst; tm->tm_isdst = tmp->tm_isdst;
...@@ -1712,7 +1712,7 @@ DecodeTimezone(char *str, int *tzp) ...@@ -1712,7 +1712,7 @@ DecodeTimezone(char *str, int *tzp)
else else
min = 0; min = 0;
tz = (hr * SECS_PER_MINUTE + min) * SECS_PER_MINUTE; tz = (hr * MINS_PER_HOUR + min) * SECS_PER_MINUTE;
if (*str == '-') if (*str == '-')
tz = -tz; tz = -tz;
...@@ -1752,7 +1752,7 @@ DecodePosixTimezone(char *str, int *tzp) ...@@ -1752,7 +1752,7 @@ DecodePosixTimezone(char *str, int *tzp)
{ {
case DTZ: case DTZ:
case TZ: case TZ:
*tzp = (val * SECS_PER_MINUTE) - tz; *tzp = (val * MINS_PER_HOUR) - tz;
break; break;
default: default:
...@@ -2398,7 +2398,7 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -2398,7 +2398,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 1; tm->tm_isdst = 1;
if (tzp == NULL) if (tzp == NULL)
return -1; return -1;
*tzp += val * SECS_PER_MINUTE; *tzp += val * MINS_PER_HOUR;
break; break;
case DTZ: case DTZ:
...@@ -2411,7 +2411,7 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -2411,7 +2411,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 1; tm->tm_isdst = 1;
if (tzp == NULL) if (tzp == NULL)
return -1; return -1;
*tzp = val * SECS_PER_MINUTE; *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ; ftype[i] = DTK_TZ;
break; break;
...@@ -2419,7 +2419,7 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -2419,7 +2419,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 0; tm->tm_isdst = 0;
if (tzp == NULL) if (tzp == NULL)
return -1; return -1;
*tzp = val * SECS_PER_MINUTE; *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ; ftype[i] = DTK_TZ;
break; break;
...@@ -3108,7 +3108,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d, ...@@ -3108,7 +3108,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d,
* timezone value of the datetktbl table is in * timezone value of the datetktbl table is in
* quarter hours * quarter hours
*/ */
*tz = -15 * SECS_PER_MINUTE * datetktbl[j].value; *tz = -15 * MINS_PER_HOUR * datetktbl[j].value;
break; break;
} }
} }
......
...@@ -723,7 +723,7 @@ tm2interval(struct tm *tm, fsec_t fsec, interval *span) ...@@ -723,7 +723,7 @@ tm2interval(struct tm *tm, fsec_t fsec, interval *span)
tm->tm_sec) * USECS_PER_SEC) + fsec; tm->tm_sec) * USECS_PER_SEC) + fsec;
#else #else
span->time = (((((tm->tm_mday * (double)HOURS_PER_DAY) + span->time = (((((tm->tm_mday * (double)HOURS_PER_DAY) +
tm->tm_hour) * (double)SECS_PER_MINUTE) + tm->tm_hour) * (double)MINS_PER_HOUR) +
tm->tm_min) * (double)SECS_PER_MINUTE) + tm->tm_min) * (double)SECS_PER_MINUTE) +
tm->tm_sec; tm->tm_sec;
span->time = JROUND(span->time + fsec); span->time = JROUND(span->time + fsec);
......
...@@ -20,14 +20,14 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int ...@@ -20,14 +20,14 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int
static int64 static int64
time2t(const int hour, const int min, const int sec, const fsec_t fsec) time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{ {
return (((((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec; return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec;
} /* time2t() */ } /* time2t() */
#else #else
static double static double
time2t(const int hour, const int min, const int sec, const fsec_t fsec) time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{ {
return (((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec + fsec; return (((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec + fsec;
} /* time2t() */ } /* time2t() */
#endif #endif
......
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