mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
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.
This commit is contained in:
@ -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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user