PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
compat.c File Reference
#include "postgres.h"
#include <time.h>
#include "utils/datetime.h"
#include "lib/stringinfo.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)
 
void appendStringInfo (StringInfo str, const char *fmt,...)
 
void appendStringInfoString (StringInfo str, const char *string)
 
void appendStringInfoChar (StringInfo str, char ch)
 

Macro Definition Documentation

#define FRONTEND   1

Definition at line 18 of file compat.c.

Function Documentation

void appendStringInfo ( StringInfo  str,
const char *  fmt,
  ... 
)

Definition at line 71 of file compat.c.

References generate_unaccent_rules::args.

Referenced by appendStringInfoChar(), and appendStringInfoString().

72 {
73  va_list args;
74 
75  va_start(args, fmt);
76  vprintf(fmt, args);
77  va_end(args);
78 }
void appendStringInfoChar ( StringInfo  str,
char  ch 
)

Definition at line 87 of file compat.c.

References appendStringInfo(), StringInfoData::data, enlargeStringInfo(), StringInfoData::len, and StringInfoData::maxlen.

88 {
89  appendStringInfo(str, "%c", ch);
90 }
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: compat.c:71
void appendStringInfoString ( StringInfo  str,
const char *  string 
)

Definition at line 81 of file compat.c.

References appendBinaryStringInfo(), and appendStringInfo().

82 {
83  appendStringInfo(str, "%s", string);
84 }
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: compat.c:71
const char* timestamptz_to_str ( TimestampTz  dt)

Definition at line 50 of file compat.c.

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

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

Definition at line 28 of file compat.c.

References POSTGRES_EPOCH_JDATE, SECS_PER_DAY, UNIX_EPOCH_JDATE, and USECS_PER_SEC.

Referenced by timestamptz_to_str().

29 {
30  pg_time_t result;
31 
32  result = (pg_time_t) (t / USECS_PER_SEC +
34  return result;
35 }
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