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/datetime.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/datetime.c')
-rw-r--r-- | src/backend/utils/adt/datetime.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 260c8abb341..6ac81b2fa56 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.150 2005/05/27 21:31:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.151 2005/06/29 22:51:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -20,6 +20,7 @@ #include <limits.h> #include <math.h> +#include "access/xact.h" #include "miscadmin.h" #include "utils/datetime.h" #include "utils/guc.h" @@ -674,6 +675,41 @@ j2day(int date) } /* j2day() */ +/* + * GetCurrentDateTime() + * + * Get the transaction start time ("now()") broken down as a struct pg_tm. + */ +void +GetCurrentDateTime(struct pg_tm * tm) +{ + int tz; + fsec_t fsec; + + timestamp2tm(GetCurrentTransactionStartTimestamp(), &tz, tm, &fsec, + NULL, NULL); + /* Note: don't pass NULL tzp to timestamp2tm; affects behavior */ +} + +/* + * 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; + + timestamp2tm(GetCurrentTransactionStartTimestamp(), &tz, tm, fsec, + NULL, NULL); + /* Note: don't pass NULL tzp to timestamp2tm; affects behavior */ + if (tzp != NULL) + *tzp = tz; +} + + /* TrimTrailingZeros() * ... resulting from printing numbers with full precision. */ |