mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-03 16:46:57 +02:00
Clean up "stopgap" implementation of timestamptz_to_str().
Use correct type for "result", fix bogus strftime argument, don't use unnecessary static variables, improve comments. Andres Freund and Tom Lane
This commit is contained in:
parent
c153530dc1
commit
1418e6e07b
@ -41,21 +41,26 @@ timestamptz_to_time_t(TimestampTz t)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Stopgap implementation of timestamptz_to_str that doesn't depend on backend
|
* Stopgap implementation of timestamptz_to_str that doesn't depend on backend
|
||||||
* infrastructure.
|
* infrastructure. This will work for timestamps that are within the range
|
||||||
|
* of the platform time_t type. (pg_time_t is compatible except for possibly
|
||||||
|
* being wider.)
|
||||||
|
*
|
||||||
|
* XXX the return value points to a static buffer, so beware of using more
|
||||||
|
* than one result value concurrently.
|
||||||
*
|
*
|
||||||
* XXX: The backend timestamp infrastructure should instead be split out and
|
* XXX: The backend timestamp infrastructure should instead be split out and
|
||||||
* moved into src/common.
|
* moved into src/common. That's a large project though.
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
timestamptz_to_str(TimestampTz dt)
|
timestamptz_to_str(TimestampTz dt)
|
||||||
{
|
{
|
||||||
static char buf[MAXDATELEN + 1];
|
static char buf[MAXDATELEN + 1];
|
||||||
static char ts[MAXDATELEN + 1];
|
char ts[MAXDATELEN + 1];
|
||||||
static char zone[MAXDATELEN + 1];
|
char zone[MAXDATELEN + 1];
|
||||||
pg_time_t result = timestamptz_to_time_t(dt);
|
time_t result = (time_t) timestamptz_to_time_t(dt);
|
||||||
struct tm *ltime = localtime(&result);
|
struct tm *ltime = localtime(&result);
|
||||||
|
|
||||||
strftime(ts, sizeof(zone), "%Y-%m-%d %H:%M:%S", ltime);
|
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", ltime);
|
||||||
strftime(zone, sizeof(zone), "%Z", ltime);
|
strftime(zone, sizeof(zone), "%Z", ltime);
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
|
Loading…
Reference in New Issue
Block a user