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