php_date.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  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. | https://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: Derick Rethans <derick@derickrethans.nl> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef PHP_DATE_H
  17. #define PHP_DATE_H
  18. #include "lib/timelib.h"
  19. #include "Zend/zend_hash.h"
  20. #include "php_version.h"
  21. #define PHP_DATE_VERSION PHP_VERSION
  22. extern zend_module_entry date_module_entry;
  23. #define phpext_date_ptr &date_module_entry
  24. PHP_RINIT_FUNCTION(date);
  25. PHP_RSHUTDOWN_FUNCTION(date);
  26. PHP_MINIT_FUNCTION(date);
  27. PHP_MSHUTDOWN_FUNCTION(date);
  28. PHP_MINFO_FUNCTION(date);
  29. ZEND_MODULE_POST_ZEND_DEACTIVATE_D(date);
  30. typedef struct _php_date_obj php_date_obj;
  31. typedef struct _php_timezone_obj php_timezone_obj;
  32. typedef struct _php_interval_obj php_interval_obj;
  33. typedef struct _php_period_obj php_period_obj;
  34. struct _php_date_obj {
  35. timelib_time *time;
  36. zend_object std;
  37. };
  38. static inline php_date_obj *php_date_obj_from_obj(zend_object *obj) {
  39. return (php_date_obj*)((char*)(obj) - XtOffsetOf(php_date_obj, std));
  40. }
  41. #define Z_PHPDATE_P(zv) php_date_obj_from_obj(Z_OBJ_P((zv)))
  42. struct _php_timezone_obj {
  43. int initialized;
  44. int type;
  45. union {
  46. timelib_tzinfo *tz; /* TIMELIB_ZONETYPE_ID */
  47. timelib_sll utc_offset; /* TIMELIB_ZONETYPE_OFFSET */
  48. timelib_abbr_info z; /* TIMELIB_ZONETYPE_ABBR */
  49. } tzi;
  50. zend_object std;
  51. };
  52. static inline php_timezone_obj *php_timezone_obj_from_obj(zend_object *obj) {
  53. return (php_timezone_obj*)((char*)(obj) - XtOffsetOf(php_timezone_obj, std));
  54. }
  55. #define Z_PHPTIMEZONE_P(zv) php_timezone_obj_from_obj(Z_OBJ_P((zv)))
  56. #define PHP_DATE_CIVIL 1
  57. #define PHP_DATE_WALL 2
  58. struct _php_interval_obj {
  59. timelib_rel_time *diff;
  60. int civil_or_wall;
  61. int initialized;
  62. zend_object std;
  63. };
  64. static inline php_interval_obj *php_interval_obj_from_obj(zend_object *obj) {
  65. return (php_interval_obj*)((char*)(obj) - XtOffsetOf(php_interval_obj, std));
  66. }
  67. #define Z_PHPINTERVAL_P(zv) php_interval_obj_from_obj(Z_OBJ_P((zv)))
  68. struct _php_period_obj {
  69. timelib_time *start;
  70. zend_class_entry *start_ce;
  71. timelib_time *current;
  72. timelib_time *end;
  73. timelib_rel_time *interval;
  74. int recurrences;
  75. int initialized;
  76. int include_start_date;
  77. zend_object std;
  78. };
  79. static inline php_period_obj *php_period_obj_from_obj(zend_object *obj) {
  80. return (php_period_obj*)((char*)(obj) - XtOffsetOf(php_period_obj, std));
  81. }
  82. #define Z_PHPPERIOD_P(zv) php_period_obj_from_obj(Z_OBJ_P((zv)))
  83. ZEND_BEGIN_MODULE_GLOBALS(date)
  84. char *default_timezone;
  85. char *timezone;
  86. HashTable *tzcache;
  87. timelib_error_container *last_errors;
  88. int timezone_valid;
  89. ZEND_END_MODULE_GLOBALS(date)
  90. #define DATEG(v) ZEND_MODULE_GLOBALS_ACCESSOR(date, v)
  91. PHPAPI time_t php_time(void);
  92. /* Backwards compatibility wrapper */
  93. PHPAPI zend_long php_parse_date(const char *string, zend_long *now);
  94. PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt);
  95. PHPAPI int php_idate(char format, time_t ts, int localtime);
  96. #define _php_strftime php_strftime
  97. PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
  98. PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, int localtime);
  99. /* Mechanism to set new TZ database */
  100. PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
  101. PHPAPI timelib_tzinfo *get_timezone_info(void);
  102. /* Grabbing CE's so that other exts can use the date objects too */
  103. PHPAPI zend_class_entry *php_date_get_date_ce(void);
  104. PHPAPI zend_class_entry *php_date_get_immutable_ce(void);
  105. PHPAPI zend_class_entry *php_date_get_interface_ce(void);
  106. PHPAPI zend_class_entry *php_date_get_timezone_ce(void);
  107. PHPAPI zend_class_entry *php_date_get_interval_ce(void);
  108. PHPAPI zend_class_entry *php_date_get_period_ce(void);
  109. /* Functions for creating DateTime objects, and initializing them from a string */
  110. #define PHP_DATE_INIT_CTOR 0x01
  111. #define PHP_DATE_INIT_FORMAT 0x02
  112. PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object);
  113. PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, const char *format, zval *timezone_object, int flags);
  114. #endif /* PHP_DATE_H */