2013-02-22 20:46:24 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* compat.c
|
|
|
|
* Reimplementations of various backend functions.
|
|
|
|
*
|
2019-01-02 18:44:25 +01:00
|
|
|
* Portions Copyright (c) 2013-2019, PostgreSQL Global Development Group
|
2013-02-22 20:46:24 +01:00
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2017-02-09 22:23:46 +01:00
|
|
|
* src/bin/pg_waldump/compat.c
|
2013-02-22 20:46:24 +01:00
|
|
|
*
|
|
|
|
* This file contains client-side implementations for various backend
|
|
|
|
* functions that the rm_desc functions in *desc.c files rely on.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ugly hack, same as in e.g pg_controldata */
|
|
|
|
#define FRONTEND 1
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
2019-10-23 06:08:53 +02:00
|
|
|
#include "utils/datetime.h"
|
2013-02-22 20:46:24 +01:00
|
|
|
|
|
|
|
/* copied from timestamp.c */
|
|
|
|
pg_time_t
|
|
|
|
timestamptz_to_time_t(TimestampTz t)
|
|
|
|
{
|
|
|
|
pg_time_t result;
|
|
|
|
|
|
|
|
result = (pg_time_t) (t / USECS_PER_SEC +
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
|
2013-02-22 20:46:24 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stopgap implementation of timestamptz_to_str that doesn't depend on backend
|
2014-05-06 18:12:18 +02:00
|
|
|
* infrastructure. This will work for timestamps that are within the range
|
2013-02-26 21:50:22 +01:00
|
|
|
* 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.
|
2013-02-22 20:46:24 +01:00
|
|
|
*
|
|
|
|
* XXX: The backend timestamp infrastructure should instead be split out and
|
2013-02-26 21:50:22 +01:00
|
|
|
* moved into src/common. That's a large project though.
|
2013-02-22 20:46:24 +01:00
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
timestamptz_to_str(TimestampTz dt)
|
|
|
|
{
|
|
|
|
static char buf[MAXDATELEN + 1];
|
2013-02-26 21:50:22 +01:00
|
|
|
char ts[MAXDATELEN + 1];
|
|
|
|
char zone[MAXDATELEN + 1];
|
|
|
|
time_t result = (time_t) timestamptz_to_time_t(dt);
|
2013-02-22 20:46:24 +01:00
|
|
|
struct tm *ltime = localtime(&result);
|
|
|
|
|
2013-02-26 21:50:22 +01:00
|
|
|
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", ltime);
|
2013-02-22 20:46:24 +01:00
|
|
|
strftime(zone, sizeof(zone), "%Z", ltime);
|
|
|
|
|
2018-06-16 20:45:47 +02:00
|
|
|
snprintf(buf, sizeof(buf), "%s.%06d %s",
|
|
|
|
ts, (int) (dt % USECS_PER_SEC), zone);
|
2013-02-22 20:46:24 +01:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|