Commit a536b2dd authored by Bruce Momjian's avatar Bruce Momjian

Add time/date macros for code clarity:

	#define DAYS_PER_YEAR   365.25
	#define MONTHS_PER_YEAR 12
	#define DAYS_PER_MONTH  30
	#define HOURS_PER_DAY   24
parent dc73819f
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.110 2005/07/20 16:42:30 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.111 2005/07/21 03:56:10 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -325,7 +325,7 @@ assign_timezone(const char *value, bool doit, GucSource source) ...@@ -325,7 +325,7 @@ assign_timezone(const char *value, bool doit, GucSource source)
if (doit) if (doit)
{ {
/* Here we change from SQL to Unix sign convention */ /* Here we change from SQL to Unix sign convention */
CTimeZone = -hours * 3600; CTimeZone = -hours * SECS_PER_HOUR;
HasCTZSet = true; HasCTZSet = true;
} }
} }
...@@ -402,7 +402,7 @@ assign_timezone(const char *value, bool doit, GucSource source) ...@@ -402,7 +402,7 @@ assign_timezone(const char *value, bool doit, GucSource source)
if (!result) if (!result)
return NULL; return NULL;
snprintf(result, 64, "%.5f", snprintf(result, 64, "%.5f",
(double) (-CTimeZone) / 3600.0); (double) (-CTimeZone) / (double)SECS_PER_HOUR);
} }
else else
result = strdup(value); result = strdup(value);
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.459 2005/07/14 05:13:40 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.460 2005/07/21 03:56:11 momjian Exp $
* *
* NOTES * NOTES
* *
...@@ -1284,7 +1284,7 @@ ServerLoop(void) ...@@ -1284,7 +1284,7 @@ ServerLoop(void)
* less than an hour ... * less than an hour ...
*/ */
now = time(NULL); now = time(NULL);
if (now - last_touch_time >= 58 * 60) if (now - last_touch_time >= 58 * SECS_PER_MINUTE)
{ {
TouchSocketFile(); TouchSocketFile();
TouchSocketLockFile(); TouchSocketLockFile();
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.16 2005/07/04 04:51:47 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.17 2005/07/21 03:56:11 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "storage/pg_shmem.h" #include "storage/pg_shmem.h"
#include "utils/guc.h" #include "utils/guc.h"
#include "utils/ps_status.h" #include "utils/ps_status.h"
#include "utils/timestamp.h"
/* /*
* We really want line-buffered mode for logfile output, but Windows does * We really want line-buffered mode for logfile output, but Windows does
...@@ -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 = 24 * 60; int Log_RotationAge = HOURS_PER_DAY * SECS_PER_MINUTE;
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;
...@@ -855,7 +855,7 @@ set_next_rotation_time(void) ...@@ -855,7 +855,7 @@ set_next_rotation_time(void)
* fairly loosely. In this version we align to local time rather than * fairly loosely. In this version we align to local time rather than
* GMT. * GMT.
*/ */
rotinterval = Log_RotationAge * 60; /* convert to seconds */ rotinterval = Log_RotationAge * SECS_PER_MINUTE; /* convert to seconds */
now = time(NULL); now = time(NULL);
tm = pg_localtime(&now, global_timezone); tm = pg_localtime(&now, global_timezone);
now += tm->tm_gmtoff; now += tm->tm_gmtoff;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.454 2005/07/14 05:13:41 tgl Exp $ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.455 2005/07/21 03:56:11 momjian Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -3536,10 +3536,10 @@ log_disconnections(int code, Datum arg) ...@@ -3536,10 +3536,10 @@ log_disconnections(int code, Datum arg)
end.tv_sec -= port->session_start.tv_sec; end.tv_sec -= port->session_start.tv_sec;
end.tv_usec -= port->session_start.tv_usec; end.tv_usec -= port->session_start.tv_usec;
hours = end.tv_sec / 3600; hours = end.tv_sec / SECS_PER_HOUR;
end.tv_sec %= 3600; end.tv_sec %= SECS_PER_HOUR;
minutes = end.tv_sec / 60; minutes = end.tv_sec / SECS_PER_MINUTE;
seconds = end.tv_sec % 60; seconds = end.tv_sec % SECS_PER_MINUTE;
/* if time has gone backwards for some reason say so, or print time */ /* if time has gone backwards for some reason say so, or print time */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.113 2005/07/20 16:42:30 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.114 2005/07/21 03:56:13 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
/* /*
* gcc's -ffast-math switch breaks routines that expect exact results from * gcc's -ffast-math switch breaks routines that expect exact results from
* expressions like timeval / 3600, where timeval is double. * expressions like timeval / SECS_PER_HOUR, where timeval is double.
*/ */
#ifdef __FAST_MATH__ #ifdef __FAST_MATH__
#error -ffast-math is known to break this code #error -ffast-math is known to break this code
...@@ -918,10 +918,10 @@ static int ...@@ -918,10 +918,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 * 60 + tm->tm_min) * 60) + tm->tm_sec) *result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec)
* USECS_PER_SEC) + fsec; * USECS_PER_SEC) + fsec;
#else #else
*result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec; *result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
#endif #endif
return 0; return 0;
} }
...@@ -946,8 +946,8 @@ time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec) ...@@ -946,8 +946,8 @@ time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
double trem; double trem;
trem = time; trem = time;
TMODULO(trem, tm->tm_hour, 3600.0); TMODULO(trem, tm->tm_hour, (double)SECS_PER_HOUR);
TMODULO(trem, tm->tm_min, 60.0); TMODULO(trem, tm->tm_min, (double)SECS_PER_MINUTE);
TMODULO(trem, tm->tm_sec, 1.0); TMODULO(trem, tm->tm_sec, 1.0);
*fsec = trem; *fsec = trem;
#endif #endif
...@@ -1348,10 +1348,10 @@ timestamp_time(PG_FUNCTION_ARGS) ...@@ -1348,10 +1348,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 * 60 + tm->tm_min) * 60) + tm->tm_sec) * result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
USECS_PER_SEC) + fsec; USECS_PER_SEC) + fsec;
#else #else
result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec; result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
#endif #endif
PG_RETURN_TIMEADT(result); PG_RETURN_TIMEADT(result);
...@@ -1385,10 +1385,10 @@ timestamptz_time(PG_FUNCTION_ARGS) ...@@ -1385,10 +1385,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 * 60 + tm->tm_min) * 60) + tm->tm_sec) * result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
USECS_PER_SEC) + fsec; USECS_PER_SEC) + fsec;
#else #else
result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec; result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
#endif #endif
PG_RETURN_TIMEADT(result); PG_RETURN_TIMEADT(result);
...@@ -1715,10 +1715,10 @@ static int ...@@ -1715,10 +1715,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 * 60 + tm->tm_min) * 60) + tm->tm_sec) * result->time = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
USECS_PER_SEC) + fsec; USECS_PER_SEC) + fsec;
#else #else
result->time = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec; result->time = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
#endif #endif
result->zone = tz; result->zone = tz;
...@@ -1843,8 +1843,8 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp) ...@@ -1843,8 +1843,8 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
#else #else
double trem = time->time; double trem = time->time;
TMODULO(trem, tm->tm_hour, 3600.0); TMODULO(trem, tm->tm_hour, (double)SECS_PER_HOUR);
TMODULO(trem, tm->tm_min, 60.0); TMODULO(trem, tm->tm_min, (double)SECS_PER_MINUTE);
TMODULO(trem, tm->tm_sec, 1.0); TMODULO(trem, tm->tm_sec, 1.0);
*fsec = trem; *fsec = trem;
#endif #endif
...@@ -2399,13 +2399,13 @@ timetz_part(PG_FUNCTION_ARGS) ...@@ -2399,13 +2399,13 @@ timetz_part(PG_FUNCTION_ARGS)
case DTK_TZ_MINUTE: case DTK_TZ_MINUTE:
result = -tz; result = -tz;
result /= 60; result /= SECS_PER_MINUTE;
FMODULO(result, dummy, 60.0); FMODULO(result, dummy, (double)SECS_PER_MINUTE);
break; break;
case DTK_TZ_HOUR: case DTK_TZ_HOUR:
dummy = -tz; dummy = -tz;
FMODULO(dummy, result, 3600.0); FMODULO(dummy, result, (double)SECS_PER_HOUR);
break; break;
case DTK_MICROSEC: case DTK_MICROSEC:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.152 2005/07/12 15:17:44 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.153 2005/07/21 03:56:14 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 * 60; *tzp += val * SECS_PER_MINUTE;
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 * 60; *tzp = val * SECS_PER_MINUTE;
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 * 60; *tzp = val * SECS_PER_MINUTE;
ftype[i] = DTK_TZ; ftype[i] = DTK_TZ;
break; break;
...@@ -1566,7 +1566,7 @@ DecodeDateTime(char **field, int *ftype, int nf, ...@@ -1566,7 +1566,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
/* check for valid month */ /* check for valid month */
if (fmask & DTK_M(MONTH)) if (fmask & DTK_M(MONTH))
{ {
if (tm->tm_mon < 1 || tm->tm_mon > 12) if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR)
return DTERR_MD_FIELD_OVERFLOW; return DTERR_MD_FIELD_OVERFLOW;
} }
...@@ -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 * 60) * 60; sec = tm->tm_sec + (tm->tm_min + tm->tm_hour * SECS_PER_MINUTE) * 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 - (24 * 60 * 60); prevtime = mytime - (HOURS_PER_DAY * SECS_PER_MINUTE * SECS_PER_MINUTE);
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 * 60; *tzp += val * SECS_PER_MINUTE;
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 * 60; *tzp = val * SECS_PER_MINUTE;
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 * 60; *tzp = val * SECS_PER_MINUTE;
ftype[i] = DTK_TZ; ftype[i] = DTK_TZ;
break; break;
...@@ -2431,7 +2431,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm) ...@@ -2431,7 +2431,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm)
} }
/* check for valid month */ /* check for valid month */
if (tm->tm_mon < 1 || tm->tm_mon > 12) if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR)
return DTERR_MD_FIELD_OVERFLOW; return DTERR_MD_FIELD_OVERFLOW;
/* check for valid day */ /* check for valid day */
...@@ -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 * 60 + min) * 60; tz = (hr * SECS_PER_MINUTE + 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 * 60) - tz; *tzp = (val * SECS_PER_MINUTE) - tz;
break; break;
default: default:
...@@ -3116,7 +3116,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm, ...@@ -3116,7 +3116,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
{ {
int sec; int sec;
fval *= 60; fval *= SECS_PER_MINUTE;
sec = fval; sec = fval;
tm->tm_sec += sec; tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -3134,7 +3134,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm, ...@@ -3134,7 +3134,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
{ {
int sec; int sec;
fval *= 3600; fval *= SECS_PER_HOUR;
sec = fval; sec = fval;
tm->tm_sec += sec; tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -3188,7 +3188,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm, ...@@ -3188,7 +3188,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
{ {
int sec; int sec;
fval *= 30 * SECS_PER_DAY; fval *= DAYS_PER_MONTH * SECS_PER_DAY;
sec = fval; sec = fval;
tm->tm_sec += sec; tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -3203,28 +3203,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm, ...@@ -3203,28 +3203,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
case DTK_YEAR: case DTK_YEAR:
tm->tm_year += val; tm->tm_year += val;
if (fval != 0) if (fval != 0)
tm->tm_mon += fval * 12; tm->tm_mon += fval * MONTHS_PER_YEAR;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR); tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break; break;
case DTK_DECADE: case DTK_DECADE:
tm->tm_year += val * 10; tm->tm_year += val * 10;
if (fval != 0) if (fval != 0)
tm->tm_mon += fval * 120; tm->tm_mon += fval * MONTHS_PER_YEAR * 10;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR); tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break; break;
case DTK_CENTURY: case DTK_CENTURY:
tm->tm_year += val * 100; tm->tm_year += val * 100;
if (fval != 0) if (fval != 0)
tm->tm_mon += fval * 1200; tm->tm_mon += fval * MONTHS_PER_YEAR * 100;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR); tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break; break;
case DTK_MILLENNIUM: case DTK_MILLENNIUM:
tm->tm_year += val * 1000; tm->tm_year += val * 1000;
if (fval != 0) if (fval != 0)
tm->tm_mon += fval * 12000; tm->tm_mon += fval * MONTHS_PER_YEAR * 1000;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR); tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break; break;
...@@ -3422,7 +3422,7 @@ datebsearch(char *key, datetkn *base, unsigned int nel) ...@@ -3422,7 +3422,7 @@ datebsearch(char *key, datetkn *base, unsigned int nel)
int int
EncodeDateOnly(struct pg_tm * tm, int style, char *str) EncodeDateOnly(struct pg_tm * tm, int style, char *str)
{ {
if (tm->tm_mon < 1 || tm->tm_mon > 12) if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR)
return -1; return -1;
switch (style) switch (style)
...@@ -3482,7 +3482,7 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str) ...@@ -3482,7 +3482,7 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
int int
EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str) EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
{ {
if (tm->tm_hour < 0 || tm->tm_hour > 24) if (tm->tm_hour < 0 || tm->tm_hour > HOURS_PER_DAY)
return -1; return -1;
sprintf(str, "%02d:%02d", tm->tm_hour, tm->tm_min); sprintf(str, "%02d:%02d", tm->tm_hour, tm->tm_min);
...@@ -3509,8 +3509,8 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str) ...@@ -3509,8 +3509,8 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
int hour, int hour,
min; min;
hour = -(*tzp / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
...@@ -3538,9 +3538,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3538,9 +3538,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
/* /*
* Why are we checking only the month field? Change this to an * Why are we checking only the month field? Change this to an
* assert... if (tm->tm_mon < 1 || tm->tm_mon > 12) return -1; * assert... if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR) return -1;
*/ */
Assert(tm->tm_mon >= 1 && tm->tm_mon <= 12); Assert(tm->tm_mon >= 1 && tm->tm_mon <= MONTHS_PER_YEAR);
switch (style) switch (style)
{ {
...@@ -3582,8 +3582,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3582,8 +3582,8 @@ 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 / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
...@@ -3632,8 +3632,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3632,8 +3632,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn); sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
else else
{ {
hour = -(*tzp / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
} }
...@@ -3680,8 +3680,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3680,8 +3680,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn); sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
else else
{ {
hour = -(*tzp / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
} }
...@@ -3746,8 +3746,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, ...@@ -3746,8 +3746,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
* rejected by the date/time parser later. - thomas * rejected by the date/time parser later. - thomas
* 2001-10-19 * 2001-10-19
*/ */
hour = -(*tzp / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min);
} }
} }
......
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* formatting.c * formatting.c
* *
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.91 2005/07/20 16:42:30 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.92 2005/07/21 03:56:16 momjian Exp $
* *
* *
* Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group
...@@ -1718,7 +1718,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) ...@@ -1718,7 +1718,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
if (flag == TO_CHAR) if (flag == TO_CHAR)
{ {
strcpy(inout, ((tm->tm_hour > 11 strcpy(inout, ((tm->tm_hour > 11
&& tm->tm_hour < 24) ? P_M_STR : A_M_STR)); && tm->tm_hour < HOURS_PER_DAY) ? P_M_STR : A_M_STR));
return 3; return 3;
} }
else if (flag == FROM_CHAR) else if (flag == FROM_CHAR)
...@@ -1737,7 +1737,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) ...@@ -1737,7 +1737,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
if (flag == TO_CHAR) if (flag == TO_CHAR)
{ {
strcpy(inout, ((tm->tm_hour > 11 strcpy(inout, ((tm->tm_hour > 11
&& tm->tm_hour < 24) ? PM_STR : AM_STR)); && tm->tm_hour < HOURS_PER_DAY) ? PM_STR : AM_STR));
return 1; return 1;
} }
else if (flag == FROM_CHAR) else if (flag == FROM_CHAR)
...@@ -1756,7 +1756,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) ...@@ -1756,7 +1756,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
if (flag == TO_CHAR) if (flag == TO_CHAR)
{ {
strcpy(inout, ((tm->tm_hour > 11 strcpy(inout, ((tm->tm_hour > 11
&& tm->tm_hour < 24) ? p_m_STR : a_m_STR)); && tm->tm_hour < HOURS_PER_DAY) ? p_m_STR : a_m_STR));
return 3; return 3;
} }
else if (flag == FROM_CHAR) else if (flag == FROM_CHAR)
...@@ -1775,7 +1775,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) ...@@ -1775,7 +1775,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
if (flag == TO_CHAR) if (flag == TO_CHAR)
{ {
strcpy(inout, ((tm->tm_hour > 11 strcpy(inout, ((tm->tm_hour > 11
&& tm->tm_hour < 24) ? pm_STR : am_STR)); && tm->tm_hour < HOURS_PER_DAY) ? pm_STR : am_STR));
return 1; return 1;
} }
else if (flag == FROM_CHAR) else if (flag == FROM_CHAR)
...@@ -1991,8 +1991,8 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data) ...@@ -1991,8 +1991,8 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
case DCH_SSSS: case DCH_SSSS:
if (flag == TO_CHAR) if (flag == TO_CHAR)
{ {
sprintf(inout, "%d", tm->tm_hour * 3600 + sprintf(inout, "%d", tm->tm_hour * SECS_PER_HOUR +
tm->tm_min * 60 + tm->tm_min * SECS_PER_MINUTE +
tm->tm_sec); tm->tm_sec);
if (S_THth(suf)) if (S_THth(suf))
str_numth(p_inout, inout, S_TH_TYPE(suf)); str_numth(p_inout, inout, S_TH_TYPE(suf));
...@@ -3129,10 +3129,10 @@ do_to_timestamp(text *date_txt, text *fmt, ...@@ -3129,10 +3129,10 @@ do_to_timestamp(text *date_txt, text *fmt,
{ {
int x = tmfc.ssss; int x = tmfc.ssss;
tm->tm_hour = x / 3600; tm->tm_hour = x / SECS_PER_HOUR;
x %= 3600; x %= SECS_PER_HOUR;
tm->tm_min = x / 60; tm->tm_min = x / SECS_PER_MINUTE;
x %= 60; x %= SECS_PER_MINUTE;
tm->tm_sec = x; tm->tm_sec = x;
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.136 2005/07/20 16:42:30 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.137 2005/07/21 03:56:18 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 * 24 + tm->tm_hour) * 60) * 60; sec = tm->tm_sec + tz + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * SECS_PER_MINUTE) * 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 * 60 + tm->tm_min) * 60) + tm->tm_sec; 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 * 30) + tm->tm_mday) * SECS_PER_DAY; result += tm->tm_year * 36525 * 864 + ((tm->tm_mon * DAYS_PER_MONTH) + tm->tm_mday) * SECS_PER_DAY;
break; break;
default: default:
...@@ -705,8 +705,8 @@ reltime2tm(RelativeTime time, struct pg_tm * tm) ...@@ -705,8 +705,8 @@ reltime2tm(RelativeTime time, struct pg_tm * tm)
FMODULO(dtime, tm->tm_year, 31557600); FMODULO(dtime, tm->tm_year, 31557600);
FMODULO(dtime, tm->tm_mon, 2592000); FMODULO(dtime, tm->tm_mon, 2592000);
FMODULO(dtime, tm->tm_mday, SECS_PER_DAY); FMODULO(dtime, tm->tm_mday, SECS_PER_DAY);
FMODULO(dtime, tm->tm_hour, 3600); FMODULO(dtime, tm->tm_hour, SECS_PER_HOUR);
FMODULO(dtime, tm->tm_min, 60); FMODULO(dtime, tm->tm_min, SECS_PER_MINUTE);
FMODULO(dtime, tm->tm_sec, 1); FMODULO(dtime, tm->tm_sec, 1);
} }
...@@ -838,8 +838,8 @@ interval_reltime(PG_FUNCTION_ARGS) ...@@ -838,8 +838,8 @@ interval_reltime(PG_FUNCTION_ARGS)
double span; double span;
#endif #endif
year = interval->month / 12; year = interval->month / MONTHS_PER_YEAR;
month = interval->month % 12; month = interval->month % MONTHS_PER_YEAR;
day = interval->day; day = interval->day;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -848,7 +848,7 @@ interval_reltime(PG_FUNCTION_ARGS) ...@@ -848,7 +848,7 @@ interval_reltime(PG_FUNCTION_ARGS)
interval->time; interval->time;
span /= USECS_PER_SEC; span /= USECS_PER_SEC;
#else #else
span = (365.25 * year + 30.0 * month + day) * SECS_PER_DAY + interval->time; span = (DAYS_PER_YEAR * year + (double)DAYS_PER_MONTH * month + day) * SECS_PER_DAY + interval->time;
#endif #endif
if (span < INT_MIN || span > INT_MAX) if (span < INT_MIN || span > INT_MAX)
...@@ -886,20 +886,20 @@ reltime_interval(PG_FUNCTION_ARGS) ...@@ -886,20 +886,20 @@ reltime_interval(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
year = (reltime / (36525 * 864)); year = (reltime / (36525 * 864));
reltime -= (year * (36525 * 864)); reltime -= (year * (36525 * 864));
month = (reltime / (30 * SECS_PER_DAY)); month = (reltime / (DAYS_PER_MONTH * SECS_PER_DAY));
reltime -= (month * (30 * SECS_PER_DAY)); reltime -= (month * (DAYS_PER_MONTH * SECS_PER_DAY));
day = reltime / SECS_PER_DAY; day = reltime / SECS_PER_DAY;
reltime -= day * SECS_PER_DAY; reltime -= day * SECS_PER_DAY;
result->time = (reltime * USECS_PER_SEC); result->time = (reltime * USECS_PER_SEC);
#else #else
TMODULO(reltime, year, 36525 * 864); TMODULO(reltime, year, 36525 * 864);
TMODULO(reltime, month, 30 * SECS_PER_DAY); TMODULO(reltime, month, DAYS_PER_MONTH * SECS_PER_DAY);
TMODULO(reltime, day, SECS_PER_DAY); TMODULO(reltime, day, SECS_PER_DAY);
result->time = reltime; result->time = reltime;
#endif #endif
result->month = 12 * year + month; result->month = MONTHS_PER_YEAR * year + month;
result->day = day; result->day = day;
break; break;
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.185 2005/07/20 16:42:30 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.186 2005/07/21 03:56:18 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2785,10 +2785,10 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -2785,10 +2785,10 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
*/ */
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
return interval->time + interval->day * (double)USECS_PER_DAY + return interval->time + interval->day * (double)USECS_PER_DAY +
interval->month * ((365.25 / 12.0) * USECS_PER_DAY); interval->month * ((DAYS_PER_YEAR / (double)MONTHS_PER_YEAR) * USECS_PER_DAY);
#else #else
return interval->time + interval->day * SECS_PER_DAY + return interval->time + interval->day * SECS_PER_DAY +
interval->month * ((365.25 / 12.0) * (double)SECS_PER_DAY); interval->month * ((DAYS_PER_YEAR / (double)MONTHS_PER_YEAR) * (double)SECS_PER_DAY);
#endif #endif
} }
case RELTIMEOID: case RELTIMEOID:
......
This diff is collapsed.
...@@ -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.274 2005/07/14 05:13:42 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.275 2005/07/21 03:56:21 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,
24 * 60, 0, INT_MAX / 60, NULL, NULL HOURS_PER_DAY * SECS_PER_MINUTE, 0, INT_MAX / SECS_PER_MINUTE, 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.47 2005/07/20 16:42:32 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.48 2005/07/21 03:56:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -60,8 +60,17 @@ typedef struct ...@@ -60,8 +60,17 @@ typedef struct
#define MAX_TIMESTAMP_PRECISION 6 #define MAX_TIMESTAMP_PRECISION 6
#define MAX_INTERVAL_PRECISION 6 #define MAX_INTERVAL_PRECISION 6
/* in both timestamp.h and ecpg/dt.h */
#define DAYS_PER_YEAR 365.25
#define MONTHS_PER_YEAR 12
/* average days per month */
#define DAYS_PER_MONTH 30
#define HOURS_PER_DAY 24
#define SECS_PER_DAY 86400 #define SECS_PER_DAY 86400
#define SECS_PER_HOUR 3600 #define SECS_PER_HOUR 3600
#define SECS_PER_MINUTE 60
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
#define USECS_PER_DAY INT64CONST(86400000000) #define USECS_PER_DAY INT64CONST(86400000000)
#define USECS_PER_HOUR INT64CONST(3600000000) #define USECS_PER_HOUR INT64CONST(3600000000)
......
...@@ -678,7 +678,7 @@ PGTYPESdate_defmt_asc(date *d, char *fmt, char *str) ...@@ -678,7 +678,7 @@ PGTYPESdate_defmt_asc(date *d, char *fmt, char *str)
return -1; return -1;
} }
if (tm.tm_mon < 1 || tm.tm_mon > 12) if (tm.tm_mon < 1 || tm.tm_mon > MONTHS_PER_YEAR)
{ {
errno = PGTYPES_DATE_BAD_MONTH; errno = PGTYPES_DATE_BAD_MONTH;
return -1; return -1;
......
...@@ -216,7 +216,17 @@ do { \ ...@@ -216,7 +216,17 @@ do { \
} while(0) } while(0)
#endif #endif
/* in both timestamp.h and ecpg/dt.h */
#define DAYS_PER_YEAR 365.25
#define MONTHS_PER_YEAR 12
/* average days per month */
#define DAYS_PER_MONTH 30
#define HOURS_PER_DAY 24
#define SECS_PER_DAY 86400 #define SECS_PER_DAY 86400
#define SECS_PER_HOUR 3600
#define SECS_PER_MINUTE 60
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
#define USECS_PER_DAY INT64CONST(86400000000) #define USECS_PER_DAY INT64CONST(86400000000)
#define USECS_PER_HOUR INT64CONST(3600000000) #define USECS_PER_HOUR INT64CONST(3600000000)
......
...@@ -688,7 +688,7 @@ DecodeSpecial(int field, char *lowtoken, int *val) ...@@ -688,7 +688,7 @@ DecodeSpecial(int field, char *lowtoken, int *val)
int int
EncodeDateOnly(struct tm * tm, int style, char *str, bool EuroDates) EncodeDateOnly(struct tm * tm, int style, char *str, bool EuroDates)
{ {
if (tm->tm_mon < 1 || tm->tm_mon > 12) if (tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR)
return -1; return -1;
switch (style) switch (style)
...@@ -813,8 +813,8 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha ...@@ -813,8 +813,8 @@ 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 / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
break; break;
...@@ -861,8 +861,8 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha ...@@ -861,8 +861,8 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn); sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
else else
{ {
hour = -(*tzp / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
} }
...@@ -907,8 +907,8 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha ...@@ -907,8 +907,8 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn); sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
else else
{ {
hour = -(*tzp / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
} }
} }
...@@ -970,8 +970,8 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha ...@@ -970,8 +970,8 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha
* rejected by the date/time parser later. - thomas * rejected by the date/time parser later. - thomas
* 2001-10-19 * 2001-10-19
*/ */
hour = -(*tzp / 3600); hour = -(*tzp / SECS_PER_HOUR);
min = (abs(*tzp) / 60) % 60; min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min); sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min);
} }
} }
...@@ -1055,7 +1055,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn) ...@@ -1055,7 +1055,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct tm * tm, char **tzn)
#elif defined(HAVE_INT_TIMEZONE) #elif defined(HAVE_INT_TIMEZONE)
if (tzp != NULL) if (tzp != NULL)
{ {
*tzp = (tm->tm_isdst > 0) ? TIMEZONE_GLOBAL - 3600 : TIMEZONE_GLOBAL; *tzp = (tm->tm_isdst > 0) ? TIMEZONE_GLOBAL - SECS_PER_HOUR : TIMEZONE_GLOBAL;
if (tzn != NULL) if (tzn != NULL)
{ {
...@@ -1138,7 +1138,7 @@ DetermineLocalTimeZone(struct tm * tm) ...@@ -1138,7 +1138,7 @@ DetermineLocalTimeZone(struct tm * tm)
/* tm_gmtoff is Sun/DEC-ism */ /* tm_gmtoff is Sun/DEC-ism */
tz = -(tmp->tm_gmtoff); tz = -(tmp->tm_gmtoff);
#elif defined(HAVE_INT_TIMEZONE) #elif defined(HAVE_INT_TIMEZONE)
tz = (tmp->tm_isdst > 0) ? TIMEZONE_GLOBAL - 3600 : TIMEZONE_GLOBAL; tz = (tmp->tm_isdst > 0) ? TIMEZONE_GLOBAL - SECS_PER_HOUR : TIMEZONE_GLOBAL;
#endif /* HAVE_INT_TIMEZONE */ #endif /* HAVE_INT_TIMEZONE */
} }
else else
...@@ -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 * 24 + tm->tm_hour) * 60) * 60; mysec = tm->tm_sec + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * SECS_PER_MINUTE) * 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 * 24 + tmp->tm_hour) * 60) * 60; locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * 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 * 24 + tmp->tm_hour) * 60) * 60; locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * 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 * 24 + tmp->tm_hour) * 60) * 60; locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE;
delta2 = mysec - locsec; delta2 = mysec - locsec;
} }
tm->tm_isdst = tmp->tm_isdst; tm->tm_isdst = tmp->tm_isdst;
...@@ -1250,10 +1250,10 @@ dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec) ...@@ -1250,10 +1250,10 @@ dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
*sec = time / USECS_PER_SEC; *sec = time / USECS_PER_SEC;
*fsec = time - (*sec * USECS_PER_SEC); *fsec = time - (*sec * USECS_PER_SEC);
#else #else
*hour = time / 3600; *hour = time / SECS_PER_HOUR;
time -= (*hour) * 3600; time -= (*hour) * SECS_PER_HOUR;
*min = time / 60; *min = time / SECS_PER_MINUTE;
time -= (*min) * 60; time -= (*min) * SECS_PER_MINUTE;
*sec = time; *sec = time;
*fsec = JROUND(time - *sec); *fsec = JROUND(time - *sec);
#endif #endif
...@@ -1437,7 +1437,7 @@ int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits, bool EuroDates) ...@@ -1437,7 +1437,7 @@ int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits, bool EuroDates)
} }
/* already have year? then could be month */ /* already have year? then could be month */
else if ((fmask & DTK_M(YEAR)) && !(fmask & DTK_M(MONTH)) && val >= 1 && val <= 12) else if ((fmask & DTK_M(YEAR)) && !(fmask & DTK_M(MONTH)) && val >= 1 && val <= MONTHS_PER_YEAR)
{ {
*tmask = DTK_M(MONTH); *tmask = DTK_M(MONTH);
tm->tm_mon = val; tm->tm_mon = val;
...@@ -1450,7 +1450,7 @@ int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits, bool EuroDates) ...@@ -1450,7 +1450,7 @@ int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits, bool EuroDates)
*tmask = DTK_M(DAY); *tmask = DTK_M(DAY);
tm->tm_mday = val; tm->tm_mday = val;
} }
else if (!(fmask & DTK_M(MONTH)) && val >= 1 && val <= 12) else if (!(fmask & DTK_M(MONTH)) && val >= 1 && val <= MONTHS_PER_YEAR)
{ {
*tmask = DTK_M(MONTH); *tmask = DTK_M(MONTH);
tm->tm_mon = val; tm->tm_mon = val;
...@@ -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 * 60 + min) * 60; tz = (hr * SECS_PER_MINUTE + 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 * 60) - tz; *tzp = (val * SECS_PER_MINUTE) - 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 * 60; *tzp += val * SECS_PER_MINUTE;
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 * 60; *tzp = val * SECS_PER_MINUTE;
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 * 60; *tzp = val * SECS_PER_MINUTE;
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 * 60 * datetktbl[j].value; *tz = -15 * SECS_PER_MINUTE * datetktbl[j].value;
break; break;
} }
} }
...@@ -3167,7 +3167,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d, ...@@ -3167,7 +3167,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d,
err = 1; err = 1;
*hour = 0; *hour = 0;
} }
if (*month > 12) if (*month > MONTHS_PER_YEAR)
{ {
err = 1; err = 1;
*month = 1; *month = 1;
......
...@@ -254,7 +254,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec ...@@ -254,7 +254,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec
{ {
int sec; int sec;
fval *= 60; fval *= SECS_PER_MINUTE;
sec = fval; sec = fval;
tm->tm_sec += sec; tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -272,7 +272,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec ...@@ -272,7 +272,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec
{ {
int sec; int sec;
fval *= 3600; fval *= SECS_PER_HOUR;
sec = fval; sec = fval;
tm->tm_sec += sec; tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -326,7 +326,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec ...@@ -326,7 +326,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec
{ {
int sec; int sec;
fval *= 30 * SECS_PER_DAY; fval *= DAYS_PER_MONTH * SECS_PER_DAY;
sec = fval; sec = fval;
tm->tm_sec += sec; tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
...@@ -341,28 +341,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec ...@@ -341,28 +341,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec
case DTK_YEAR: case DTK_YEAR:
tm->tm_year += val; tm->tm_year += val;
if (fval != 0) if (fval != 0)
tm->tm_mon += fval * 12; tm->tm_mon += fval * MONTHS_PER_YEAR;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR); tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break; break;
case DTK_DECADE: case DTK_DECADE:
tm->tm_year += val * 10; tm->tm_year += val * 10;
if (fval != 0) if (fval != 0)
tm->tm_mon += fval * 120; tm->tm_mon += fval * MONTHS_PER_YEAR * 10;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR); tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break; break;
case DTK_CENTURY: case DTK_CENTURY:
tm->tm_year += val * 100; tm->tm_year += val * 100;
if (fval != 0) if (fval != 0)
tm->tm_mon += fval * 1200; tm->tm_mon += fval * MONTHS_PER_YEAR * 100;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR); tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break; break;
case DTK_MILLENNIUM: case DTK_MILLENNIUM:
tm->tm_year += val * 1000; tm->tm_year += val * 1000;
if (fval != 0) if (fval != 0)
tm->tm_mon += fval * 12000; tm->tm_mon += fval * MONTHS_PER_YEAR * 1000;
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR); tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
break; break;
...@@ -680,8 +680,8 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec) ...@@ -680,8 +680,8 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec)
if (span.month != 0) if (span.month != 0)
{ {
tm->tm_year = span.month / 12; tm->tm_year = span.month / MONTHS_PER_YEAR;
tm->tm_mon = span.month % 12; tm->tm_mon = span.month % MONTHS_PER_YEAR;
} }
else else
...@@ -703,8 +703,8 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec) ...@@ -703,8 +703,8 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec)
*fsec = (time - (tm->tm_sec * USECS_PER_SEC)); *fsec = (time - (tm->tm_sec * USECS_PER_SEC));
#else #else
TMODULO(time, tm->tm_mday, (double)SECS_PER_DAY); TMODULO(time, tm->tm_mday, (double)SECS_PER_DAY);
TMODULO(time, tm->tm_hour, 3600.0); TMODULO(time, tm->tm_hour, (double)SECS_PER_HOUR);
TMODULO(time, tm->tm_min, 60.0); TMODULO(time, tm->tm_min, (double)SECS_PER_MINUTE);
TMODULO(time, tm->tm_sec, 1.0); TMODULO(time, tm->tm_sec, 1.0);
*fsec = time; *fsec = time;
#endif #endif
...@@ -715,16 +715,16 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec) ...@@ -715,16 +715,16 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec)
static int static int
tm2interval(struct tm *tm, fsec_t fsec, interval *span) tm2interval(struct tm *tm, fsec_t fsec, interval *span)
{ {
span->month = tm->tm_year * 12 + tm->tm_mon; span->month = tm->tm_year * MONTHS_PER_YEAR + tm->tm_mon;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
span->time = (((((((tm->tm_mday * INT64CONST(24)) + span->time = (((((((tm->tm_mday * INT64CONST(HOURS_PER_DAY)) +
tm->tm_hour) * INT64CONST(60)) + tm->tm_hour) * INT64CONST(SECS_PER_MINUTE)) +
tm->tm_min) * INT64CONST(60)) + tm->tm_min) * INT64CONST(SECS_PER_MINUTE)) +
tm->tm_sec) * USECS_PER_SEC) + fsec; tm->tm_sec) * USECS_PER_SEC) + fsec;
#else #else
span->time = (((((tm->tm_mday * 24.0) + span->time = (((((tm->tm_mday * (double)HOURS_PER_DAY) +
tm->tm_hour) * 60.0) + tm->tm_hour) * (double)SECS_PER_MINUTE) +
tm->tm_min) * 60.0) + 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);
#endif #endif
......
...@@ -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 * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec; return (((((hour * SECS_PER_MINUTE) + 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 * 60) + min) * 60) + sec + fsec; return (((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec + fsec;
} /* time2t() */ } /* time2t() */
#endif #endif
...@@ -119,10 +119,10 @@ dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec) ...@@ -119,10 +119,10 @@ dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
*sec = time / USECS_PER_SEC; *sec = time / USECS_PER_SEC;
*fsec = time - *sec * USECS_PER_SEC; *fsec = time - *sec * USECS_PER_SEC;
#else #else
*hour = time / 3600; *hour = time / SECS_PER_HOUR;
time -= (*hour) * 3600; time -= (*hour) * SECS_PER_HOUR;
*min = time / 60; *min = time / SECS_PER_MINUTE;
time -= (*min) * 60; time -= (*min) * SECS_PER_MINUTE;
*sec = time; *sec = time;
*fsec = JROUND(time - *sec); *fsec = JROUND(time - *sec);
#endif #endif
...@@ -221,7 +221,7 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn) ...@@ -221,7 +221,7 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
if (tzn != NULL) if (tzn != NULL)
*tzn = (char *) tm->tm_zone; *tzn = (char *) tm->tm_zone;
#elif defined(HAVE_INT_TIMEZONE) #elif defined(HAVE_INT_TIMEZONE)
*tzp = (tm->tm_isdst > 0) ? TIMEZONE_GLOBAL - 3600 : TIMEZONE_GLOBAL; *tzp = (tm->tm_isdst > 0) ? TIMEZONE_GLOBAL - SECS_PER_HOUR : TIMEZONE_GLOBAL;
if (tzn != NULL) if (tzn != NULL)
*tzn = TZNAME_GLOBAL[(tm->tm_isdst > 0)]; *tzn = TZNAME_GLOBAL[(tm->tm_isdst > 0)];
#endif #endif
...@@ -875,15 +875,15 @@ PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout) ...@@ -875,15 +875,15 @@ PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout)
if (timestamp2tm(*tin, NULL, tm, &fsec, NULL) !=0) if (timestamp2tm(*tin, NULL, tm, &fsec, NULL) !=0)
return -1; return -1;
tm->tm_mon += span->month; tm->tm_mon += span->month;
if (tm->tm_mon > 12) if (tm->tm_mon > MONTHS_PER_YEAR)
{ {
tm->tm_year += (tm->tm_mon - 1) / 12; tm->tm_year += (tm->tm_mon - 1) / MONTHS_PER_YEAR;
tm->tm_mon = (tm->tm_mon - 1) % 12 + 1; tm->tm_mon = (tm->tm_mon - 1) % MONTHS_PER_YEAR + 1;
} }
else if (tm->tm_mon < 1) else if (tm->tm_mon < 1)
{ {
tm->tm_year += tm->tm_mon / 12 - 1; tm->tm_year += tm->tm_mon / MONTHS_PER_YEAR - 1;
tm->tm_mon = tm->tm_mon % 12 + 12; tm->tm_mon = tm->tm_mon % MONTHS_PER_YEAR + MONTHS_PER_YEAR;
} }
......
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