PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgtz.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pgtz.h
4 * Timezone Library Integration Functions
5 *
6 * Note: this file contains only definitions that are private to the
7 * timezone library. Public definitions are in pgtime.h.
8 *
9 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
10 *
11 * IDENTIFICATION
12 * src/timezone/pgtz.h
13 *
14 *-------------------------------------------------------------------------
15 */
16#ifndef _PGTZ_H
17#define _PGTZ_H
18
19#include "pgtime.h"
20#include "tzfile.h"
21
22/*
23 * Support leap seconds in TZ files.
24 * Maybe we should disable this?
25 */
26#define TZ_RUNTIME_LEAPS 1
27
28/*
29 * Limit to time zone abbreviation length in proleptic TZ strings.
30 * This is distinct from TZ_MAX_CHARS, which limits TZif file contents.
31 * It defaults to 254, not 255, so that desigidx_type can be an unsigned char.
32 * unsigned char suffices for TZif files, so the only reason to increase
33 * TZNAME_MAXIMUM is to support TZ strings specifying abbreviations
34 * longer than 254 bytes. There is little reason to do that, though,
35 * as strings that long are hardly "abbreviations".
36 */
37#define TZNAME_MAXIMUM 254
38
39typedef unsigned char desigidx_type;
40
41/*
42 * A type that can represent any 32-bit two's complement integer,
43 * i.e., any integer in the range -2**31 .. 2**31 - 1.
44 */
46
47struct ttinfo
48{ /* time type information */
49 int_least32_t tt_utoff; /* UT offset in seconds; in the range -2**31 +
50 * 1 .. 2**31 - 1 */
51 desigidx_type tt_desigidx; /* abbreviation list index */
52 bool tt_isdst; /* used to set tm_isdst */
53 bool tt_ttisstd; /* transition is std time */
54 bool tt_ttisut; /* transition is UT */
55};
56
57struct lsinfo
58{ /* leap second information */
59 pg_time_t ls_trans; /* transition time (positive) */
60 int_fast32_2s ls_corr; /* correction to apply */
61};
62
63/* This abbreviation means local time is unspecified. */
64static char const UNSPEC[] = "-00";
65
66/*
67 * How many extra bytes are needed at the end of struct state's chars array.
68 * This needs to be at least 1 for null termination in case the input
69 * data isn't properly terminated, and it also needs to be big enough
70 * for ttunspecified to work without crashing.
71 */
72enum
73{
74CHARS_EXTRA = Max(sizeof UNSPEC, 2) - 1};
75
76/*
77 * A representation of the contents of a TZif file. Ideally this
78 * would have no size limits; the following sizes should suffice for
79 * practical use. This struct should not be too large, as instances
80 * are put on the stack and stacks are relatively small on some platforms.
81 * See tzfile.h for more about the sizes.
82 */
83struct state
84{
85#if TZ_RUNTIME_LEAPS
87#endif
91 bool goback;
92 bool goahead;
94 unsigned char types[TZ_MAX_TIMES];
96 char chars[Max(Max(TZ_MAX_CHARS + CHARS_EXTRA, sizeof "UTC"),
97 2 * (TZNAME_MAXIMUM + 1))];
98#if TZ_RUNTIME_LEAPS
100#endif
101};
102
103
104struct pg_tz
105{
106 /* TZname contains the canonically-cased name of the timezone */
108 struct state state;
109};
110
111
112/* in pgtz.c */
113extern int pg_open_tzfile(const char *name, char *canonname);
114
115/* in localtime.c */
116extern bool pg_tzload(const char *name, char *canonname, struct state *sp);
117
118#endif /* _PGTZ_H */
#define Max(x, y)
Definition c.h:1125
#define TZ_STRLEN_MAX
Definition pgtime.h:54
int64 pg_time_t
Definition pgtime.h:23
bool pg_tzload(const char *name, char *canonname, struct state *sp)
Definition localtime.c:1590
int pg_open_tzfile(const char *name, char *canonname)
#define TZNAME_MAXIMUM
Definition pgtz.h:37
unsigned char desigidx_type
Definition pgtz.h:39
@ CHARS_EXTRA
Definition pgtz.h:74
static char const UNSPEC[]
Definition pgtz.h:64
int_fast32_t int_fast32_2s
Definition pgtz.h:45
static int fb(int x)
Definition pgtz.h:58
pg_time_t ls_trans
Definition pgtz.h:59
int_fast32_2s ls_corr
Definition pgtz.h:60
Definition pgtz.h:105
char TZname[TZ_STRLEN_MAX+1]
Definition pgtz.h:107
int timecnt
Definition pgtz.h:88
bool goback
Definition pgtz.h:91
struct ttinfo ttis[TZ_MAX_TYPES]
Definition pgtz.h:95
int charcnt
Definition pgtz.h:90
int typecnt
Definition pgtz.h:89
int leapcnt
Definition pgtz.h:86
pg_time_t ats[TZ_MAX_TIMES]
Definition pgtz.h:93
struct lsinfo lsis[TZ_MAX_LEAPS]
Definition pgtz.h:99
unsigned char types[TZ_MAX_TIMES]
Definition pgtz.h:94
char chars[Max(Max(TZ_MAX_CHARS+CHARS_EXTRA, sizeof "UTC"), 2 *(TZNAME_MAXIMUM+1))]
Definition pgtz.h:97
bool goahead
Definition pgtz.h:92
Definition pgtz.h:48
bool tt_ttisstd
Definition pgtz.h:53
bool tt_isdst
Definition pgtz.h:52
int_least32_t tt_utoff
Definition pgtz.h:49
desigidx_type tt_desigidx
Definition pgtz.h:51
bool tt_ttisut
Definition pgtz.h:54
#define TZ_MAX_CHARS
Definition tzfile.h:112
#define TZ_MAX_TYPES
Definition tzfile.h:107
#define TZ_MAX_TIMES
Definition tzfile.h:102
#define TZ_MAX_LEAPS
Definition tzfile.h:122
const char * name