php_date.h 6.6 KB

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