xref: /PHP-5.5/ext/date/lib/timelib_structs.h (revision 912e42fc)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 5                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2015 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Derick Rethans <derick@derickrethans.nl>                    |
16    +----------------------------------------------------------------------+
17  */
18 
19 /* $Id$ */
20 
21 #ifndef __TIMELIB_STRUCTS_H__
22 #define __TIMELIB_STRUCTS_H__
23 
24 #include "timelib_config.h"
25 
26 #ifdef HAVE_SYS_TYPES_H
27 #include <sys/types.h>
28 #endif
29 
30 #if defined(HAVE_INTTYPES_H)
31 #include <inttypes.h>
32 #elif defined(HAVE_STDINT_H)
33 #include <stdint.h>
34 #endif
35 
36 #ifdef PHP_WIN32
37 /* TODO: Remove these hacks/defs once we have the int definitions in main/
38 	 rathen than in each 2nd extension and win32/ */
39 # include "win32/php_stdint.h"
40 #else
41 # ifndef HAVE_INT32_T
42 #  if SIZEOF_INT == 4
43 typedef int int32_t;
44 #  elif SIZEOF_LONG == 4
45 typedef long int int32_t;
46 #  endif
47 # endif
48 
49 # ifndef HAVE_UINT32_T
50 #  if SIZEOF_INT == 4
51 typedef unsigned int uint32_t;
52 #  elif SIZEOF_LONG == 4
53 typedef unsigned long int uint32_t;
54 #  endif
55 # endif
56 #endif
57 
58 #include <stdio.h>
59 
60 #ifdef HAVE_STDLIB_H
61 #include <stdlib.h>
62 #endif
63 
64 #ifdef HAVE_STRING_H
65 #include <string.h>
66 #else
67 #include <strings.h>
68 #endif
69 
70 #if defined(_MSC_VER)
71 typedef uint64_t timelib_ull;
72 typedef int64_t timelib_sll;
73 # define TIMELIB_LL_CONST(n) n ## i64
74 #else
75 typedef unsigned long long timelib_ull;
76 typedef signed long long timelib_sll;
77 # define TIMELIB_LL_CONST(n) n ## ll
78 #endif
79 
80 typedef struct ttinfo
81 {
82 	int32_t      offset;
83 	int          isdst;
84 	unsigned int abbr_idx;
85 
86 	unsigned int isstdcnt;
87 	unsigned int isgmtcnt;
88 } ttinfo;
89 
90 typedef struct tlinfo
91 {
92 	int32_t  trans;
93 	int32_t  offset;
94 } tlinfo;
95 
96 typedef struct tlocinfo
97 {
98 	char country_code[3];
99 	double latitude;
100 	double longitude;
101 	char *comments;
102 } tlocinfo;
103 
104 typedef struct timelib_tzinfo
105 {
106 	char    *name;
107 	struct {
108 		uint32_t ttisgmtcnt;
109 		uint32_t ttisstdcnt;
110 		uint32_t leapcnt;
111 		uint32_t timecnt;
112 		uint32_t typecnt;
113 		uint32_t charcnt;
114 	} bit32;
115 	struct {
116 		uint64_t ttisgmtcnt;
117 		uint64_t ttisstdcnt;
118 		uint64_t leapcnt;
119 		uint64_t timecnt;
120 		uint64_t typecnt;
121 		uint64_t charcnt;
122 	} bit64;
123 
124 	int32_t *trans;
125 	unsigned char *trans_idx;
126 
127 	ttinfo  *type;
128 	char    *timezone_abbr;
129 
130 	tlinfo  *leap_times;
131 	unsigned char bc;
132 	tlocinfo location;
133 } timelib_tzinfo;
134 
135 typedef struct timelib_special {
136 	unsigned int type;
137 	timelib_sll amount;
138 } timelib_special;
139 
140 typedef struct timelib_rel_time {
141 	timelib_sll y, m, d; /* Years, Months and Days */
142 	timelib_sll h, i, s; /* Hours, mInutes and Seconds */
143 
144 	int weekday; /* Stores the day in 'next monday' */
145 	int weekday_behavior; /* 0: the current day should *not* be counted when advancing forwards; 1: the current day *should* be counted */
146 
147 	int first_last_day_of;
148 	int invert; /* Whether the difference should be inverted */
149 	timelib_sll days; /* Contains the number of *days*, instead of Y-M-D differences */
150 
151 	timelib_special  special;
152 	unsigned int   have_weekday_relative, have_special_relative;
153 } timelib_rel_time;
154 
155 typedef struct timelib_time_offset {
156 	int32_t      offset;
157 	unsigned int leap_secs;
158 	unsigned int is_dst;
159 	char        *abbr;
160 	timelib_sll  transistion_time;
161 } timelib_time_offset;
162 
163 typedef struct timelib_time {
164 	timelib_sll      y, m, d;     /* Year, Month, Day */
165 	timelib_sll      h, i, s;     /* Hour, mInute, Second */
166 	double           f;           /* Fraction */
167 	int              z;           /* GMT offset in minutes */
168 	char            *tz_abbr;     /* Timezone abbreviation (display only) */
169 	timelib_tzinfo  *tz_info;     /* Timezone structure */
170 	signed int       dst;         /* Flag if we were parsing a DST zone */
171 	timelib_rel_time relative;
172 
173 	timelib_sll      sse;         /* Seconds since epoch */
174 
175 	unsigned int   have_time, have_date, have_zone, have_relative, have_weeknr_day;
176 
177 	unsigned int   sse_uptodate; /* !0 if the sse member is up to date with the date/time members */
178 	unsigned int   tim_uptodate; /* !0 if the date/time members are up to date with the sse member */
179 	unsigned int   is_localtime; /*  1 if the current struct represents localtime, 0 if it is in GMT */
180 	unsigned int   zone_type;    /*  1 time offset,
181 	                              *  3 TimeZone identifier,
182 	                              *  2 TimeZone abbreviation */
183 } timelib_time;
184 
185 typedef struct timelib_abbr_info {
186 	timelib_sll  utc_offset;
187 	char        *abbr;
188 	int          dst;
189 } timelib_abbr_info;
190 
191 typedef struct timelib_error_message {
192 	int         position;
193 	char        character;
194 	char       *message;
195 } timelib_error_message;
196 
197 typedef struct timelib_error_container {
198 	int                           warning_count;
199 	struct timelib_error_message *warning_messages;
200 	int                           error_count;
201 	struct timelib_error_message *error_messages;
202 } timelib_error_container;
203 
204 typedef struct _timelib_tz_lookup_table {
205 	char       *name;
206 	int         type;
207 	float       gmtoffset;
208 	char       *full_tz_name;
209 } timelib_tz_lookup_table;
210 
211 typedef struct _timelib_tzdb_index_entry {
212 	char *id;
213 	unsigned int pos;
214 } timelib_tzdb_index_entry;
215 
216 typedef struct _timelib_tzdb {
217 	char                           *version;
218 	int                             index_size;
219 	const timelib_tzdb_index_entry *index;
220 	const unsigned char            *data;
221 } timelib_tzdb;
222 
223 #define TIMELIB_ZONETYPE_OFFSET 1
224 #define TIMELIB_ZONETYPE_ABBR   2
225 #define TIMELIB_ZONETYPE_ID     3
226 
227 #define SECS_PER_ERA   TIMELIB_LL_CONST(12622780800)
228 #define SECS_PER_DAY   86400
229 #define DAYS_PER_YEAR    365
230 #define DAYS_PER_LYEAR   366
231 /* 400*365 days + 97 leap days */
232 #define DAYS_PER_LYEAR_PERIOD 146097
233 #define YEARS_PER_LYEAR_PERIOD 400
234 
235 #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
236 
237 #define TIMELIB_DEBUG(s)  if (0) { s }
238 
239 #endif
240