diff options
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r-- | src/backend/utils/adt/date.c | 11 | ||||
-rw-r--r-- | src/backend/utils/adt/datetime.c | 10 | ||||
-rw-r--r-- | src/backend/utils/adt/nabstime.c | 11 | ||||
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 22 |
4 files changed, 32 insertions, 22 deletions
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index bec5e373964..70f60c94622 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.138 2008/01/01 19:45:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.139 2008/02/17 02:09:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -945,8 +945,10 @@ tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result) /* time2tm() * Convert time data type to POSIX time structure. - * For dates within the system-supported time_t range, convert to the - * local time zone. If out of this range, leave as GMT. - tgl 97/05/27 + * + * For dates within the range of pg_time_t, convert to the local time zone. + * If out of this range, leave as UTC (in practice that could only happen + * if pg_time_t is just 32 bits) - thomas 97/05/27 */ static int time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec) @@ -2466,10 +2468,9 @@ timetz_zone(PG_FUNCTION_ARGS) if (tzp) { /* Get the offset-from-GMT that is valid today for the selected zone */ - pg_time_t now; + pg_time_t now = (pg_time_t) time(NULL); struct pg_tm *tm; - now = time(NULL); tm = pg_localtime(&now, tzp); tz = -tm->tm_gmtoff; } diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index ed411cf21af..0bfdd0ec2d6 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.184 2008/01/01 19:45:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.185 2008/02/17 02:09:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -650,9 +650,11 @@ ParseDateTime(const char *timestr, char *workbuf, size_t buflen, * "20011225T040506.789-07" * * Use the system-provided functions to get the current time zone - * if not specified in the input string. - * If the date is outside the time_t system-supported time range, - * then assume UTC time zone. - thomas 1997-05-27 + * if not specified in the input string. + * + * If the date is outside the range of pg_time_t (in practice that could only + * happen if pg_time_t is just 32 bits), then assume UTC time zone - thomas + * 1997-05-27 */ int DecodeDateTime(char **field, int *ftype, int nf, diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index a2e9fc26433..2265b7d903e 100644 --- a/src/backend/utils/adt/nabstime.c +++ b/src/backend/utils/adt/nabstime.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.152 2008/01/01 19:45:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.153 2008/02/17 02:09:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -86,6 +86,8 @@ static void parsetinterval(char *i_string, * GetCurrentAbsoluteTime() * * Get the current system time (relative to Unix epoch). + * + * NB: this will overflow in 2038; it should be gone long before that. */ AbsoluteTime GetCurrentAbsoluteTime(void) @@ -1029,12 +1031,7 @@ tintervalrel(PG_FUNCTION_ARGS) Datum timenow(PG_FUNCTION_ARGS) { - time_t sec; - - if (time(&sec) < 0) - PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); - - PG_RETURN_ABSOLUTETIME((AbsoluteTime) sec); + PG_RETURN_ABSOLUTETIME(GetCurrentAbsoluteTime()); } /* diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 1277562b794..f450922f26e 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.184 2008/01/01 19:45:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.185 2008/02/17 02:09:28 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1264,9 +1264,14 @@ TimestampDifferenceExceeds(TimestampTz start_time, * * We do not use time_t internally in Postgres, but this is provided for use * by functions that need to interpret, say, a stat(2) result. + * + * To avoid having the function's ABI vary depending on the width of time_t, + * we declare the argument as pg_time_t, which is cast-compatible with + * time_t but always 64 bits wide (unless the platform has no 64-bit type). + * This detail should be invisible to callers, at least at source code level. */ TimestampTz -time_t_to_timestamptz(time_t tm) +time_t_to_timestamptz(pg_time_t tm) { TimestampTz result; @@ -1284,17 +1289,22 @@ time_t_to_timestamptz(time_t tm) * Convert a TimestampTz to time_t. * * This too is just marginally useful, but some places need it. + * + * To avoid having the function's ABI vary depending on the width of time_t, + * we declare the result as pg_time_t, which is cast-compatible with + * time_t but always 64 bits wide (unless the platform has no 64-bit type). + * This detail should be invisible to callers, at least at source code level. */ -time_t +pg_time_t timestamptz_to_time_t(TimestampTz t) { - time_t result; + pg_time_t result; #ifdef HAVE_INT64_TIMESTAMP - result = (time_t) (t / USECS_PER_SEC + + result = (pg_time_t) (t / USECS_PER_SEC + ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)); #else - result = (time_t) (t + + result = (pg_time_t) (t + ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)); #endif |