xref: /PHP-7.0/ext/date/php_date.h (revision 478f119a)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2017 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 PHP_DATE_H
22 #define PHP_DATE_H
23 
24 #include "lib/timelib.h"
25 #include "Zend/zend_hash.h"
26 
27 #include "php_version.h"
28 #define PHP_DATE_VERSION PHP_VERSION
29 
30 extern zend_module_entry date_module_entry;
31 #define phpext_date_ptr &date_module_entry
32 
33 PHP_FUNCTION(date);
34 PHP_FUNCTION(idate);
35 PHP_FUNCTION(gmdate);
36 PHP_FUNCTION(strtotime);
37 
38 PHP_FUNCTION(mktime);
39 PHP_FUNCTION(gmmktime);
40 
41 PHP_FUNCTION(checkdate);
42 
43 #ifdef HAVE_STRFTIME
44 PHP_FUNCTION(strftime);
45 PHP_FUNCTION(gmstrftime);
46 #endif
47 
48 PHP_FUNCTION(time);
49 PHP_FUNCTION(localtime);
50 PHP_FUNCTION(getdate);
51 
52 /* Advanced Interface */
53 PHP_METHOD(DateTime, __construct);
54 PHP_METHOD(DateTime, __wakeup);
55 PHP_METHOD(DateTime, __set_state);
56 PHP_FUNCTION(date_create);
57 PHP_FUNCTION(date_create_immutable);
58 PHP_FUNCTION(date_create_from_format);
59 PHP_FUNCTION(date_create_immutable_from_format);
60 PHP_FUNCTION(date_parse);
61 PHP_FUNCTION(date_parse_from_format);
62 PHP_FUNCTION(date_get_last_errors);
63 PHP_FUNCTION(date_format);
64 PHP_FUNCTION(date_modify);
65 PHP_FUNCTION(date_add);
66 PHP_FUNCTION(date_sub);
67 PHP_FUNCTION(date_timezone_get);
68 PHP_FUNCTION(date_timezone_set);
69 PHP_FUNCTION(date_offset_get);
70 PHP_FUNCTION(date_diff);
71 
72 PHP_FUNCTION(date_time_set);
73 PHP_FUNCTION(date_date_set);
74 PHP_FUNCTION(date_isodate_set);
75 PHP_FUNCTION(date_timestamp_set);
76 PHP_FUNCTION(date_timestamp_get);
77 
78 PHP_METHOD(DateTimeImmutable, __construct);
79 PHP_METHOD(DateTimeImmutable, __set_state);
80 PHP_METHOD(DateTimeImmutable, modify);
81 PHP_METHOD(DateTimeImmutable, add);
82 PHP_METHOD(DateTimeImmutable, sub);
83 PHP_METHOD(DateTimeImmutable, setTimezone);
84 PHP_METHOD(DateTimeImmutable, setTime);
85 PHP_METHOD(DateTimeImmutable, setDate);
86 PHP_METHOD(DateTimeImmutable, setISODate);
87 PHP_METHOD(DateTimeImmutable, setTimestamp);
88 PHP_METHOD(DateTimeImmutable, createFromMutable);
89 
90 PHP_METHOD(DateTimeZone, __construct);
91 PHP_METHOD(DateTimeZone, __wakeup);
92 PHP_METHOD(DateTimeZone, __set_state);
93 PHP_FUNCTION(timezone_open);
94 PHP_FUNCTION(timezone_name_get);
95 PHP_FUNCTION(timezone_name_from_abbr);
96 PHP_FUNCTION(timezone_offset_get);
97 PHP_FUNCTION(timezone_transitions_get);
98 PHP_FUNCTION(timezone_location_get);
99 PHP_FUNCTION(timezone_identifiers_list);
100 PHP_FUNCTION(timezone_abbreviations_list);
101 PHP_FUNCTION(timezone_version_get);
102 
103 PHP_METHOD(DateInterval, __construct);
104 PHP_METHOD(DateInterval, __wakeup);
105 PHP_METHOD(DateInterval, __set_state);
106 PHP_FUNCTION(date_interval_format);
107 PHP_FUNCTION(date_interval_create_from_date_string);
108 
109 PHP_METHOD(DatePeriod, __construct);
110 PHP_METHOD(DatePeriod, __wakeup);
111 PHP_METHOD(DatePeriod, __set_state);
112 PHP_METHOD(DatePeriod, getStartDate);
113 PHP_METHOD(DatePeriod, getEndDate);
114 PHP_METHOD(DatePeriod, getDateInterval);
115 
116 /* Options and Configuration */
117 PHP_FUNCTION(date_default_timezone_set);
118 PHP_FUNCTION(date_default_timezone_get);
119 
120 /* Astro functions */
121 PHP_FUNCTION(date_sunrise);
122 PHP_FUNCTION(date_sunset);
123 PHP_FUNCTION(date_sun_info);
124 
125 PHP_RINIT_FUNCTION(date);
126 PHP_RSHUTDOWN_FUNCTION(date);
127 PHP_MINIT_FUNCTION(date);
128 PHP_MSHUTDOWN_FUNCTION(date);
129 PHP_MINFO_FUNCTION(date);
130 
131 typedef struct _php_date_obj php_date_obj;
132 typedef struct _php_timezone_obj php_timezone_obj;
133 typedef struct _php_interval_obj php_interval_obj;
134 typedef struct _php_period_obj php_period_obj;
135 
136 struct _php_date_obj {
137 	timelib_time *time;
138 	HashTable    *props;
139 	zend_object   std;
140 };
141 
php_date_obj_from_obj(zend_object * obj)142 static inline php_date_obj *php_date_obj_from_obj(zend_object *obj) {
143 	return (php_date_obj*)((char*)(obj) - XtOffsetOf(php_date_obj, std));
144 }
145 
146 #define Z_PHPDATE_P(zv)  php_date_obj_from_obj(Z_OBJ_P((zv)))
147 
148 struct _php_timezone_obj {
149 	int             initialized;
150 	int             type;
151 	union {
152 		timelib_tzinfo   *tz;         /* TIMELIB_ZONETYPE_ID */
153 		timelib_sll       utc_offset; /* TIMELIB_ZONETYPE_OFFSET */
154 		timelib_abbr_info z;          /* TIMELIB_ZONETYPE_ABBR */
155 	} tzi;
156 	HashTable *props;
157 	zend_object std;
158 };
159 
php_timezone_obj_from_obj(zend_object * obj)160 static inline php_timezone_obj *php_timezone_obj_from_obj(zend_object *obj) {
161 	return (php_timezone_obj*)((char*)(obj) - XtOffsetOf(php_timezone_obj, std));
162 }
163 
164 #define Z_PHPTIMEZONE_P(zv)  php_timezone_obj_from_obj(Z_OBJ_P((zv)))
165 
166 struct _php_interval_obj {
167 	timelib_rel_time *diff;
168 	HashTable        *props;
169 	int               initialized;
170 	zend_object       std;
171 };
172 
php_interval_obj_from_obj(zend_object * obj)173 static inline php_interval_obj *php_interval_obj_from_obj(zend_object *obj) {
174 	return (php_interval_obj*)((char*)(obj) - XtOffsetOf(php_interval_obj, std));
175 }
176 
177 #define Z_PHPINTERVAL_P(zv)  php_interval_obj_from_obj(Z_OBJ_P((zv)))
178 
179 struct _php_period_obj {
180 	timelib_time     *start;
181 	zend_class_entry *start_ce;
182 	timelib_time     *current;
183 	timelib_time     *end;
184 	timelib_rel_time *interval;
185 	int               recurrences;
186 	int               initialized;
187 	int               include_start_date;
188 	zend_object       std;
189 };
190 
php_period_obj_from_obj(zend_object * obj)191 static inline php_period_obj *php_period_obj_from_obj(zend_object *obj) {
192 	return (php_period_obj*)((char*)(obj) - XtOffsetOf(php_period_obj, std));
193 }
194 
195 #define Z_PHPPERIOD_P(zv)  php_period_obj_from_obj(Z_OBJ_P((zv)))
196 
197 ZEND_BEGIN_MODULE_GLOBALS(date)
198 	char                    *default_timezone;
199 	char                    *timezone;
200 	HashTable               *tzcache;
201 	timelib_error_container *last_errors;
202 	int                     timezone_valid;
203 ZEND_END_MODULE_GLOBALS(date)
204 
205 #define DATEG(v) ZEND_MODULE_GLOBALS_ACCESSOR(date, v)
206 
207 /* Backwards compatibility wrapper */
208 PHPAPI zend_long php_parse_date(char *string, zend_long *now);
209 PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt);
210 PHPAPI int php_idate(char format, time_t ts, int localtime);
211 #if HAVE_STRFTIME
212 #define _php_strftime php_strftime
213 PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
214 #endif
215 PHPAPI zend_string *php_format_date(char *format, size_t format_len, time_t ts, int localtime);
216 
217 /* Mechanism to set new TZ database */
218 PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
219 PHPAPI timelib_tzinfo *get_timezone_info(void);
220 
221 /* Grabbing CE's so that other exts can use the date objects too */
222 PHPAPI zend_class_entry *php_date_get_date_ce(void);
223 PHPAPI zend_class_entry *php_date_get_immutable_ce(void);
224 PHPAPI zend_class_entry *php_date_get_timezone_ce(void);
225 
226 /* Functions for creating DateTime objects, and initializing them from a string */
227 PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object);
228 PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, size_t time_str_len, char *format, zval *timezone_object, int ctor);
229 
230 
231 #endif /* PHP_DATE_H */
232