PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pgtime.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pgtime.h
4 * PostgreSQL internal timezone library
5 *
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 *
8 * IDENTIFICATION
9 * src/include/pgtime.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef _PGTIME_H
14#define _PGTIME_H
15
16
17/*
18 * The API of this library is generally similar to the corresponding
19 * C library functions, except that we use pg_time_t which (we hope) is
20 * 64 bits wide, and which is most definitely signed not unsigned.
21 */
22
24
25/*
26 * Data structure representing a broken-down timestamp.
27 *
28 * CAUTION: the IANA timezone library (src/timezone/) follows the POSIX
29 * convention that tm_mon counts from 0 and tm_year is relative to 1900.
30 * However, Postgres' datetime functions generally treat tm_mon as counting
31 * from 1 and tm_year as relative to 1 BC. Be sure to make the appropriate
32 * adjustments when moving from one code domain to the other.
33 */
34struct pg_tm
35{
36 int tm_sec;
37 int tm_min;
40 int tm_mon; /* see above */
41 int tm_year; /* see above */
45 long int tm_gmtoff;
46 const char *tm_zone;
47};
48
49/* These structs are opaque outside the timezone library */
50typedef struct pg_tz pg_tz;
51typedef struct pg_tzenum pg_tzenum;
52
53/* Maximum length of a timezone name (not including trailing null) */
54#define TZ_STRLEN_MAX 255
55
56/* these functions are in localtime.c */
57
58extern struct pg_tm *pg_localtime(const pg_time_t *timep, const pg_tz *tz);
59extern struct pg_tm *pg_gmtime(const pg_time_t *timep);
60extern int pg_next_dst_boundary(const pg_time_t *timep,
61 long int *before_gmtoff,
62 int *before_isdst,
63 pg_time_t *boundary,
64 long int *after_gmtoff,
65 int *after_isdst,
66 const pg_tz *tz);
67extern bool pg_interpret_timezone_abbrev(const char *abbrev,
68 const pg_time_t *timep,
69 long int *gmtoff,
70 int *isdst,
71 const pg_tz *tz);
72extern bool pg_get_timezone_offset(const pg_tz *tz, long int *gmtoff);
73extern const char *pg_get_timezone_name(pg_tz *tz);
74extern bool pg_tz_acceptable(pg_tz *tz);
75
76/* these functions are in strftime.c */
77
78extern size_t pg_strftime(char *s, size_t maxsize, const char *format,
79 const struct pg_tm *t);
80
81/* these functions and variables are in pgtz.c */
82
85
86extern void pg_timezone_initialize(void);
87extern pg_tz *pg_tzset(const char *tzname);
88extern pg_tz *pg_tzset_offset(long gmtoffset);
89
92extern void pg_tzenumerate_end(pg_tzenum *dir);
93
94#endif /* _PGTIME_H */
#define PGDLLIMPORT
Definition: c.h:1274
int64_t int64
Definition: c.h:482
static char format
pg_tz * pg_tzset_offset(long gmtoffset)
Definition: pgtz.c:320
pg_tz * pg_tzenumerate_next(pg_tzenum *dir)
Definition: pgtz.c:426
bool pg_tz_acceptable(pg_tz *tz)
Definition: localtime.c:1890
int pg_next_dst_boundary(const pg_time_t *timep, long int *before_gmtoff, int *before_isdst, pg_time_t *boundary, long int *after_gmtoff, int *after_isdst, const pg_tz *tz)
Definition: localtime.c:1610
const char * pg_get_timezone_name(pg_tz *tz)
Definition: localtime.c:1875
void pg_timezone_initialize(void)
Definition: pgtz.c:361
pg_tz * pg_tzset(const char *tzname)
Definition: pgtz.c:234
bool pg_get_timezone_offset(const pg_tz *tz, long int *gmtoff)
Definition: localtime.c:1851
PGDLLIMPORT pg_tz * session_timezone
Definition: pgtz.c:28
int64 pg_time_t
Definition: pgtime.h:23
void pg_tzenumerate_end(pg_tzenum *dir)
Definition: pgtz.c:414
size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm *t)
Definition: strftime.c:128
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition: localtime.c:1344
PGDLLIMPORT pg_tz * log_timezone
Definition: pgtz.c:31
pg_tzenum * pg_tzenumerate_start(void)
Definition: pgtz.c:397
struct pg_tm * pg_gmtime(const pg_time_t *timep)
Definition: localtime.c:1389
bool pg_interpret_timezone_abbrev(const char *abbrev, const pg_time_t *timep, long int *gmtoff, int *isdst, const pg_tz *tz)
Definition: localtime.c:1757
Definition: pgtime.h:35
int tm_hour
Definition: pgtime.h:38
int tm_mday
Definition: pgtime.h:39
int tm_mon
Definition: pgtime.h:40
int tm_min
Definition: pgtime.h:37
const char * tm_zone
Definition: pgtime.h:46
int tm_yday
Definition: pgtime.h:43
int tm_wday
Definition: pgtime.h:42
int tm_sec
Definition: pgtime.h:36
int tm_isdst
Definition: pgtime.h:44
long int tm_gmtoff
Definition: pgtime.h:45
int tm_year
Definition: pgtime.h:41
Definition: pgtz.h:66