xref: /PHP-5.4/ext/date/lib/timelib_structs.h (revision 22dba2f5)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 5                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2014 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 	uint32_t ttisgmtcnt;
108 	uint32_t ttisstdcnt;
109 	uint32_t leapcnt;
110 	uint32_t timecnt;
111 	uint32_t typecnt;
112 	uint32_t charcnt;
113 
114 	int32_t *trans;
115 	unsigned char *trans_idx;
116 
117 	ttinfo  *type;
118 	char    *timezone_abbr;
119 
120 	tlinfo  *leap_times;
121 	unsigned char bc;
122 	tlocinfo location;
123 } timelib_tzinfo;
124 
125 typedef struct timelib_special {
126 	unsigned int type;
127 	timelib_sll amount;
128 } timelib_special;
129 
130 typedef struct timelib_rel_time {
131 	timelib_sll y, m, d; /* Years, Months and Days */
132 	timelib_sll h, i, s; /* Hours, mInutes and Seconds */
133 
134 	int weekday; /* Stores the day in 'next monday' */
135 	int weekday_behavior; /* 0: the current day should *not* be counted when advancing forwards; 1: the current day *should* be counted */
136 
137 	int first_last_day_of;
138 	int invert; /* Whether the difference should be inverted */
139 	timelib_sll days; /* Contains the number of *days*, instead of Y-M-D differences */
140 
141 	timelib_special  special;
142 	unsigned int   have_weekday_relative, have_special_relative;
143 } timelib_rel_time;
144 
145 typedef struct timelib_time_offset {
146 	int32_t      offset;
147 	unsigned int leap_secs;
148 	unsigned int is_dst;
149 	char        *abbr;
150 	timelib_sll  transistion_time;
151 } timelib_time_offset;
152 
153 typedef struct timelib_time {
154 	timelib_sll      y, m, d;     /* Year, Month, Day */
155 	timelib_sll      h, i, s;     /* Hour, mInute, Second */
156 	double           f;           /* Fraction */
157 	int              z;           /* GMT offset in minutes */
158 	char            *tz_abbr;     /* Timezone abbreviation (display only) */
159 	timelib_tzinfo  *tz_info;     /* Timezone structure */
160 	signed int       dst;         /* Flag if we were parsing a DST zone */
161 	timelib_rel_time relative;
162 
163 	timelib_sll      sse;         /* Seconds since epoch */
164 
165 	unsigned int   have_time, have_date, have_zone, have_relative, have_weeknr_day;
166 
167 	unsigned int   sse_uptodate; /* !0 if the sse member is up to date with the date/time members */
168 	unsigned int   tim_uptodate; /* !0 if the date/time members are up to date with the sse member */
169 	unsigned int   is_localtime; /*  1 if the current struct represents localtime, 0 if it is in GMT */
170 	unsigned int   zone_type;    /*  1 time offset,
171 	                              *  3 TimeZone identifier,
172 	                              *  2 TimeZone abbreviation */
173 } timelib_time;
174 
175 typedef struct timelib_abbr_info {
176 	timelib_sll  utc_offset;
177 	char        *abbr;
178 	int          dst;
179 } timelib_abbr_info;
180 
181 typedef struct timelib_error_message {
182 	int         position;
183 	char        character;
184 	char       *message;
185 } timelib_error_message;
186 
187 typedef struct timelib_error_container {
188 	int                           warning_count;
189 	struct timelib_error_message *warning_messages;
190 	int                           error_count;
191 	struct timelib_error_message *error_messages;
192 } timelib_error_container;
193 
194 typedef struct _timelib_tz_lookup_table {
195 	char       *name;
196 	int         type;
197 	float       gmtoffset;
198 	char       *full_tz_name;
199 } timelib_tz_lookup_table;
200 
201 typedef struct _timelib_tzdb_index_entry {
202 	char *id;
203 	unsigned int pos;
204 } timelib_tzdb_index_entry;
205 
206 typedef struct _timelib_tzdb {
207 	char                           *version;
208 	int                             index_size;
209 	const timelib_tzdb_index_entry *index;
210 	const unsigned char            *data;
211 } timelib_tzdb;
212 
213 #define TIMELIB_ZONETYPE_OFFSET 1
214 #define TIMELIB_ZONETYPE_ABBR   2
215 #define TIMELIB_ZONETYPE_ID     3
216 
217 #define SECS_PER_ERA   TIMELIB_LL_CONST(12622780800)
218 #define SECS_PER_DAY   86400
219 #define DAYS_PER_YEAR    365
220 #define DAYS_PER_LYEAR   366
221 /* 400*365 days + 97 leap days */
222 #define DAYS_PER_LYEAR_PERIOD 146097
223 #define YEARS_PER_LYEAR_PERIOD 400
224 
225 #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
226 
227 #define TIMELIB_DEBUG(s)  if (0) { s }
228 
229 #endif
230