mirror of https://github.com/postgres/postgres
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
This commit is contained in:
parent
dc73819f2e
commit
a536b2dd80
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
*
|
||||
* 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)
|
|||
if (doit)
|
||||
{
|
||||
/* Here we change from SQL to Unix sign convention */
|
||||
CTimeZone = -hours * 3600;
|
||||
CTimeZone = -hours * SECS_PER_HOUR;
|
||||
HasCTZSet = true;
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ assign_timezone(const char *value, bool doit, GucSource source)
|
|||
if (!result)
|
||||
return NULL;
|
||||
snprintf(result, 64, "%.5f",
|
||||
(double) (-CTimeZone) / 3600.0);
|
||||
(double) (-CTimeZone) / (double)SECS_PER_HOUR);
|
||||
}
|
||||
else
|
||||
result = strdup(value);
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
*
|
||||
*
|
||||
* 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
|
||||
*
|
||||
|
@ -1284,7 +1284,7 @@ ServerLoop(void)
|
|||
* less than an hour ...
|
||||
*/
|
||||
now = time(NULL);
|
||||
if (now - last_touch_time >= 58 * 60)
|
||||
if (now - last_touch_time >= 58 * SECS_PER_MINUTE)
|
||||
{
|
||||
TouchSocketFile();
|
||||
TouchSocketLockFile();
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*
|
||||
*
|
||||
* 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 @@
|
|||
#include "storage/pg_shmem.h"
|
||||
#include "utils/guc.h"
|
||||
#include "utils/ps_status.h"
|
||||
|
||||
#include "utils/timestamp.h"
|
||||
|
||||
/*
|
||||
* We really want line-buffered mode for logfile output, but Windows does
|
||||
|
@ -60,7 +60,7 @@
|
|||
* start, but the rest can change at SIGHUP.
|
||||
*/
|
||||
bool Redirect_stderr = false;
|
||||
int Log_RotationAge = 24 * 60;
|
||||
int Log_RotationAge = HOURS_PER_DAY * SECS_PER_MINUTE;
|
||||
int Log_RotationSize = 10 * 1024;
|
||||
char *Log_directory = NULL;
|
||||
char *Log_filename = NULL;
|
||||
|
@ -855,7 +855,7 @@ set_next_rotation_time(void)
|
|||
* fairly loosely. In this version we align to local time rather than
|
||||
* GMT.
|
||||
*/
|
||||
rotinterval = Log_RotationAge * 60; /* convert to seconds */
|
||||
rotinterval = Log_RotationAge * SECS_PER_MINUTE; /* convert to seconds */
|
||||
now = time(NULL);
|
||||
tm = pg_localtime(&now, global_timezone);
|
||||
now += tm->tm_gmtoff;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* 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
|
||||
* this is the "main" module of the postgres backend and
|
||||
|
@ -3536,10 +3536,10 @@ log_disconnections(int code, Datum arg)
|
|||
end.tv_sec -= port->session_start.tv_sec;
|
||||
end.tv_usec -= port->session_start.tv_usec;
|
||||
|
||||
hours = end.tv_sec / 3600;
|
||||
end.tv_sec %= 3600;
|
||||
minutes = end.tv_sec / 60;
|
||||
seconds = end.tv_sec % 60;
|
||||
hours = end.tv_sec / SECS_PER_HOUR;
|
||||
end.tv_sec %= SECS_PER_HOUR;
|
||||
minutes = end.tv_sec / SECS_PER_MINUTE;
|
||||
seconds = end.tv_sec % SECS_PER_MINUTE;
|
||||
|
||||
/* if time has gone backwards for some reason say so, or print time */
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* 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 @@
|
|||
|
||||
/*
|
||||
* 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__
|
||||
#error -ffast-math is known to break this code
|
||||
|
@ -918,10 +918,10 @@ static int
|
|||
tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
|
||||
{
|
||||
#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;
|
||||
#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
|
||||
return 0;
|
||||
}
|
||||
|
@ -946,8 +946,8 @@ time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
|
|||
double trem;
|
||||
|
||||
trem = time;
|
||||
TMODULO(trem, tm->tm_hour, 3600.0);
|
||||
TMODULO(trem, tm->tm_min, 60.0);
|
||||
TMODULO(trem, tm->tm_hour, (double)SECS_PER_HOUR);
|
||||
TMODULO(trem, tm->tm_min, (double)SECS_PER_MINUTE);
|
||||
TMODULO(trem, tm->tm_sec, 1.0);
|
||||
*fsec = trem;
|
||||
#endif
|
||||
|
@ -1348,10 +1348,10 @@ timestamp_time(PG_FUNCTION_ARGS)
|
|||
* Could also do this with time = (timestamp / USECS_PER_DAY *
|
||||
* USECS_PER_DAY) - timestamp;
|
||||
*/
|
||||
result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
|
||||
result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
|
||||
USECS_PER_SEC) + fsec;
|
||||
#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
|
||||
|
||||
PG_RETURN_TIMEADT(result);
|
||||
|
@ -1385,10 +1385,10 @@ timestamptz_time(PG_FUNCTION_ARGS)
|
|||
* Could also do this with time = (timestamp / USECS_PER_DAY *
|
||||
* USECS_PER_DAY) - timestamp;
|
||||
*/
|
||||
result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
|
||||
result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
|
||||
USECS_PER_SEC) + fsec;
|
||||
#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
|
||||
|
||||
PG_RETURN_TIMEADT(result);
|
||||
|
@ -1715,10 +1715,10 @@ static int
|
|||
tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
|
||||
{
|
||||
#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;
|
||||
#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
|
||||
result->zone = tz;
|
||||
|
||||
|
@ -1843,8 +1843,8 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
|
|||
#else
|
||||
double trem = time->time;
|
||||
|
||||
TMODULO(trem, tm->tm_hour, 3600.0);
|
||||
TMODULO(trem, tm->tm_min, 60.0);
|
||||
TMODULO(trem, tm->tm_hour, (double)SECS_PER_HOUR);
|
||||
TMODULO(trem, tm->tm_min, (double)SECS_PER_MINUTE);
|
||||
TMODULO(trem, tm->tm_sec, 1.0);
|
||||
*fsec = trem;
|
||||
#endif
|
||||
|
@ -2399,13 +2399,13 @@ timetz_part(PG_FUNCTION_ARGS)
|
|||
|
||||
case DTK_TZ_MINUTE:
|
||||
result = -tz;
|
||||
result /= 60;
|
||||
FMODULO(result, dummy, 60.0);
|
||||
result /= SECS_PER_MINUTE;
|
||||
FMODULO(result, dummy, (double)SECS_PER_MINUTE);
|
||||
break;
|
||||
|
||||
case DTK_TZ_HOUR:
|
||||
dummy = -tz;
|
||||
FMODULO(dummy, result, 3600.0);
|
||||
FMODULO(dummy, result, (double)SECS_PER_HOUR);
|
||||
break;
|
||||
|
||||
case DTK_MICROSEC:
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* 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,
|
|||
tm->tm_isdst = 1;
|
||||
if (tzp == NULL)
|
||||
return DTERR_BAD_FORMAT;
|
||||
*tzp += val * 60;
|
||||
*tzp += val * SECS_PER_MINUTE;
|
||||
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 * 60;
|
||||
*tzp = val * SECS_PER_MINUTE;
|
||||
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 * 60;
|
||||
*tzp = val * SECS_PER_MINUTE;
|
||||
ftype[i] = DTK_TZ;
|
||||
break;
|
||||
|
||||
|
@ -1566,7 +1566,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
|||
/* check for valid 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;
|
||||
}
|
||||
|
||||
|
@ -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 * 60) * 60;
|
||||
sec = tm->tm_sec + (tm->tm_min + tm->tm_hour * SECS_PER_MINUTE) * 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 - (24 * 60 * 60);
|
||||
prevtime = mytime - (HOURS_PER_DAY * SECS_PER_MINUTE * SECS_PER_MINUTE);
|
||||
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 * 60;
|
||||
*tzp += val * SECS_PER_MINUTE;
|
||||
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 * 60;
|
||||
*tzp = val * SECS_PER_MINUTE;
|
||||
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 * 60;
|
||||
*tzp = val * SECS_PER_MINUTE;
|
||||
ftype[i] = DTK_TZ;
|
||||
break;
|
||||
|
||||
|
@ -2431,7 +2431,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm)
|
|||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
/* check for valid day */
|
||||
|
@ -2833,7 +2833,7 @@ DecodeTimezone(char *str, int *tzp)
|
|||
if (min < 0 || min >= 60)
|
||||
return DTERR_TZDISP_OVERFLOW;
|
||||
|
||||
tz = (hr * 60 + min) * 60;
|
||||
tz = (hr * SECS_PER_MINUTE + min) * SECS_PER_MINUTE;
|
||||
if (*str == '-')
|
||||
tz = -tz;
|
||||
|
||||
|
@ -2890,7 +2890,7 @@ DecodePosixTimezone(char *str, int *tzp)
|
|||
{
|
||||
case DTZ:
|
||||
case TZ:
|
||||
*tzp = (val * 60) - tz;
|
||||
*tzp = (val * SECS_PER_MINUTE) - tz;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -3116,7 +3116,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||
{
|
||||
int sec;
|
||||
|
||||
fval *= 60;
|
||||
fval *= SECS_PER_MINUTE;
|
||||
sec = fval;
|
||||
tm->tm_sec += sec;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
|
@ -3134,7 +3134,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||
{
|
||||
int sec;
|
||||
|
||||
fval *= 3600;
|
||||
fval *= SECS_PER_HOUR;
|
||||
sec = fval;
|
||||
tm->tm_sec += sec;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
|
@ -3188,7 +3188,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||
{
|
||||
int sec;
|
||||
|
||||
fval *= 30 * SECS_PER_DAY;
|
||||
fval *= DAYS_PER_MONTH * SECS_PER_DAY;
|
||||
sec = fval;
|
||||
tm->tm_sec += sec;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
|
@ -3203,28 +3203,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
|
|||
case DTK_YEAR:
|
||||
tm->tm_year += val;
|
||||
if (fval != 0)
|
||||
tm->tm_mon += fval * 12;
|
||||
tm->tm_mon += fval * MONTHS_PER_YEAR;
|
||||
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
|
||||
break;
|
||||
|
||||
case DTK_DECADE:
|
||||
tm->tm_year += val * 10;
|
||||
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);
|
||||
break;
|
||||
|
||||
case DTK_CENTURY:
|
||||
tm->tm_year += val * 100;
|
||||
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);
|
||||
break;
|
||||
|
||||
case DTK_MILLENNIUM:
|
||||
tm->tm_year += val * 1000;
|
||||
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);
|
||||
break;
|
||||
|
||||
|
@ -3422,7 +3422,7 @@ datebsearch(char *key, datetkn *base, unsigned int nel)
|
|||
int
|
||||
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;
|
||||
|
||||
switch (style)
|
||||
|
@ -3482,7 +3482,7 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
|
|||
int
|
||||
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;
|
||||
|
||||
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)
|
|||
int hour,
|
||||
min;
|
||||
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
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,
|
|||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
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,
|
|||
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
|
||||
else
|
||||
{
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
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,
|
|||
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
|
||||
else
|
||||
{
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
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,
|
|||
* rejected by the date/time parser later. - thomas
|
||||
* 2001-10-19
|
||||
*/
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* -----------------------------------------------------------------------
|
||||
* 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
|
||||
|
@ -1718,7 +1718,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
|
|||
if (flag == TO_CHAR)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (flag == FROM_CHAR)
|
||||
|
@ -1737,7 +1737,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
|
|||
if (flag == TO_CHAR)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (flag == FROM_CHAR)
|
||||
|
@ -1756,7 +1756,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
|
|||
if (flag == TO_CHAR)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (flag == FROM_CHAR)
|
||||
|
@ -1775,7 +1775,7 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
|
|||
if (flag == TO_CHAR)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (flag == FROM_CHAR)
|
||||
|
@ -1991,8 +1991,8 @@ dch_time(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
|
|||
case DCH_SSSS:
|
||||
if (flag == TO_CHAR)
|
||||
{
|
||||
sprintf(inout, "%d", tm->tm_hour * 3600 +
|
||||
tm->tm_min * 60 +
|
||||
sprintf(inout, "%d", tm->tm_hour * SECS_PER_HOUR +
|
||||
tm->tm_min * SECS_PER_MINUTE +
|
||||
tm->tm_sec);
|
||||
if (S_THth(suf))
|
||||
str_numth(p_inout, inout, S_TH_TYPE(suf));
|
||||
|
@ -3129,10 +3129,10 @@ do_to_timestamp(text *date_txt, text *fmt,
|
|||
{
|
||||
int x = tmfc.ssss;
|
||||
|
||||
tm->tm_hour = x / 3600;
|
||||
x %= 3600;
|
||||
tm->tm_min = x / 60;
|
||||
x %= 60;
|
||||
tm->tm_hour = x / SECS_PER_HOUR;
|
||||
x %= SECS_PER_HOUR;
|
||||
tm->tm_min = x / SECS_PER_MINUTE;
|
||||
x %= SECS_PER_MINUTE;
|
||||
tm->tm_sec = x;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*
|
||||
*
|
||||
* 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)
|
|||
return INVALID_ABSTIME;
|
||||
|
||||
/* 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 */
|
||||
if ((day == MAX_DAYNUM && sec < 0) ||
|
||||
|
@ -638,8 +638,8 @@ reltimein(PG_FUNCTION_ARGS)
|
|||
switch (dtype)
|
||||
{
|
||||
case DTK_DELTA:
|
||||
result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec;
|
||||
result += tm->tm_year * 36525 * 864 + ((tm->tm_mon * 30) + tm->tm_mday) * SECS_PER_DAY;
|
||||
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;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -705,8 +705,8 @@ reltime2tm(RelativeTime time, struct pg_tm * tm)
|
|||
FMODULO(dtime, tm->tm_year, 31557600);
|
||||
FMODULO(dtime, tm->tm_mon, 2592000);
|
||||
FMODULO(dtime, tm->tm_mday, SECS_PER_DAY);
|
||||
FMODULO(dtime, tm->tm_hour, 3600);
|
||||
FMODULO(dtime, tm->tm_min, 60);
|
||||
FMODULO(dtime, tm->tm_hour, SECS_PER_HOUR);
|
||||
FMODULO(dtime, tm->tm_min, SECS_PER_MINUTE);
|
||||
FMODULO(dtime, tm->tm_sec, 1);
|
||||
}
|
||||
|
||||
|
@ -838,8 +838,8 @@ interval_reltime(PG_FUNCTION_ARGS)
|
|||
double span;
|
||||
#endif
|
||||
|
||||
year = interval->month / 12;
|
||||
month = interval->month % 12;
|
||||
year = interval->month / MONTHS_PER_YEAR;
|
||||
month = interval->month % MONTHS_PER_YEAR;
|
||||
day = interval->day;
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
|
@ -848,7 +848,7 @@ interval_reltime(PG_FUNCTION_ARGS)
|
|||
interval->time;
|
||||
span /= USECS_PER_SEC;
|
||||
#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
|
||||
|
||||
if (span < INT_MIN || span > INT_MAX)
|
||||
|
@ -886,20 +886,20 @@ reltime_interval(PG_FUNCTION_ARGS)
|
|||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
year = (reltime / (36525 * 864));
|
||||
reltime -= (year * (36525 * 864));
|
||||
month = (reltime / (30 * SECS_PER_DAY));
|
||||
reltime -= (month * (30 * SECS_PER_DAY));
|
||||
month = (reltime / (DAYS_PER_MONTH * SECS_PER_DAY));
|
||||
reltime -= (month * (DAYS_PER_MONTH * SECS_PER_DAY));
|
||||
day = reltime / SECS_PER_DAY;
|
||||
reltime -= day * SECS_PER_DAY;
|
||||
|
||||
result->time = (reltime * USECS_PER_SEC);
|
||||
#else
|
||||
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);
|
||||
|
||||
result->time = reltime;
|
||||
#endif
|
||||
result->month = 12 * year + month;
|
||||
result->month = MONTHS_PER_YEAR * year + month;
|
||||
result->day = day;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
*
|
||||
* 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)
|
|||
*/
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
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
|
||||
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
|
||||
}
|
||||
case RELTIMEOID:
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.134 2005/07/20 16:42:31 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.135 2005/07/21 03:56:20 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -34,7 +34,7 @@
|
|||
|
||||
/*
|
||||
* 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__
|
||||
#error -ffast-math is known to break this code
|
||||
|
@ -698,13 +698,13 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||
}
|
||||
else if (range == INTERVAL_MASK(YEAR))
|
||||
{
|
||||
interval->month = (interval->month / 12) * 12;
|
||||
interval->month = (interval->month / MONTHS_PER_YEAR) * MONTHS_PER_YEAR;
|
||||
interval->day = 0;
|
||||
interval->time = 0;
|
||||
}
|
||||
else if (range == INTERVAL_MASK(MONTH))
|
||||
{
|
||||
interval->month %= 12;
|
||||
interval->month %= MONTHS_PER_YEAR;
|
||||
interval->day = 0;
|
||||
interval->time = 0;
|
||||
}
|
||||
|
@ -729,7 +729,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||
interval->time = (interval->time / USECS_PER_HOUR) *
|
||||
USECS_PER_HOUR;
|
||||
#else
|
||||
interval->time = ((int)(interval->time / 3600)) * 3600.0;
|
||||
interval->time = ((int)(interval->time / SECS_PER_HOUR)) * (double)SECS_PER_HOUR;
|
||||
#endif
|
||||
}
|
||||
else if (range == INTERVAL_MASK(MINUTE))
|
||||
|
@ -750,8 +750,8 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||
USECS_PER_MINUTE;
|
||||
|
||||
#else
|
||||
TMODULO(interval->time, hour, 3600.0);
|
||||
interval->time = ((int)(interval->time / 60)) * 60.0;
|
||||
TMODULO(interval->time, hour, (double)SECS_PER_HOUR);
|
||||
interval->time = ((int)(interval->time / SECS_PER_MINUTE)) * (double)SECS_PER_MINUTE;
|
||||
#endif
|
||||
}
|
||||
else if (range == INTERVAL_MASK(SECOND))
|
||||
|
@ -769,7 +769,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||
minute = interval->time / USECS_PER_MINUTE;
|
||||
interval->time -= minute * USECS_PER_MINUTE;
|
||||
#else
|
||||
TMODULO(interval->time, minute, 60.0);
|
||||
TMODULO(interval->time, minute, (double)SECS_PER_MINUTE);
|
||||
/* return subseconds too */
|
||||
#endif
|
||||
}
|
||||
|
@ -783,7 +783,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||
interval->time = (interval->time / USECS_PER_HOUR) *
|
||||
USECS_PER_HOUR;
|
||||
#else
|
||||
interval->time = ((int) (interval->time / 3600)) * 3600.0;
|
||||
interval->time = ((int) (interval->time / SECS_PER_HOUR)) * (double)SECS_PER_HOUR;
|
||||
#endif
|
||||
}
|
||||
/* DAY TO MINUTE */
|
||||
|
@ -797,7 +797,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||
interval->time = (interval->time / USECS_PER_MINUTE) *
|
||||
USECS_PER_MINUTE;
|
||||
#else
|
||||
interval->time = ((int)(interval->time / 60)) * 60.0;
|
||||
interval->time = ((int)(interval->time / SECS_PER_MINUTE)) * (double)SECS_PER_MINUTE;
|
||||
#endif
|
||||
}
|
||||
/* DAY TO SECOND */
|
||||
|
@ -818,7 +818,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||
interval->time = (interval->time / USECS_PER_MINUTE) *
|
||||
USECS_PER_MINUTE;
|
||||
#else
|
||||
interval->time = ((int)(interval->time / 60)) * 60.0;
|
||||
interval->time = ((int)(interval->time / SECS_PER_MINUTE)) * (double)SECS_PER_MINUTE;
|
||||
#endif
|
||||
}
|
||||
/* HOUR TO SECOND */
|
||||
|
@ -848,7 +848,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
|
|||
hour = interval->time / USECS_PER_HOUR;
|
||||
interval->time -= hour * USECS_PER_HOUR;
|
||||
#else
|
||||
TMODULO(interval->time, hour, 3600.0);
|
||||
TMODULO(interval->time, hour, (double)SECS_PER_HOUR);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
@ -971,10 +971,10 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
|
|||
*sec = time / USECS_PER_SEC;
|
||||
*fsec = time - (*sec * USECS_PER_SEC);
|
||||
#else
|
||||
*hour = time / 3600;
|
||||
time -= (*hour) * 3600;
|
||||
*min = time / 60;
|
||||
time -= (*min) * 60;
|
||||
*hour = time / SECS_PER_HOUR;
|
||||
time -= (*hour) * SECS_PER_HOUR;
|
||||
*min = time / SECS_PER_MINUTE;
|
||||
time -= (*min) * SECS_PER_MINUTE;
|
||||
*sec = time;
|
||||
*fsec = JROUND(time - *sec);
|
||||
#endif
|
||||
|
@ -1180,8 +1180,8 @@ interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec)
|
|||
double time;
|
||||
#endif
|
||||
|
||||
tm->tm_year = span.month / 12;
|
||||
tm->tm_mon = span.month % 12;
|
||||
tm->tm_year = span.month / MONTHS_PER_YEAR;
|
||||
tm->tm_mon = span.month % MONTHS_PER_YEAR;
|
||||
tm->tm_mday = span.day;
|
||||
time = span.time;
|
||||
|
||||
|
@ -1193,8 +1193,8 @@ interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec)
|
|||
tm->tm_sec = (time / USECS_PER_SEC);
|
||||
*fsec = (time - (tm->tm_sec * USECS_PER_SEC));
|
||||
#else
|
||||
TMODULO(time, tm->tm_hour, 3600.0);
|
||||
TMODULO(time, tm->tm_min, 60.0);
|
||||
TMODULO(time, tm->tm_hour, (double)SECS_PER_HOUR);
|
||||
TMODULO(time, tm->tm_min, (double)SECS_PER_MINUTE);
|
||||
TMODULO(time, tm->tm_sec, 1.0);
|
||||
*fsec = time;
|
||||
#endif
|
||||
|
@ -1205,15 +1205,15 @@ interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec)
|
|||
int
|
||||
tm2interval(struct pg_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;
|
||||
span->day = tm->tm_mday;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
span->time = (((((tm->tm_hour * INT64CONST(60)) +
|
||||
tm->tm_min) * INT64CONST(60)) +
|
||||
span->time = (((((tm->tm_hour * INT64CONST(SECS_PER_MINUTE)) +
|
||||
tm->tm_min) * INT64CONST(SECS_PER_MINUTE)) +
|
||||
tm->tm_sec) * USECS_PER_SEC) + fsec;
|
||||
#else
|
||||
span->time = (((tm->tm_hour * 60.0) +
|
||||
tm->tm_min) * 60.0) +
|
||||
span->time = (((tm->tm_hour * (double)SECS_PER_MINUTE) +
|
||||
tm->tm_min) * (double)SECS_PER_MINUTE) +
|
||||
tm->tm_sec;
|
||||
span->time = JROUND(span->time + fsec);
|
||||
#endif
|
||||
|
@ -1225,14 +1225,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 * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec;
|
||||
return (((((hour * SECS_PER_MINUTE) + 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 * 60) + min) * 60) + sec + fsec;
|
||||
return (((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec + fsec;
|
||||
} /* time2t() */
|
||||
#endif
|
||||
|
||||
|
@ -1608,15 +1608,15 @@ interval_cmp_internal(Interval *interval1, Interval *interval2)
|
|||
span2 = interval2->time;
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
span1 += interval1->month * INT64CONST(30) * USECS_PER_DAY;
|
||||
span1 += interval1->day * INT64CONST(24) * USECS_PER_HOUR;
|
||||
span2 += interval2->month * INT64CONST(30) * USECS_PER_DAY;
|
||||
span2 += interval2->day * INT64CONST(24) * USECS_PER_HOUR;
|
||||
span1 += interval1->month * INT64CONST(DAYS_PER_MONTH) * USECS_PER_DAY;
|
||||
span1 += interval1->day * INT64CONST(HOURS_PER_DAY) * USECS_PER_HOUR;
|
||||
span2 += interval2->month * INT64CONST(DAYS_PER_MONTH) * USECS_PER_DAY;
|
||||
span2 += interval2->day * INT64CONST(HOURS_PER_DAY) * USECS_PER_HOUR;
|
||||
#else
|
||||
span1 += interval1->month * (30.0 * SECS_PER_DAY);
|
||||
span1 += interval1->day * (24.0 * SECS_PER_HOUR);
|
||||
span2 += interval2->month * (30.0 * SECS_PER_DAY);
|
||||
span2 += interval2->day * (24.0 * SECS_PER_HOUR);
|
||||
span1 += interval1->month * ((double)DAYS_PER_MONTH * SECS_PER_DAY);
|
||||
span1 += interval1->day * ((double)HOURS_PER_DAY * SECS_PER_HOUR);
|
||||
span2 += interval2->month * ((double)DAYS_PER_MONTH * SECS_PER_DAY);
|
||||
span2 += interval2->day * ((double)HOURS_PER_DAY * SECS_PER_HOUR);
|
||||
#endif
|
||||
|
||||
return ((span1 < span2) ? -1 : (span1 > span2) ? 1 : 0);
|
||||
|
@ -1940,12 +1940,12 @@ interval_justify_days(PG_FUNCTION_ARGS)
|
|||
result->time = span->time;
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
result->day += span->month * 30.0;
|
||||
result->month = span->day / 30;
|
||||
result->day -= result->month * 30;
|
||||
result->day += span->month * (double)DAYS_PER_MONTH;
|
||||
result->month = span->day / DAYS_PER_MONTH;
|
||||
result->day -= result->month * DAYS_PER_MONTH;
|
||||
#else
|
||||
result->day += span->month * 30.0;
|
||||
TMODULO(result->day, result->month, 30.0);
|
||||
result->day += span->month * (double)DAYS_PER_MONTH;
|
||||
TMODULO(result->day, result->month, (double)DAYS_PER_MONTH);
|
||||
#endif
|
||||
|
||||
PG_RETURN_INTERVAL_P(result);
|
||||
|
@ -1984,15 +1984,15 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
|
|||
errmsg("timestamp out of range")));
|
||||
|
||||
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_mon = ((tm->tm_mon - 1) % 12) + 1;
|
||||
tm->tm_year += (tm->tm_mon - 1) / MONTHS_PER_YEAR;
|
||||
tm->tm_mon = ((tm->tm_mon - 1) % MONTHS_PER_YEAR) + 1;
|
||||
}
|
||||
else if (tm->tm_mon < 1)
|
||||
{
|
||||
tm->tm_year += tm->tm_mon / 12 - 1;
|
||||
tm->tm_mon = tm->tm_mon % 12 + 12;
|
||||
tm->tm_year += tm->tm_mon / MONTHS_PER_YEAR - 1;
|
||||
tm->tm_mon = tm->tm_mon % MONTHS_PER_YEAR + MONTHS_PER_YEAR;
|
||||
}
|
||||
|
||||
/* adjust for end of month boundary problems... */
|
||||
|
@ -2085,15 +2085,15 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
|
|||
errmsg("timestamp out of range")));
|
||||
|
||||
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_mon = ((tm->tm_mon - 1) % 12) + 1;
|
||||
tm->tm_year += (tm->tm_mon - 1) / MONTHS_PER_YEAR;
|
||||
tm->tm_mon = ((tm->tm_mon - 1) % MONTHS_PER_YEAR) + 1;
|
||||
}
|
||||
else if (tm->tm_mon < 1)
|
||||
{
|
||||
tm->tm_year += tm->tm_mon / 12 - 1;
|
||||
tm->tm_mon = tm->tm_mon % 12 + 12;
|
||||
tm->tm_year += tm->tm_mon / MONTHS_PER_YEAR - 1;
|
||||
tm->tm_mon = tm->tm_mon % MONTHS_PER_YEAR + MONTHS_PER_YEAR;
|
||||
}
|
||||
|
||||
/* adjust for end of month boundary problems... */
|
||||
|
@ -2264,16 +2264,16 @@ interval_mul(PG_FUNCTION_ARGS)
|
|||
result->month = months;
|
||||
result->day = days;
|
||||
result->time = (span1->time * factor);
|
||||
result->time += (months - result->month) * INT64CONST(30) * USECS_PER_DAY;
|
||||
result->time += (days - result->day) * INT64CONST(24) * USECS_PER_HOUR;
|
||||
result->time += (months - result->month) * INT64CONST(DAYS_PER_MONTH) * USECS_PER_DAY;
|
||||
result->time += (days - result->day) * INT64CONST(HOURS_PER_DAY) * USECS_PER_HOUR;
|
||||
#else
|
||||
result->month = (int)months;
|
||||
result->day = (int)days;
|
||||
result->time = JROUND(span1->time * factor);
|
||||
/* evaluate fractional months as 30 days */
|
||||
result->time += JROUND((months - result->month) * 30 * SECS_PER_DAY);
|
||||
result->time += JROUND((months - result->month) * DAYS_PER_MONTH * SECS_PER_DAY);
|
||||
/* evaluate fractional days as 24 hours */
|
||||
result->time += JROUND((days - result->day) * 24 * SECS_PER_HOUR);
|
||||
result->time += JROUND((days - result->day) * HOURS_PER_DAY * SECS_PER_HOUR);
|
||||
#endif
|
||||
|
||||
PG_RETURN_INTERVAL_P(result);
|
||||
|
@ -2314,9 +2314,9 @@ interval_div(PG_FUNCTION_ARGS)
|
|||
|
||||
/* Cascade fractions to lower units */
|
||||
/* fractional months full days into days */
|
||||
result->day += month_remainder * 30;
|
||||
result->day += month_remainder * DAYS_PER_MONTH;
|
||||
/* fractional months partial days into time */
|
||||
day_remainder += (month_remainder * 30) - (int)(month_remainder * 30);
|
||||
day_remainder += (month_remainder * DAYS_PER_MONTH) - (int)(month_remainder * DAYS_PER_MONTH);
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
result->time += day_remainder * USECS_PER_DAY;
|
||||
|
@ -2469,19 +2469,19 @@ timestamp_age(PG_FUNCTION_ARGS)
|
|||
|
||||
while (tm->tm_sec < 0)
|
||||
{
|
||||
tm->tm_sec += 60;
|
||||
tm->tm_sec += SECS_PER_MINUTE;
|
||||
tm->tm_min--;
|
||||
}
|
||||
|
||||
while (tm->tm_min < 0)
|
||||
{
|
||||
tm->tm_min += 60;
|
||||
tm->tm_min += SECS_PER_MINUTE;
|
||||
tm->tm_hour--;
|
||||
}
|
||||
|
||||
while (tm->tm_hour < 0)
|
||||
{
|
||||
tm->tm_hour += 24;
|
||||
tm->tm_hour += HOURS_PER_DAY;
|
||||
tm->tm_mday--;
|
||||
}
|
||||
|
||||
|
@ -2501,7 +2501,7 @@ timestamp_age(PG_FUNCTION_ARGS)
|
|||
|
||||
while (tm->tm_mon < 0)
|
||||
{
|
||||
tm->tm_mon += 12;
|
||||
tm->tm_mon += MONTHS_PER_YEAR;
|
||||
tm->tm_year--;
|
||||
}
|
||||
|
||||
|
@ -2583,19 +2583,19 @@ timestamptz_age(PG_FUNCTION_ARGS)
|
|||
|
||||
while (tm->tm_sec < 0)
|
||||
{
|
||||
tm->tm_sec += 60;
|
||||
tm->tm_sec += SECS_PER_MINUTE;
|
||||
tm->tm_min--;
|
||||
}
|
||||
|
||||
while (tm->tm_min < 0)
|
||||
{
|
||||
tm->tm_min += 60;
|
||||
tm->tm_min += SECS_PER_MINUTE;
|
||||
tm->tm_hour--;
|
||||
}
|
||||
|
||||
while (tm->tm_hour < 0)
|
||||
{
|
||||
tm->tm_hour += 24;
|
||||
tm->tm_hour += HOURS_PER_DAY;
|
||||
tm->tm_mday--;
|
||||
}
|
||||
|
||||
|
@ -2615,7 +2615,7 @@ timestamptz_age(PG_FUNCTION_ARGS)
|
|||
|
||||
while (tm->tm_mon < 0)
|
||||
{
|
||||
tm->tm_mon += 12;
|
||||
tm->tm_mon += MONTHS_PER_YEAR;
|
||||
tm->tm_year--;
|
||||
}
|
||||
|
||||
|
@ -2881,7 +2881,7 @@ timestamp_trunc(PG_FUNCTION_ARGS)
|
|||
*/
|
||||
if (woy >= 52 && tm->tm_mon == 1)
|
||||
--tm->tm_year;
|
||||
if (woy <= 1 && tm->tm_mon == 12)
|
||||
if (woy <= 1 && tm->tm_mon == MONTHS_PER_YEAR)
|
||||
++tm->tm_year;
|
||||
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
|
||||
tm->tm_hour = 0;
|
||||
|
@ -3015,7 +3015,7 @@ timestamptz_trunc(PG_FUNCTION_ARGS)
|
|||
*/
|
||||
if (woy >= 52 && tm->tm_mon == 1)
|
||||
--tm->tm_year;
|
||||
if (woy <= 1 && tm->tm_mon == 12)
|
||||
if (woy <= 1 && tm->tm_mon == MONTHS_PER_YEAR)
|
||||
++tm->tm_year;
|
||||
isoweek2date(woy, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
|
||||
tm->tm_hour = 0;
|
||||
|
@ -3492,10 +3492,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 * 60) + tm->tm_min) * 60) +
|
||||
result += ((((tm->tm_hour * SECS_PER_MINUTE) + tm->tm_min) * SECS_PER_MINUTE) +
|
||||
tm->tm_sec + (fsec / 1000000.0)) / (double)SECS_PER_DAY;
|
||||
#else
|
||||
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
|
||||
result += ((((tm->tm_hour * SECS_PER_MINUTE) + tm->tm_min) * SECS_PER_MINUTE) +
|
||||
tm->tm_sec + fsec) / (double)SECS_PER_DAY;
|
||||
#endif
|
||||
break;
|
||||
|
@ -3628,13 +3628,13 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
|||
|
||||
case DTK_TZ_MINUTE:
|
||||
result = -tz;
|
||||
result /= 60;
|
||||
FMODULO(result, dummy, 60.0);
|
||||
result /= SECS_PER_MINUTE;
|
||||
FMODULO(result, dummy, (double)SECS_PER_MINUTE);
|
||||
break;
|
||||
|
||||
case DTK_TZ_HOUR:
|
||||
dummy = -tz;
|
||||
FMODULO(dummy, result, 3600.0);
|
||||
FMODULO(dummy, result, (double)SECS_PER_HOUR);
|
||||
break;
|
||||
|
||||
case DTK_MICROSEC:
|
||||
|
@ -3720,10 +3720,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 * 60) + tm->tm_min) * 60) +
|
||||
result += ((((tm->tm_hour * SECS_PER_MINUTE) + tm->tm_min) * SECS_PER_MINUTE) +
|
||||
tm->tm_sec + (fsec / 1000000.0)) / (double)SECS_PER_DAY;
|
||||
#else
|
||||
result += ((((tm->tm_hour * 60) + tm->tm_min) * 60) +
|
||||
result += ((((tm->tm_hour * SECS_PER_MINUTE) + tm->tm_min) * SECS_PER_MINUTE) +
|
||||
tm->tm_sec + fsec) / (double)SECS_PER_DAY;
|
||||
#endif
|
||||
break;
|
||||
|
@ -3904,8 +3904,8 @@ interval_part(PG_FUNCTION_ARGS)
|
|||
#else
|
||||
result = interval->time;
|
||||
#endif
|
||||
result += (365.25 * SECS_PER_DAY) * (interval->month / 12);
|
||||
result += (30.0 * SECS_PER_DAY) * (interval->month % 12);
|
||||
result += (DAYS_PER_YEAR * SECS_PER_DAY) * (interval->month / MONTHS_PER_YEAR);
|
||||
result += ((double)DAYS_PER_MONTH * SECS_PER_DAY) * (interval->month % MONTHS_PER_YEAR);
|
||||
result += interval->day * SECS_PER_DAY;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
*
|
||||
* 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[] =
|
|||
NULL
|
||||
},
|
||||
&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 @@
|
|||
* 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.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
|
|||
#define MAX_TIMESTAMP_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_HOUR 3600
|
||||
#define SECS_PER_MINUTE 60
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
#define USECS_PER_DAY INT64CONST(86400000000)
|
||||
#define USECS_PER_HOUR INT64CONST(3600000000)
|
||||
|
|
|
@ -678,7 +678,7 @@ PGTYPESdate_defmt_asc(date *d, char *fmt, char *str)
|
|||
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;
|
||||
return -1;
|
||||
|
|
|
@ -216,7 +216,17 @@ do { \
|
|||
} while(0)
|
||||
#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_HOUR 3600
|
||||
#define SECS_PER_MINUTE 60
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
#define USECS_PER_DAY INT64CONST(86400000000)
|
||||
#define USECS_PER_HOUR INT64CONST(3600000000)
|
||||
|
|
|
@ -688,7 +688,7 @@ DecodeSpecial(int field, char *lowtoken, int *val)
|
|||
int
|
||||
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;
|
||||
|
||||
switch (style)
|
||||
|
@ -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)
|
||||
{
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min);
|
||||
}
|
||||
break;
|
||||
|
@ -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);
|
||||
else
|
||||
{
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
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
|
|||
sprintf(str + strlen(str), " %.*s", MAXTZLEN, *tzn);
|
||||
else
|
||||
{
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
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
|
|||
* rejected by the date/time parser later. - thomas
|
||||
* 2001-10-19
|
||||
*/
|
||||
hour = -(*tzp / 3600);
|
||||
min = (abs(*tzp) / 60) % 60;
|
||||
hour = -(*tzp / SECS_PER_HOUR);
|
||||
min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE;
|
||||
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)
|
|||
#elif defined(HAVE_INT_TIMEZONE)
|
||||
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)
|
||||
{
|
||||
|
@ -1138,7 +1138,7 @@ DetermineLocalTimeZone(struct tm * tm)
|
|||
/* tm_gmtoff is Sun/DEC-ism */
|
||||
tz = -(tmp->tm_gmtoff);
|
||||
#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 */
|
||||
}
|
||||
else
|
||||
|
@ -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 * 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;
|
||||
|
||||
/*
|
||||
|
@ -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 * 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
|
||||
|
@ -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 * 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;
|
||||
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 * 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;
|
||||
}
|
||||
tm->tm_isdst = tmp->tm_isdst;
|
||||
|
@ -1250,10 +1250,10 @@ dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
|
|||
*sec = time / USECS_PER_SEC;
|
||||
*fsec = time - (*sec * USECS_PER_SEC);
|
||||
#else
|
||||
*hour = time / 3600;
|
||||
time -= (*hour) * 3600;
|
||||
*min = time / 60;
|
||||
time -= (*min) * 60;
|
||||
*hour = time / SECS_PER_HOUR;
|
||||
time -= (*hour) * SECS_PER_HOUR;
|
||||
*min = time / SECS_PER_MINUTE;
|
||||
time -= (*min) * SECS_PER_MINUTE;
|
||||
*sec = time;
|
||||
*fsec = JROUND(time - *sec);
|
||||
#endif
|
||||
|
@ -1437,7 +1437,7 @@ int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits, bool EuroDates)
|
|||
}
|
||||
|
||||
/* 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);
|
||||
tm->tm_mon = val;
|
||||
|
@ -1450,7 +1450,7 @@ int *tmask, struct tm * tm, fsec_t *fsec, int *is2digits, bool EuroDates)
|
|||
*tmask = DTK_M(DAY);
|
||||
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);
|
||||
tm->tm_mon = val;
|
||||
|
@ -1712,7 +1712,7 @@ DecodeTimezone(char *str, int *tzp)
|
|||
else
|
||||
min = 0;
|
||||
|
||||
tz = (hr * 60 + min) * 60;
|
||||
tz = (hr * SECS_PER_MINUTE + min) * SECS_PER_MINUTE;
|
||||
if (*str == '-')
|
||||
tz = -tz;
|
||||
|
||||
|
@ -1752,7 +1752,7 @@ DecodePosixTimezone(char *str, int *tzp)
|
|||
{
|
||||
case DTZ:
|
||||
case TZ:
|
||||
*tzp = (val * 60) - tz;
|
||||
*tzp = (val * SECS_PER_MINUTE) - 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 * 60;
|
||||
*tzp += val * SECS_PER_MINUTE;
|
||||
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 * 60;
|
||||
*tzp = val * SECS_PER_MINUTE;
|
||||
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 * 60;
|
||||
*tzp = val * SECS_PER_MINUTE;
|
||||
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 * 60 * datetktbl[j].value;
|
||||
*tz = -15 * SECS_PER_MINUTE * datetktbl[j].value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3167,7 +3167,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d,
|
|||
err = 1;
|
||||
*hour = 0;
|
||||
}
|
||||
if (*month > 12)
|
||||
if (*month > MONTHS_PER_YEAR)
|
||||
{
|
||||
err = 1;
|
||||
*month = 1;
|
||||
|
|
|
@ -254,7 +254,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec
|
|||
{
|
||||
int sec;
|
||||
|
||||
fval *= 60;
|
||||
fval *= SECS_PER_MINUTE;
|
||||
sec = fval;
|
||||
tm->tm_sec += sec;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
|
@ -272,7 +272,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec
|
|||
{
|
||||
int sec;
|
||||
|
||||
fval *= 3600;
|
||||
fval *= SECS_PER_HOUR;
|
||||
sec = fval;
|
||||
tm->tm_sec += sec;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
|
@ -326,7 +326,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec
|
|||
{
|
||||
int sec;
|
||||
|
||||
fval *= 30 * SECS_PER_DAY;
|
||||
fval *= DAYS_PER_MONTH * SECS_PER_DAY;
|
||||
sec = fval;
|
||||
tm->tm_sec += sec;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
|
@ -341,28 +341,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec
|
|||
case DTK_YEAR:
|
||||
tm->tm_year += val;
|
||||
if (fval != 0)
|
||||
tm->tm_mon += fval * 12;
|
||||
tm->tm_mon += fval * MONTHS_PER_YEAR;
|
||||
tmask = (fmask & DTK_M(YEAR)) ? 0 : DTK_M(YEAR);
|
||||
break;
|
||||
|
||||
case DTK_DECADE:
|
||||
tm->tm_year += val * 10;
|
||||
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);
|
||||
break;
|
||||
|
||||
case DTK_CENTURY:
|
||||
tm->tm_year += val * 100;
|
||||
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);
|
||||
break;
|
||||
|
||||
case DTK_MILLENNIUM:
|
||||
tm->tm_year += val * 1000;
|
||||
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);
|
||||
break;
|
||||
|
||||
|
@ -680,8 +680,8 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec)
|
|||
|
||||
if (span.month != 0)
|
||||
{
|
||||
tm->tm_year = span.month / 12;
|
||||
tm->tm_mon = span.month % 12;
|
||||
tm->tm_year = span.month / MONTHS_PER_YEAR;
|
||||
tm->tm_mon = span.month % MONTHS_PER_YEAR;
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -703,8 +703,8 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec)
|
|||
*fsec = (time - (tm->tm_sec * USECS_PER_SEC));
|
||||
#else
|
||||
TMODULO(time, tm->tm_mday, (double)SECS_PER_DAY);
|
||||
TMODULO(time, tm->tm_hour, 3600.0);
|
||||
TMODULO(time, tm->tm_min, 60.0);
|
||||
TMODULO(time, tm->tm_hour, (double)SECS_PER_HOUR);
|
||||
TMODULO(time, tm->tm_min, (double)SECS_PER_MINUTE);
|
||||
TMODULO(time, tm->tm_sec, 1.0);
|
||||
*fsec = time;
|
||||
#endif
|
||||
|
@ -715,16 +715,16 @@ interval2tm(interval span, struct tm *tm, fsec_t *fsec)
|
|||
static int
|
||||
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
|
||||
span->time = (((((((tm->tm_mday * INT64CONST(24)) +
|
||||
tm->tm_hour) * INT64CONST(60)) +
|
||||
tm->tm_min) * INT64CONST(60)) +
|
||||
span->time = (((((((tm->tm_mday * INT64CONST(HOURS_PER_DAY)) +
|
||||
tm->tm_hour) * INT64CONST(SECS_PER_MINUTE)) +
|
||||
tm->tm_min) * INT64CONST(SECS_PER_MINUTE)) +
|
||||
tm->tm_sec) * USECS_PER_SEC) + fsec;
|
||||
#else
|
||||
span->time = (((((tm->tm_mday * 24.0) +
|
||||
tm->tm_hour) * 60.0) +
|
||||
tm->tm_min) * 60.0) +
|
||||
span->time = (((((tm->tm_mday * (double)HOURS_PER_DAY) +
|
||||
tm->tm_hour) * (double)SECS_PER_MINUTE) +
|
||||
tm->tm_min) * (double)SECS_PER_MINUTE) +
|
||||
tm->tm_sec;
|
||||
span->time = JROUND(span->time + fsec);
|
||||
#endif
|
||||
|
|
|
@ -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 * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec;
|
||||
return (((((hour * SECS_PER_MINUTE) + 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 * 60) + min) * 60) + sec + fsec;
|
||||
return (((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec + fsec;
|
||||
} /* time2t() */
|
||||
#endif
|
||||
|
||||
|
@ -119,10 +119,10 @@ dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
|
|||
*sec = time / USECS_PER_SEC;
|
||||
*fsec = time - *sec * USECS_PER_SEC;
|
||||
#else
|
||||
*hour = time / 3600;
|
||||
time -= (*hour) * 3600;
|
||||
*min = time / 60;
|
||||
time -= (*min) * 60;
|
||||
*hour = time / SECS_PER_HOUR;
|
||||
time -= (*hour) * SECS_PER_HOUR;
|
||||
*min = time / SECS_PER_MINUTE;
|
||||
time -= (*min) * SECS_PER_MINUTE;
|
||||
*sec = time;
|
||||
*fsec = JROUND(time - *sec);
|
||||
#endif
|
||||
|
@ -221,7 +221,7 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
|
|||
if (tzn != NULL)
|
||||
*tzn = (char *) tm->tm_zone;
|
||||
#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)
|
||||
*tzn = TZNAME_GLOBAL[(tm->tm_isdst > 0)];
|
||||
#endif
|
||||
|
@ -875,15 +875,15 @@ PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout)
|
|||
if (timestamp2tm(*tin, NULL, tm, &fsec, NULL) !=0)
|
||||
return -1;
|
||||
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_mon = (tm->tm_mon - 1) % 12 + 1;
|
||||
tm->tm_year += (tm->tm_mon - 1) / MONTHS_PER_YEAR;
|
||||
tm->tm_mon = (tm->tm_mon - 1) % MONTHS_PER_YEAR + 1;
|
||||
}
|
||||
else if (tm->tm_mon < 1)
|
||||
{
|
||||
tm->tm_year += tm->tm_mon / 12 - 1;
|
||||
tm->tm_mon = tm->tm_mon % 12 + 12;
|
||||
tm->tm_year += tm->tm_mon / MONTHS_PER_YEAR - 1;
|
||||
tm->tm_mon = tm->tm_mon % MONTHS_PER_YEAR + MONTHS_PER_YEAR;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue