1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #ifndef __TIMELIB_STRUCTS_H__
26 #define __TIMELIB_STRUCTS_H__
27
28 #ifdef HAVE_TIMELIB_CONFIG_H
29 # include "timelib_config.h"
30 #endif
31
32 #ifndef TIMELIB_OMIT_STDINT
33
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
36 #endif
37
38 #if defined(HAVE_INTTYPES_H)
39 #include <inttypes.h>
40 #elif defined(HAVE_STDINT_H)
41 #include <stdint.h>
42 #endif
43
44 # ifndef HAVE_INT32_T
45 # if SIZEOF_INT == 4
46 typedef int int32_t;
47 # elif SIZEOF_LONG == 4
48 typedef long int int32_t;
49 # endif
50 # endif
51
52 # ifndef HAVE_UINT32_T
53 # if SIZEOF_INT == 4
54 typedef unsigned int uint32_t;
55 # elif SIZEOF_LONG == 4
56 typedef unsigned long int uint32_t;
57 # endif
58 # endif
59
60 #ifdef _WIN32
61 # if _MSC_VER >= 1600
62 # include <stdint.h>
63 # endif
64 # ifndef SIZEOF_INT
65 # define SIZEOF_INT 4
66 # endif
67 # ifndef SIZEOF_LONG
68 # define SIZEOF_LONG 4
69 # endif
70 # ifndef int32_t
71 typedef __int32 int32_t;
72 # endif
73 # ifndef uint32_t
74 typedef unsigned __int32 uint32_t;
75 # endif
76 # ifndef int64_t
77 typedef __int64 int64_t;
78 # endif
79 # ifndef uint64_t
80 typedef unsigned __int64 uint64_t;
81 # endif
82 # ifndef PRId32
83 # define PRId32 "I32d"
84 # endif
85 # ifndef PRIu32
86 # define PRIu32 "I32u"
87 # endif
88 # ifndef PRId64
89 # define PRId64 "I64d"
90 # endif
91 # ifndef PRIu64
92 # define PRIu64 "I64u"
93 # endif
94 # ifndef INT32_MAX
95 #define INT32_MAX _I32_MAX
96 # endif
97 # ifndef INT32_MIN
98 #define INT32_MIN ((int32_t)_I32_MIN)
99 # endif
100 # ifndef UINT32_MAX
101 #define UINT32_MAX _UI32_MAX
102 # endif
103 # ifndef INT64_MIN
104 #define INT64_MIN ((int64_t)_I64_MIN)
105 # endif
106 # ifndef INT64_MAX
107 #define INT64_MAX _I64_MAX
108 # endif
109 # ifndef UINT64_MAX
110 #define UINT64_MAX _UI64_MAX
111 # endif
112 #endif
113
114 #endif
115
116 #include <stdio.h>
117
118 #ifdef HAVE_STDLIB_H
119 #include <stdlib.h>
120 #endif
121
122 #ifdef HAVE_STRING_H
123 #include <string.h>
124 #else
125 #include <strings.h>
126 #endif
127
128 #if defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)
129 typedef int64_t timelib_long;
130 typedef uint64_t timelib_ulong;
131 # define TIMELIB_LONG_MAX INT64_MAX
132 # define TIMELIB_LONG_MIN INT64_MIN
133 # define TIMELIB_ULONG_MAX UINT64_MAX
134 # define TIMELIB_LONG_FMT "%" PRId64
135 # define TIMELIB_ULONG_FMT "%" PRIu64
136 #else
137 typedef int32_t timelib_long;
138 typedef uint32_t timelib_ulong;
139 # define TIMELIB_LONG_MAX INT32_MAX
140 # define TIMELIB_LONG_MIN INT32_MIN
141 # define TIMELIB_ULONG_MAX UINT32_MAX
142 # define TIMELIB_LONG_FMT "%" PRId32
143 # define TIMELIB_ULONG_FMT "%" PRIu32
144 #endif
145
146 #if defined(_MSC_VER)
147 typedef uint64_t timelib_ull;
148 typedef int64_t timelib_sll;
149 # define TIMELIB_LL_CONST(n) n ## i64
150 #else
151 typedef unsigned long long timelib_ull;
152 typedef signed long long timelib_sll;
153 # define TIMELIB_LL_CONST(n) n ## ll
154 #endif
155
156 typedef struct ttinfo
157 {
158 int32_t offset;
159 int isdst;
160 unsigned int abbr_idx;
161
162 unsigned int isstdcnt;
163 unsigned int isgmtcnt;
164 } ttinfo;
165
166 typedef struct tlinfo
167 {
168 int32_t trans;
169 int32_t offset;
170 } tlinfo;
171
172 typedef struct tlocinfo
173 {
174 char country_code[3];
175 double latitude;
176 double longitude;
177 char *comments;
178 } tlocinfo;
179
180 typedef struct timelib_tzinfo
181 {
182 char *name;
183 struct {
184 uint32_t ttisgmtcnt;
185 uint32_t ttisstdcnt;
186 uint32_t leapcnt;
187 uint32_t timecnt;
188 uint32_t typecnt;
189 uint32_t charcnt;
190 } bit32;
191 struct {
192 uint64_t ttisgmtcnt;
193 uint64_t ttisstdcnt;
194 uint64_t leapcnt;
195 uint64_t timecnt;
196 uint64_t typecnt;
197 uint64_t charcnt;
198 } bit64;
199
200 int32_t *trans;
201 unsigned char *trans_idx;
202
203 ttinfo *type;
204 char *timezone_abbr;
205
206 tlinfo *leap_times;
207 unsigned char bc;
208 tlocinfo location;
209 } timelib_tzinfo;
210
211 typedef struct timelib_special {
212 unsigned int type;
213 timelib_sll amount;
214 } timelib_special;
215
216 typedef struct timelib_rel_time {
217 timelib_sll y, m, d;
218 timelib_sll h, i, s;
219
220 int weekday;
221 int weekday_behavior;
222
223 int first_last_day_of;
224 int invert;
225 timelib_sll days;
226
227 timelib_special special;
228 unsigned int have_weekday_relative, have_special_relative;
229 } timelib_rel_time;
230
231 typedef struct timelib_time_offset {
232 int32_t offset;
233 unsigned int leap_secs;
234 unsigned int is_dst;
235 char *abbr;
236 timelib_sll transistion_time;
237 } timelib_time_offset;
238
239 typedef struct timelib_time {
240 timelib_sll y, m, d;
241 timelib_sll h, i, s;
242 double f;
243 int z;
244 char *tz_abbr;
245 timelib_tzinfo *tz_info;
246 signed int dst;
247 timelib_rel_time relative;
248
249 timelib_sll sse;
250
251 unsigned int have_time, have_date, have_zone, have_relative, have_weeknr_day;
252
253 unsigned int sse_uptodate;
254 unsigned int tim_uptodate;
255 unsigned int is_localtime;
256 unsigned int zone_type;
257
258
259 } timelib_time;
260
261 typedef struct timelib_abbr_info {
262 timelib_sll utc_offset;
263 char *abbr;
264 int dst;
265 } timelib_abbr_info;
266
267 typedef struct timelib_error_message {
268 int position;
269 char character;
270 char *message;
271 } timelib_error_message;
272
273 typedef struct timelib_error_container {
274 struct timelib_error_message *error_messages;
275 struct timelib_error_message *warning_messages;
276 int error_count;
277 int warning_count;
278 } timelib_error_container;
279
280 typedef struct _timelib_tz_lookup_table {
281 char *name;
282 int type;
283 float gmtoffset;
284 char *full_tz_name;
285 } timelib_tz_lookup_table;
286
287 typedef struct _timelib_tzdb_index_entry {
288 char *id;
289 unsigned int pos;
290 } timelib_tzdb_index_entry;
291
292 typedef struct _timelib_tzdb {
293 char *version;
294 int index_size;
295 const timelib_tzdb_index_entry *index;
296 const unsigned char *data;
297 } timelib_tzdb;
298
299 #define TIMELIB_ZONETYPE_OFFSET 1
300 #define TIMELIB_ZONETYPE_ABBR 2
301 #define TIMELIB_ZONETYPE_ID 3
302
303 #define SECS_PER_ERA TIMELIB_LL_CONST(12622780800)
304 #define SECS_PER_DAY 86400
305 #define DAYS_PER_YEAR 365
306 #define DAYS_PER_LYEAR 366
307
308 #define DAYS_PER_LYEAR_PERIOD 146097
309 #define YEARS_PER_LYEAR_PERIOD 400
310
311 #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
312
313 #define TIMELIB_DEBUG(s) if (0) { s }
314
315 #endif