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
27extern zend_module_entry date_module_entry;
28#define phpext_date_ptr &date_module_entry
29
30PHP_FUNCTION(date);
31PHP_FUNCTION(idate);
32PHP_FUNCTION(gmdate);
33PHP_FUNCTION(strtotime);
34
35PHP_FUNCTION(mktime);
36PHP_FUNCTION(gmmktime);
37
38PHP_FUNCTION(checkdate);
39
40#ifdef HAVE_STRFTIME
41PHP_FUNCTION(strftime);
42PHP_FUNCTION(gmstrftime);
43#endif
44
45PHP_FUNCTION(time);
46PHP_FUNCTION(localtime);
47PHP_FUNCTION(getdate);
48
49/* Advanced Interface */
50PHP_METHOD(DateTime, __construct);
51PHP_METHOD(DateTime, __wakeup);
52PHP_METHOD(DateTime, __set_state);
53PHP_FUNCTION(date_create);
54PHP_FUNCTION(date_create_immutable);
55PHP_FUNCTION(date_create_from_format);
56PHP_FUNCTION(date_create_immutable_from_format);
57PHP_FUNCTION(date_parse);
58PHP_FUNCTION(date_parse_from_format);
59PHP_FUNCTION(date_get_last_errors);
60PHP_FUNCTION(date_format);
61PHP_FUNCTION(date_modify);
62PHP_FUNCTION(date_add);
63PHP_FUNCTION(date_sub);
64PHP_FUNCTION(date_timezone_get);
65PHP_FUNCTION(date_timezone_set);
66PHP_FUNCTION(date_offset_get);
67PHP_FUNCTION(date_diff);
68
69PHP_FUNCTION(date_time_set);
70PHP_FUNCTION(date_date_set);
71PHP_FUNCTION(date_isodate_set);
72PHP_FUNCTION(date_timestamp_set);
73PHP_FUNCTION(date_timestamp_get);
74
75PHP_METHOD(DateTimeImmutable, __construct);
76PHP_METHOD(DateTimeImmutable, __set_state);
77PHP_METHOD(DateTimeImmutable, modify);
78PHP_METHOD(DateTimeImmutable, add);
79PHP_METHOD(DateTimeImmutable, sub);
80PHP_METHOD(DateTimeImmutable, setTimezone);
81PHP_METHOD(DateTimeImmutable, setTime);
82PHP_METHOD(DateTimeImmutable, setDate);
83PHP_METHOD(DateTimeImmutable, setISODate);
84PHP_METHOD(DateTimeImmutable, setTimestamp);
85PHP_METHOD(DateTimeImmutable, createFromMutable);
86
87PHP_METHOD(DateTimeZone, __construct);
88PHP_METHOD(DateTimeZone, __wakeup);
89PHP_METHOD(DateTimeZone, __set_state);
90PHP_FUNCTION(timezone_open);
91PHP_FUNCTION(timezone_name_get);
92PHP_FUNCTION(timezone_name_from_abbr);
93PHP_FUNCTION(timezone_offset_get);
94PHP_FUNCTION(timezone_transitions_get);
95PHP_FUNCTION(timezone_location_get);
96PHP_FUNCTION(timezone_identifiers_list);
97PHP_FUNCTION(timezone_abbreviations_list);
98PHP_FUNCTION(timezone_version_get);
99
100PHP_METHOD(DateInterval, __construct);
101PHP_METHOD(DateInterval, __wakeup);
102PHP_METHOD(DateInterval, __set_state);
103PHP_FUNCTION(date_interval_format);
104PHP_FUNCTION(date_interval_create_from_date_string);
105
106PHP_METHOD(DatePeriod, __construct);
107PHP_METHOD(DatePeriod, __wakeup);
108PHP_METHOD(DatePeriod, __set_state);
109PHP_METHOD(DatePeriod, getStartDate);
110PHP_METHOD(DatePeriod, getEndDate);
111PHP_METHOD(DatePeriod, getDateInterval);
112
113/* Options and Configuration */
114PHP_FUNCTION(date_default_timezone_set);
115PHP_FUNCTION(date_default_timezone_get);
116
117/* Astro functions */
118PHP_FUNCTION(date_sunrise);
119PHP_FUNCTION(date_sunset);
120PHP_FUNCTION(date_sun_info);
121
122PHP_RINIT_FUNCTION(date);
123PHP_RSHUTDOWN_FUNCTION(date);
124PHP_MINIT_FUNCTION(date);
125PHP_MSHUTDOWN_FUNCTION(date);
126PHP_MINFO_FUNCTION(date);
127
128typedef struct _php_date_obj php_date_obj;
129typedef struct _php_timezone_obj php_timezone_obj;
130typedef struct _php_interval_obj php_interval_obj;
131typedef struct _php_period_obj php_period_obj;
132
133struct _php_date_obj {
134 zend_object std;
135 timelib_time *time;
136 HashTable *props;
137};
138
139struct _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
151struct _php_interval_obj {
152 zend_object std;
153 timelib_rel_time *diff;
154 HashTable *props;
155 int initialized;
156};
157
158struct _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
170ZEND_BEGIN_MODULE_GLOBALS(date)
171 char *default_timezone;
172 char *timezone;
173 HashTable *tzcache;
174 timelib_error_container *last_errors;
175 int timezone_valid;
176ZEND_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 */
185PHPAPI signed long php_parse_date(char *string, signed long *now);
186PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt);
187PHPAPI int php_idate(char format, time_t ts, int localtime TSRMLS_DC);
188#if HAVE_STRFTIME
189#define _php_strftime php_strftime
190PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
191#endif
192PHPAPI char *php_format_date(char *format, int format_len, time_t ts, int localtime TSRMLS_DC);
193
194/* Mechanism to set new TZ database */
195PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
196PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D);
197
198/* Grabbing CE's so that other exts can use the date objects too */
199PHPAPI zend_class_entry *php_date_get_date_ce(void);
200PHPAPI zend_class_entry *php_date_get_immutable_ce(void);
201PHPAPI zend_class_entry *php_date_get_timezone_ce(void);
202
203/* Functions for creating DateTime objects, and initializing them from a string */
204PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC);
205PHPAPI 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