xref: /PHP-7.2/ext/date/php_date.h (revision 599b94ff)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 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 PHP_METHOD(DatePeriod, getRecurrences);
116 
117 /* Options and Configuration */
118 PHP_FUNCTION(date_default_timezone_set);
119 PHP_FUNCTION(date_default_timezone_get);
120 
121 /* Astro functions */
122 PHP_FUNCTION(date_sunrise);
123 PHP_FUNCTION(date_sunset);
124 PHP_FUNCTION(date_sun_info);
125 
126 PHP_RINIT_FUNCTION(date);
127 PHP_RSHUTDOWN_FUNCTION(date);
128 PHP_MINIT_FUNCTION(date);
129 PHP_MSHUTDOWN_FUNCTION(date);
130 PHP_MINFO_FUNCTION(date);
131 
132 typedef struct _php_date_obj php_date_obj;
133 typedef struct _php_timezone_obj php_timezone_obj;
134 typedef struct _php_interval_obj php_interval_obj;
135 typedef struct _php_period_obj php_period_obj;
136 
137 struct _php_date_obj {
138 	timelib_time *time;
139 	HashTable    *props;
140 	zend_object   std;
141 };
142 
php_date_obj_from_obj(zend_object * obj)143 static inline php_date_obj *php_date_obj_from_obj(zend_object *obj) {
144 	return (php_date_obj*)((char*)(obj) - XtOffsetOf(php_date_obj, std));
145 }
146 
147 #define Z_PHPDATE_P(zv)  php_date_obj_from_obj(Z_OBJ_P((zv)))
148 
149 struct _php_timezone_obj {
150 	int             initialized;
151 	int             type;
152 	union {
153 		timelib_tzinfo   *tz;         /* TIMELIB_ZONETYPE_ID */
154 		timelib_sll       utc_offset; /* TIMELIB_ZONETYPE_OFFSET */
155 		timelib_abbr_info z;          /* TIMELIB_ZONETYPE_ABBR */
156 	} tzi;
157 	HashTable *props;
158 	zend_object std;
159 };
160 
php_timezone_obj_from_obj(zend_object * obj)161 static inline php_timezone_obj *php_timezone_obj_from_obj(zend_object *obj) {
162 	return (php_timezone_obj*)((char*)(obj) - XtOffsetOf(php_timezone_obj, std));
163 }
164 
165 #define Z_PHPTIMEZONE_P(zv)  php_timezone_obj_from_obj(Z_OBJ_P((zv)))
166 
167 struct _php_interval_obj {
168 	timelib_rel_time *diff;
169 	HashTable        *props;
170 	int               initialized;
171 	zend_object       std;
172 };
173 
php_interval_obj_from_obj(zend_object * obj)174 static inline php_interval_obj *php_interval_obj_from_obj(zend_object *obj) {
175 	return (php_interval_obj*)((char*)(obj) - XtOffsetOf(php_interval_obj, std));
176 }
177 
178 #define Z_PHPINTERVAL_P(zv)  php_interval_obj_from_obj(Z_OBJ_P((zv)))
179 
180 struct _php_period_obj {
181 	timelib_time     *start;
182 	zend_class_entry *start_ce;
183 	timelib_time     *current;
184 	timelib_time     *end;
185 	timelib_rel_time *interval;
186 	int               recurrences;
187 	int               initialized;
188 	int               include_start_date;
189 	zend_object       std;
190 };
191 
php_period_obj_from_obj(zend_object * obj)192 static inline php_period_obj *php_period_obj_from_obj(zend_object *obj) {
193 	return (php_period_obj*)((char*)(obj) - XtOffsetOf(php_period_obj, std));
194 }
195 
196 #define Z_PHPPERIOD_P(zv)  php_period_obj_from_obj(Z_OBJ_P((zv)))
197 
198 ZEND_BEGIN_MODULE_GLOBALS(date)
199 	char                    *default_timezone;
200 	char                    *timezone;
201 	HashTable               *tzcache;
202 	timelib_error_container *last_errors;
203 	int                     timezone_valid;
204 ZEND_END_MODULE_GLOBALS(date)
205 
206 #define DATEG(v) ZEND_MODULE_GLOBALS_ACCESSOR(date, v)
207 
208 PHPAPI time_t php_time();
209 
210 /* Backwards compatibility wrapper */
211 PHPAPI zend_long php_parse_date(char *string, zend_long *now);
212 PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt);
213 PHPAPI int php_idate(char format, time_t ts, int localtime);
214 #if HAVE_STRFTIME
215 #define _php_strftime php_strftime
216 PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
217 #endif
218 PHPAPI zend_string *php_format_date(char *format, size_t format_len, time_t ts, int localtime);
219 
220 /* Mechanism to set new TZ database */
221 PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
222 PHPAPI timelib_tzinfo *get_timezone_info(void);
223 
224 /* Grabbing CE's so that other exts can use the date objects too */
225 PHPAPI zend_class_entry *php_date_get_date_ce(void);
226 PHPAPI zend_class_entry *php_date_get_immutable_ce(void);
227 PHPAPI zend_class_entry *php_date_get_interface_ce(void);
228 PHPAPI zend_class_entry *php_date_get_timezone_ce(void);
229 
230 /* Functions for creating DateTime objects, and initializing them from a string */
231 PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object);
232 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);
233 
234 
235 #endif /* PHP_DATE_H */
236