PostgreSQL Source Code  git master
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 dt)
 

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  dt)

Definition at line 49 of file compat.c.

References buf, EncodeDateTime(), EncodeSpecialTimestamp(), MAXDATELEN, snprintf, strlcpy(), timestamp2tm(), TIMESTAMP_NOT_FINITE, timestamptz_to_time_t(), tm, USE_ISO_DATES, and USECS_PER_SEC.

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(dt);
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) (dt % USECS_PER_SEC), zone);
62 
63  return buf;
64 }
#define MAXDATELEN
Definition: datetime.h:201
#define USECS_PER_SEC
Definition: timestamp.h:94
static struct pg_tm tm
Definition: localtime.c:108
static char * buf
Definition: pg_test_fsync.c:67
Definition: zic.c:98
pg_time_t timestamptz_to_time_t(TimestampTz t)
Definition: compat.c:27
#define snprintf
Definition: port.h:192

◆ timestamptz_to_time_t()

pg_time_t timestamptz_to_time_t ( TimestampTz  t)

Definition at line 27 of file compat.c.

References POSTGRES_EPOCH_JDATE, SECS_PER_DAY, UNIX_EPOCH_JDATE, and USECS_PER_SEC.

Referenced by timestamptz_to_str().

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