aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2005-07-21 18:06:13 +0000
committerBruce Momjian <bruce@momjian.us>2005-07-21 18:06:13 +0000
commite6b72d6af6fbe94e90019ca374199472bb1958a4 (patch)
tree20db8e92de3685ef949f45b0fff0ee681d99e26a
parenta0407f508a8d627dcf85557f1ada476117627875 (diff)
downloadpostgresql-e6b72d6af6fbe94e90019ca374199472bb1958a4.tar.gz
postgresql-e6b72d6af6fbe94e90019ca374199472bb1958a4.zip
Update DAYS_PER_MONTH comment.
Add SECS_PER_YEAR and MINS_PER_HOUR macros.
-rw-r--r--src/backend/postmaster/syslogger.c4
-rw-r--r--src/backend/utils/adt/date.c18
-rw-r--r--src/backend/utils/adt/datetime.c32
-rw-r--r--src/backend/utils/adt/nabstime.c14
-rw-r--r--src/backend/utils/adt/timestamp.c25
-rw-r--r--src/backend/utils/misc/guc.c4
-rw-r--r--src/include/utils/timestamp.h12
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt.h10
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt_common.c28
-rw-r--r--src/interfaces/ecpg/pgtypeslib/interval.c2
-rw-r--r--src/interfaces/ecpg/pgtypeslib/timestamp.c4
11 files changed, 82 insertions, 71 deletions
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 0084cff226e..a97a4183df4 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -18,7 +18,7 @@
*
*
* 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 @@
* start, but the rest can change at SIGHUP.
*/
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;
char *Log_directory = NULL;
char *Log_filename = NULL;
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 828ca9ec7c9..bd29db56233 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -8,7 +8,7 @@
*
*
* 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
tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
{
#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;
#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
return 0;
}
@@ -1347,10 +1347,10 @@ timestamp_time(PG_FUNCTION_ARGS)
* Could also do this with time = (timestamp / USECS_PER_DAY *
* 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;
#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
PG_RETURN_TIMEADT(result);
@@ -1384,10 +1384,10 @@ timestamptz_time(PG_FUNCTION_ARGS)
* Could also do this with time = (timestamp / USECS_PER_DAY *
* 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;
#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
PG_RETURN_TIMEADT(result);
@@ -1714,10 +1714,10 @@ static int
tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
{
#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;
#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
result->zone = tz;
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 681ec039247..34a650af1ce 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -8,7 +8,7 @@
*
*
* 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,
tm->tm_isdst = 1;
if (tzp == NULL)
return DTERR_BAD_FORMAT;
- *tzp += val * SECS_PER_MINUTE;
+ *tzp += val * MINS_PER_HOUR;
break;
case DTZ:
@@ -1460,7 +1460,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 1;
if (tzp == NULL)
return DTERR_BAD_FORMAT;
- *tzp = val * SECS_PER_MINUTE;
+ *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ;
break;
@@ -1468,7 +1468,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 0;
if (tzp == NULL)
return DTERR_BAD_FORMAT;
- *tzp = val * SECS_PER_MINUTE;
+ *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ;
break;
@@ -1667,7 +1667,7 @@ DetermineLocalTimeZone(struct pg_tm * tm)
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 * 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;
/* since sec >= 0, overflow could only be from +day to -mytime */
if (mytime < 0 && day > 0)
@@ -1679,7 +1679,7 @@ DetermineLocalTimeZone(struct pg_tm * tm)
* that DST boundaries can't be closer together than 48 hours, so
* 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)
goto overflow;
@@ -2167,7 +2167,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
tm->tm_isdst = 1;
if (tzp == NULL)
return DTERR_BAD_FORMAT;
- *tzp += val * SECS_PER_MINUTE;
+ *tzp += val * MINS_PER_HOUR;
break;
case DTZ:
@@ -2180,7 +2180,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
tm->tm_isdst = 1;
if (tzp == NULL)
return DTERR_BAD_FORMAT;
- *tzp = val * SECS_PER_MINUTE;
+ *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ;
break;
@@ -2188,7 +2188,7 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
tm->tm_isdst = 0;
if (tzp == NULL)
return DTERR_BAD_FORMAT;
- *tzp = val * SECS_PER_MINUTE;
+ *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ;
break;
@@ -2833,7 +2833,7 @@ DecodeTimezone(char *str, int *tzp)
if (min < 0 || min >= 60)
return DTERR_TZDISP_OVERFLOW;
- tz = (hr * SECS_PER_MINUTE + min) * SECS_PER_MINUTE;
+ tz = (hr * MINS_PER_HOUR + min) * SECS_PER_MINUTE;
if (*str == '-')
tz = -tz;
@@ -2890,7 +2890,7 @@ DecodePosixTimezone(char *str, int *tzp)
{
case DTZ:
case TZ:
- *tzp = (val * SECS_PER_MINUTE) - tz;
+ *tzp = (val * MINS_PER_HOUR) - tz;
break;
default:
@@ -3510,7 +3510,7 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
min;
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);
}
@@ -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)
{
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);
}
@@ -3633,7 +3633,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
else
{
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);
}
}
@@ -3681,7 +3681,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
else
{
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);
}
}
@@ -3747,7 +3747,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
* 2001-10-19
*/
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);
}
}
diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c
index df5dc51ba21..4935422352c 100644
--- a/src/backend/utils/adt/nabstime.c
+++ b/src/backend/utils/adt/nabstime.c
@@ -10,7 +10,7 @@
*
*
* 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)
return INVALID_ABSTIME;
/* 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 */
if ((day == MAX_DAYNUM && sec < 0) ||
@@ -638,8 +638,8 @@ reltimein(PG_FUNCTION_ARGS)
switch (dtype)
{
case DTK_DELTA:
- result = ((tm->tm_hour * SECS_PER_MINUTE + 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_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec;
+ result += tm->tm_year * SECS_PER_YEAR + ((tm->tm_mon * DAYS_PER_MONTH) + tm->tm_mday) * SECS_PER_DAY;
break;
default:
@@ -884,8 +884,8 @@ reltime_interval(PG_FUNCTION_ARGS)
default:
#ifdef HAVE_INT64_TIMESTAMP
- year = reltime / (36525 * 864);
- reltime -= year * (36525 * 864);
+ year = reltime / SECS_PER_YEAR;
+ reltime -= year * SECS_PER_YEAR;
month = reltime / (DAYS_PER_MONTH * SECS_PER_DAY);
reltime -= month * (DAYS_PER_MONTH * SECS_PER_DAY);
day = reltime / SECS_PER_DAY;
@@ -893,7 +893,7 @@ reltime_interval(PG_FUNCTION_ARGS)
result->time = (reltime * USECS_PER_SEC);
#else
- TMODULO(reltime, year, 36525 * 864);
+ TMODULO(reltime, year, SECS_PER_YEAR);
TMODULO(reltime, month, DAYS_PER_MONTH * SECS_PER_DAY);
TMODULO(reltime, day, SECS_PER_DAY);
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 0ef505ed907..09002d9f1ea 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -8,7 +8,7 @@
*
*
* 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)
interval->time -= hour * USECS_PER_HOUR;
interval->time = (interval->time / USECS_PER_MINUTE) *
USECS_PER_MINUTE;
-
#else
TMODULO(interval->time, hour, (double)SECS_PER_HOUR);
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)
tm->tm_min) * INT64CONST(60)) +
tm->tm_sec) * USECS_PER_SEC) + fsec;
#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_sec;
span->time = JROUND(span->time + fsec);
@@ -1225,14 +1224,14 @@ 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 * 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() */
#else
static double
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() */
#endif
@@ -2475,7 +2474,7 @@ timestamp_age(PG_FUNCTION_ARGS)
while (tm->tm_min < 0)
{
- tm->tm_min += SECS_PER_MINUTE;
+ tm->tm_min += MINS_PER_HOUR;
tm->tm_hour--;
}
@@ -2589,7 +2588,7 @@ timestamptz_age(PG_FUNCTION_ARGS)
while (tm->tm_min < 0)
{
- tm->tm_min += SECS_PER_MINUTE;
+ tm->tm_min += MINS_PER_HOUR;
tm->tm_hour--;
}
@@ -3492,10 +3491,10 @@ timestamp_part(PG_FUNCTION_ARGS)
case DTK_JULIAN:
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
#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;
#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;
#endif
break;
@@ -3628,8 +3627,8 @@ timestamptz_part(PG_FUNCTION_ARGS)
case DTK_TZ_MINUTE:
result = -tz;
- result /= SECS_PER_MINUTE;
- FMODULO(result, dummy, (double)SECS_PER_MINUTE);
+ result /= MINS_PER_HOUR;
+ FMODULO(result, dummy, (double)MINS_PER_HOUR);
break;
case DTK_TZ_HOUR:
@@ -3720,10 +3719,10 @@ timestamptz_part(PG_FUNCTION_ARGS)
case DTK_JULIAN:
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
#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;
#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;
#endif
break;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 0c843d96f78..20ebfee7126 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* 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[] =
NULL
},
&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
},
{
diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h
index 35221d5f1df..3e2ac94a215 100644
--- a/src/include/utils/timestamp.h
+++ b/src/include/utils/timestamp.h
@@ -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.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
#define MONTHS_PER_YEAR 12
/*
* 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
* also return a 'time' value to be used as well.
*/
#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */
#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_MINUTE 60
+#define MINS_PER_HOUR 60
#ifdef HAVE_INT64_TIMESTAMP
#define USECS_PER_DAY INT64CONST(86400000000)
diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h
index 01b44fb27ac..008ac3b0a31 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt.h
+++ b/src/interfaces/ecpg/pgtypeslib/dt.h
@@ -221,16 +221,22 @@ do { \
#define MONTHS_PER_YEAR 12
/*
* 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
* also return a 'time' value to be used as well.
*/
#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */
#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_MINUTE 60
+#define MINS_PER_HOUR 60
#ifdef HAVE_INT64_TIMESTAMP
#define USECS_PER_DAY INT64CONST(86400000000)
diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c
index 65a70cdc874..bc2bfd4ee7e 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt_common.c
+++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c
@@ -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)
{
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);
}
break;
@@ -862,7 +862,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
else
{
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);
}
}
@@ -908,7 +908,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
else
{
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);
}
}
@@ -971,7 +971,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
* 2001-10-19
*/
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);
}
}
@@ -1161,7 +1161,7 @@ DetermineLocalTimeZone(struct tm * tm)
day = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) -
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;
/*
@@ -1171,7 +1171,7 @@ DetermineLocalTimeZone(struct tm * tm)
tmp = localtime(&mytime);
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
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
@@ -1201,7 +1201,7 @@ DetermineLocalTimeZone(struct tm * tm)
tmp = localtime(&mytime);
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
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;
if (delta2 != delta1)
{
@@ -1210,7 +1210,7 @@ DetermineLocalTimeZone(struct tm * tm)
tmp = localtime(&mytime);
day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) -
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;
}
tm->tm_isdst = tmp->tm_isdst;
@@ -1712,7 +1712,7 @@ DecodeTimezone(char *str, int *tzp)
else
min = 0;
- tz = (hr * SECS_PER_MINUTE + min) * SECS_PER_MINUTE;
+ tz = (hr * MINS_PER_HOUR + min) * SECS_PER_MINUTE;
if (*str == '-')
tz = -tz;
@@ -1752,7 +1752,7 @@ DecodePosixTimezone(char *str, int *tzp)
{
case DTZ:
case TZ:
- *tzp = (val * SECS_PER_MINUTE) - tz;
+ *tzp = (val * MINS_PER_HOUR) - tz;
break;
default:
@@ -2398,7 +2398,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 1;
if (tzp == NULL)
return -1;
- *tzp += val * SECS_PER_MINUTE;
+ *tzp += val * MINS_PER_HOUR;
break;
case DTZ:
@@ -2411,7 +2411,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 1;
if (tzp == NULL)
return -1;
- *tzp = val * SECS_PER_MINUTE;
+ *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ;
break;
@@ -2419,7 +2419,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
tm->tm_isdst = 0;
if (tzp == NULL)
return -1;
- *tzp = val * SECS_PER_MINUTE;
+ *tzp = val * MINS_PER_HOUR;
ftype[i] = DTK_TZ;
break;
@@ -3108,7 +3108,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d,
* timezone value of the datetktbl table is in
* quarter hours
*/
- *tz = -15 * SECS_PER_MINUTE * datetktbl[j].value;
+ *tz = -15 * MINS_PER_HOUR * datetktbl[j].value;
break;
}
}
diff --git a/src/interfaces/ecpg/pgtypeslib/interval.c b/src/interfaces/ecpg/pgtypeslib/interval.c
index 3fa176be84e..6c3af18eced 100644
--- a/src/interfaces/ecpg/pgtypeslib/interval.c
+++ b/src/interfaces/ecpg/pgtypeslib/interval.c
@@ -723,7 +723,7 @@ tm2interval(struct tm *tm, fsec_t fsec, interval *span)
tm->tm_sec) * USECS_PER_SEC) + fsec;
#else
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_sec;
span->time = JROUND(span->time + fsec);
diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c
index 5382022d71a..5f9ec2f2f93 100644
--- a/src/interfaces/ecpg/pgtypeslib/timestamp.c
+++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c
@@ -20,14 +20,14 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int
static int64
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() */
#else
static double
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() */
#endif