xref: /PHP-5.5/ext/date/php_date.h (revision 2c117a40)
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 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 
86 PHP_METHOD(DateTimeZone, __construct);
87 PHP_METHOD(DateTimeZone, __wakeup);
88 PHP_METHOD(DateTimeZone, __set_state);
89 PHP_FUNCTION(timezone_open);
90 PHP_FUNCTION(timezone_name_get);
91 PHP_FUNCTION(timezone_name_from_abbr);
92 PHP_FUNCTION(timezone_offset_get);
93 PHP_FUNCTION(timezone_transitions_get);
94 PHP_FUNCTION(timezone_location_get);
95 PHP_FUNCTION(timezone_identifiers_list);
96 PHP_FUNCTION(timezone_abbreviations_list);
97 PHP_FUNCTION(timezone_version_get);
98 
99 PHP_METHOD(DateInterval, __construct);
100 PHP_METHOD(DateInterval, __wakeup);
101 PHP_METHOD(DateInterval, __set_state);
102 PHP_FUNCTION(date_interval_format);
103 PHP_FUNCTION(date_interval_create_from_date_string);
104 
105 PHP_METHOD(DatePeriod, __construct);
106 PHP_METHOD(DatePeriod, __wakeup);
107 PHP_METHOD(DatePeriod, __set_state);
108 
109 /* Options and Configuration */
110 PHP_FUNCTION(date_default_timezone_set);
111 PHP_FUNCTION(date_default_timezone_get);
112 
113 /* Astro functions */
114 PHP_FUNCTION(date_sunrise);
115 PHP_FUNCTION(date_sunset);
116 PHP_FUNCTION(date_sun_info);
117 
118 PHP_RINIT_FUNCTION(date);
119 PHP_RSHUTDOWN_FUNCTION(date);
120 PHP_MINIT_FUNCTION(date);
121 PHP_MSHUTDOWN_FUNCTION(date);
122 PHP_MINFO_FUNCTION(date);
123 
124 typedef struct _php_date_obj php_date_obj;
125 typedef struct _php_timezone_obj php_timezone_obj;
126 typedef struct _php_interval_obj php_interval_obj;
127 typedef struct _php_period_obj php_period_obj;
128 
129 struct _php_date_obj {
130 	zend_object   std;
131 	timelib_time *time;
132 	HashTable    *props;
133 };
134 
135 struct _php_timezone_obj {
136 	zend_object     std;
137 	int             initialized;
138 	int             type;
139 	union {
140 		timelib_tzinfo   *tz;         /* TIMELIB_ZONETYPE_ID */
141 		timelib_sll       utc_offset; /* TIMELIB_ZONETYPE_OFFSET */
142 		timelib_abbr_info z;          /* TIMELIB_ZONETYPE_ABBR */
143 	} tzi;
144 	HashTable *props;
145 };
146 
147 struct _php_interval_obj {
148 	zend_object       std;
149 	timelib_rel_time *diff;
150 	HashTable        *props;
151 	int               initialized;
152 };
153 
154 struct _php_period_obj {
155 	zend_object       std;
156 	timelib_time     *start;
157 	zend_class_entry *start_ce;
158 	timelib_time     *current;
159 	timelib_time     *end;
160 	timelib_rel_time *interval;
161 	int               recurrences;
162 	int               initialized;
163 	int               include_start_date;
164 };
165 
166 ZEND_BEGIN_MODULE_GLOBALS(date)
167 	char                    *default_timezone;
168 	char                    *timezone;
169 	HashTable               *tzcache;
170 	timelib_error_container *last_errors;
171 	int                     timezone_valid;
172 ZEND_END_MODULE_GLOBALS(date)
173 
174 #ifdef ZTS
175 #define DATEG(v) TSRMG(date_globals_id, zend_date_globals *, v)
176 #else
177 #define DATEG(v) (date_globals.v)
178 #endif
179 
180 /* Backwards compatibility wrapper */
181 PHPAPI signed long php_parse_date(char *string, signed long *now);
182 PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt);
183 PHPAPI int php_idate(char format, time_t ts, int localtime TSRMLS_DC);
184 #if HAVE_STRFTIME
185 #define _php_strftime php_strftime
186 PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
187 #endif
188 PHPAPI char *php_format_date(char *format, int format_len, time_t ts, int localtime TSRMLS_DC);
189 
190 /* Mechanism to set new TZ database */
191 PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
192 PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D);
193 
194 /* Grabbing CE's so that other exts can use the date objects too */
195 PHPAPI zend_class_entry *php_date_get_date_ce(void);
196 PHPAPI zend_class_entry *php_date_get_immutable_ce(void);
197 PHPAPI zend_class_entry *php_date_get_timezone_ce(void);
198 
199 /* Functions for creating DateTime objects, and initializing them from a string */
200 PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC);
201 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);
202 
203 
204 #endif /* PHP_DATE_H */
205