diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-29 22:51:57 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-29 22:51:57 +0000 |
commit | b5f7cff84f57a189ed5c9dd59efe8d2568649d0d (patch) | |
tree | 77b5a25a7c4a62145ba89a578018121b3246b82d /src/backend/utils/adt/nabstime.c | |
parent | c33d575899593a46a5b9a76e4e0ef6f9d81e55dd (diff) | |
download | postgresql-b5f7cff84f57a189ed5c9dd59efe8d2568649d0d.tar.gz postgresql-b5f7cff84f57a189ed5c9dd59efe8d2568649d0d.zip |
Clean up the rather historically encumbered interface to now() and
current time: provide a GetCurrentTimestamp() function that returns
current time in the form of a TimestampTz, instead of separate time_t
and microseconds fields. This is what all the callers really want
anyway, and it eliminates low-level dependencies on AbsoluteTime,
which is a deprecated datatype that will have to disappear eventually.
Diffstat (limited to 'src/backend/utils/adt/nabstime.c')
-rw-r--r-- | src/backend/utils/adt/nabstime.c | 91 |
1 files changed, 2 insertions, 89 deletions
diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index d712d9f8b46..dfbb982521f 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.133 2005/06/15 00:34:08 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.134 2005/06/29 22:51:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -27,7 +27,7 @@ #include "miscadmin.h" #include "pgtime.h" #include "utils/builtins.h" -#include "utils/timestamp.h" +#include "utils/nabstime.h" #define MIN_DAYNUM -24856 /* December 13, 1901 */ #define MAX_DAYNUM 24854 /* January 18, 2038 */ @@ -99,84 +99,6 @@ GetCurrentAbsoluteTime(void) } -/* - * GetCurrentAbsoluteTimeUsec() - * - * Get the current system time (relative to Unix epoch), including fractional - * seconds expressed as microseconds. - */ -AbsoluteTime -GetCurrentAbsoluteTimeUsec(int *usec) -{ - time_t now; - struct timeval tp; - - gettimeofday(&tp, NULL); - now = tp.tv_sec; - *usec = tp.tv_usec; - return (AbsoluteTime) now; -} - - -/* - * AbsoluteTimeUsecToTimestampTz() - * - * Convert system time including microseconds to TimestampTz representation. - */ -TimestampTz -AbsoluteTimeUsecToTimestampTz(AbsoluteTime sec, int usec) -{ - TimestampTz result; - -#ifdef HAVE_INT64_TIMESTAMP - result = ((sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)) - * USECS_PER_SEC) + usec; -#else - result = sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY) - + (usec / 1000000.0); -#endif - - return result; -} - - -/* - * GetCurrentDateTime() - * - * Get the transaction start time ("now()") broken down as a struct pg_tm. - */ -void -GetCurrentDateTime(struct pg_tm * tm) -{ - int tz; - - abstime2tm(GetCurrentTransactionStartTime(), &tz, tm, NULL); -} - -/* - * GetCurrentTimeUsec() - * - * Get the transaction start time ("now()") broken down as a struct pg_tm, - * including fractional seconds and timezone offset. - */ -void -GetCurrentTimeUsec(struct pg_tm * tm, fsec_t *fsec, int *tzp) -{ - int tz; - int usec; - - abstime2tm(GetCurrentTransactionStartTimeUsec(&usec), &tz, tm, NULL); - /* Note: don't pass NULL tzp to abstime2tm; affects behavior */ - if (tzp != NULL) - *tzp = tz; -#ifdef HAVE_INT64_TIMESTAMP - *fsec = usec; -#else - *fsec = usec / 1000000.0; -#endif -} - - void abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn) { @@ -458,15 +380,6 @@ abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b) if (b == INVALID_ABSTIME) return -1; /* non-INVALID < INVALID */ -#if 0 - /* CURRENT is no longer stored internally... */ - /* XXX this is broken, should go away: */ - if (a == CURRENT_ABSTIME) - a = GetCurrentTransactionStartTime(); - if (b == CURRENT_ABSTIME) - b = GetCurrentTransactionStartTime(); -#endif - if (a > b) return 1; else if (a == b) |