PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
compat.c File Reference
#include "postgres.h"
#include <time.h>
#include "utils/datetime.h"
Include dependency graph for compat.c:

Go to the source code of this file.

Macros

#define FRONTEND   1
 

Functions

pg_time_t timestamptz_to_time_t (TimestampTz t)
 
const char * timestamptz_to_str (TimestampTz t)
 

Macro Definition Documentation

◆ FRONTEND

#define FRONTEND   1

Definition at line 18 of file compat.c.

Function Documentation

◆ timestamptz_to_str()

const char * timestamptz_to_str ( TimestampTz  t)

Definition at line 49 of file compat.c.

50{
51 static char buf[MAXDATELEN + 1];
52 char ts[MAXDATELEN + 1];
53 char zone[MAXDATELEN + 1];
54 time_t result = (time_t) timestamptz_to_time_t(t);
55 struct tm *ltime = localtime(&result);
56
57 strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", ltime);
58 strftime(zone, sizeof(zone), "%Z", ltime);
59
60 snprintf(buf, sizeof(buf), "%s.%06d %s",
61 ts, (int) (t % USECS_PER_SEC), zone);
62
63 return buf;
64}
pg_time_t timestamptz_to_time_t(TimestampTz t)
Definition: compat.c:27
#define USECS_PER_SEC
Definition: timestamp.h:134
#define MAXDATELEN
Definition: datetime.h:200
static struct pg_tm tm
Definition: localtime.c:104
static char * buf
Definition: pg_test_fsync.c:72
#define snprintf
Definition: port.h:238
Definition: zic.c:94

References buf, MAXDATELEN, snprintf, timestamptz_to_time_t(), tm, and USECS_PER_SEC.

◆ timestamptz_to_time_t()

pg_time_t timestamptz_to_time_t ( TimestampTz  t)

Definition at line 27 of file compat.c.

28{
29 pg_time_t result;
30
31 result = (pg_time_t) (t / USECS_PER_SEC +
33 return result;
34}
#define UNIX_EPOCH_JDATE
Definition: timestamp.h:234
#define SECS_PER_DAY
Definition: timestamp.h:126
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:235
int64 pg_time_t
Definition: pgtime.h:23

References POSTGRES_EPOCH_JDATE, SECS_PER_DAY, UNIX_EPOCH_JDATE, and USECS_PER_SEC.

Referenced by timestamptz_to_str().