1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | http://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Gustavo Lopes <cataphract@netcabo.pt> |
14 +----------------------------------------------------------------------+
15 */
16
17 #ifndef TIMEZONE_CLASS_H
18 #define TIMEZONE_CLASS_H
19
20 //redefinition of inline in PHP headers causes problems, so include this before
21 #include <math.h>
22
23 //fixes the build on windows for old versions of ICU
24 #include <stdio.h>
25
26 #include <php.h>
27 #include "intl_error.h"
28 #include "intl_data.h"
29
30 #ifndef USE_TIMEZONE_POINTER
31 typedef void TimeZone;
32 #else
33 using icu::TimeZone;
34 #endif
35
36 typedef struct {
37 // error handling
38 intl_error err;
39
40 // ICU TimeZone
41 const TimeZone *utimezone;
42
43 //whether to delete the timezone on object free
44 zend_bool should_delete;
45
46 zend_object zo;
47 } TimeZone_object;
48
php_intl_timezone_fetch_object(zend_object * obj)49 static inline TimeZone_object *php_intl_timezone_fetch_object(zend_object *obj) {
50 return (TimeZone_object *)((char*)(obj) - XtOffsetOf(TimeZone_object, zo));
51 }
52 #define Z_INTL_TIMEZONE_P(zv) php_intl_timezone_fetch_object(Z_OBJ_P(zv))
53
54 #define TIMEZONE_ERROR(to) (to)->err
55 #define TIMEZONE_ERROR_P(to) &(TIMEZONE_ERROR(to))
56
57 #define TIMEZONE_ERROR_CODE(co) INTL_ERROR_CODE(TIMEZONE_ERROR(to))
58 #define TIMEZONE_ERROR_CODE_P(co) &(INTL_ERROR_CODE(TIMEZONE_ERROR(to)))
59
60 #define TIMEZONE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(TimeZone, to)
61 #define TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_TIMEZONE, to)
62 #define TIMEZONE_METHOD_FETCH_OBJECT\
63 TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK; \
64 if (to->utimezone == NULL) { \
65 intl_errors_set(&to->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlTimeZone", 0); \
66 RETURN_FALSE; \
67 }
68
69 zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, intl_error *outside_error, const char *func, zval *ret);
70 TimeZone *timezone_process_timezone_argument(zval *zv_timezone, intl_error *error, const char *func);
71
72 void timezone_object_construct(const TimeZone *zone, zval *object, int owned);
73
74 void timezone_register_IntlTimeZone_class(void);
75
76 extern zend_class_entry *TimeZone_ce_ptr;
77 extern zend_object_handlers TimeZone_handlers;
78
79 #endif /* #ifndef TIMEZONE_CLASS_H */
80