php_date.h 7.6 KB

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