diff options
Diffstat (limited to 'src/interfaces')
| -rw-r--r-- | src/interfaces/ecpg/pgtypeslib/dt.h | 10 | ||||
| -rw-r--r-- | src/interfaces/ecpg/pgtypeslib/dt_common.c | 28 | ||||
| -rw-r--r-- | src/interfaces/ecpg/pgtypeslib/interval.c | 2 | ||||
| -rw-r--r-- | src/interfaces/ecpg/pgtypeslib/timestamp.c | 4 |
4 files changed, 25 insertions, 19 deletions
diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h index 01b44fb27ac..008ac3b0a31 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt.h +++ b/src/interfaces/ecpg/pgtypeslib/dt.h @@ -221,16 +221,22 @@ do { \ #define MONTHS_PER_YEAR 12 /* * DAYS_PER_MONTH is very imprecise. The more accurate value is - * 365.25/12 = 30.4375, or '30 days 10:30:00'. Right now we only + * 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only * return an integral number of days, but someday perhaps we should * also return a 'time' value to be used as well. */ #define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */ #define HOURS_PER_DAY 24 /* assume no daylight savings time changes */ -#define SECS_PER_DAY 86400 /* assumes no leap second */ +/* + * This doesn't adjust for uneven daylight savings time intervals, nor + * leap seconds. + */ +#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */ +#define SECS_PER_DAY 86400 #define SECS_PER_HOUR 3600 #define SECS_PER_MINUTE 60 +#define MINS_PER_HOUR 60 #ifdef HAVE_INT64_TIMESTAMP #define USECS_PER_DAY INT64CONST(86400000000) diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c index 65a70cdc874..bc2bfd4ee7e 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt_common.c +++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c @@ -814,7 +814,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha if (tzp != NULL && tm->tm_isdst >= 0) { hour = -(*tzp / SECS_PER_HOUR); - min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; + min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR; sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); } break; @@ -862,7 +862,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha else { hour = -(*tzp / SECS_PER_HOUR); - min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; + min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR; sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); } } @@ -908,7 +908,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha else { hour = -(*tzp / SECS_PER_HOUR); - min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; + min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR; sprintf(str + strlen(str), (min != 0) ? "%+03d:%02d" : "%+03d", hour, min); } } @@ -971,7 +971,7 @@ EncodeDateTime(struct tm * tm, fsec_t fsec, int *tzp, char **tzn, int style, cha * 2001-10-19 */ hour = -(*tzp / SECS_PER_HOUR); - min = (abs(*tzp) / SECS_PER_MINUTE) % SECS_PER_MINUTE; + min = (abs(*tzp) / MINS_PER_HOUR) % MINS_PER_HOUR; sprintf(str + strlen(str), (min != 0) ? " %+03d:%02d" : " %+03d", hour, min); } } @@ -1161,7 +1161,7 @@ DetermineLocalTimeZone(struct tm * tm) day = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(1970, 1, 1)); - mysec = tm->tm_sec + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; + mysec = tm->tm_sec + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE; mytime = (time_t) mysec; /* @@ -1171,7 +1171,7 @@ DetermineLocalTimeZone(struct tm * tm) tmp = localtime(&mytime); day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) - date2j(1970, 1, 1)); - locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; + locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE; /* * The local time offset corresponding to that GMT time is now @@ -1201,7 +1201,7 @@ DetermineLocalTimeZone(struct tm * tm) tmp = localtime(&mytime); day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) - date2j(1970, 1, 1)); - locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; + locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE; delta2 = mysec - locsec; if (delta2 != delta1) { @@ -1210,7 +1210,7 @@ DetermineLocalTimeZone(struct tm * tm) tmp = localtime(&mytime); day = (date2j(tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday) - date2j(1970, 1, 1)); - locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * SECS_PER_MINUTE) * SECS_PER_MINUTE; + locsec = tmp->tm_sec + (tmp->tm_min + (day * HOURS_PER_DAY + tmp->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE; delta2 = mysec - locsec; } tm->tm_isdst = tmp->tm_isdst; @@ -1712,7 +1712,7 @@ DecodeTimezone(char *str, int *tzp) else min = 0; - tz = (hr * SECS_PER_MINUTE + min) * SECS_PER_MINUTE; + tz = (hr * MINS_PER_HOUR + min) * SECS_PER_MINUTE; if (*str == '-') tz = -tz; @@ -1752,7 +1752,7 @@ DecodePosixTimezone(char *str, int *tzp) { case DTZ: case TZ: - *tzp = (val * SECS_PER_MINUTE) - tz; + *tzp = (val * MINS_PER_HOUR) - tz; break; default: @@ -2398,7 +2398,7 @@ DecodeDateTime(char **field, int *ftype, int nf, tm->tm_isdst = 1; if (tzp == NULL) return -1; - *tzp += val * SECS_PER_MINUTE; + *tzp += val * MINS_PER_HOUR; break; case DTZ: @@ -2411,7 +2411,7 @@ DecodeDateTime(char **field, int *ftype, int nf, tm->tm_isdst = 1; if (tzp == NULL) return -1; - *tzp = val * SECS_PER_MINUTE; + *tzp = val * MINS_PER_HOUR; ftype[i] = DTK_TZ; break; @@ -2419,7 +2419,7 @@ DecodeDateTime(char **field, int *ftype, int nf, tm->tm_isdst = 0; if (tzp == NULL) return -1; - *tzp = val * SECS_PER_MINUTE; + *tzp = val * MINS_PER_HOUR; ftype[i] = DTK_TZ; break; @@ -3108,7 +3108,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d, * timezone value of the datetktbl table is in * quarter hours */ - *tz = -15 * SECS_PER_MINUTE * datetktbl[j].value; + *tz = -15 * MINS_PER_HOUR * datetktbl[j].value; break; } } diff --git a/src/interfaces/ecpg/pgtypeslib/interval.c b/src/interfaces/ecpg/pgtypeslib/interval.c index 3fa176be84e..6c3af18eced 100644 --- a/src/interfaces/ecpg/pgtypeslib/interval.c +++ b/src/interfaces/ecpg/pgtypeslib/interval.c @@ -723,7 +723,7 @@ tm2interval(struct tm *tm, fsec_t fsec, interval *span) tm->tm_sec) * USECS_PER_SEC) + fsec; #else span->time = (((((tm->tm_mday * (double)HOURS_PER_DAY) + - tm->tm_hour) * (double)SECS_PER_MINUTE) + + tm->tm_hour) * (double)MINS_PER_HOUR) + tm->tm_min) * (double)SECS_PER_MINUTE) + tm->tm_sec; span->time = JROUND(span->time + fsec); diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c index 5382022d71a..5f9ec2f2f93 100644 --- a/src/interfaces/ecpg/pgtypeslib/timestamp.c +++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c @@ -20,14 +20,14 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int static int64 time2t(const int hour, const int min, const int sec, const fsec_t fsec) { - return (((((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec; + return (((((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec) * USECS_PER_SEC) + fsec; } /* time2t() */ #else static double time2t(const int hour, const int min, const int sec, const fsec_t fsec) { - return (((hour * SECS_PER_MINUTE) + min) * SECS_PER_MINUTE) + sec + fsec; + return (((hour * MINS_PER_HOUR) + min) * SECS_PER_MINUTE) + sec + fsec; } /* time2t() */ #endif |
