PageRenderTime 33ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext/datetime/ext_datetime.h

https://gitlab.com/Manu343726/hhvm
C Header | 288 lines | 227 code | 30 blank | 31 comment | 0 complexity | ca8a0e6d4eb3de4ebff7512f39703943 MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
  6. | Copyright (c) 1997-2010 The PHP Group |
  7. +----------------------------------------------------------------------+
  8. | This source file is subject to version 3.01 of the PHP license, |
  9. | that is bundled with this package in the file LICENSE, and is |
  10. | available through the world-wide-web at the following url: |
  11. | http://www.php.net/license/3_01.txt |
  12. | If you did not receive a copy of the PHP license and are unable to |
  13. | obtain it through the world-wide-web, please send a note to |
  14. | license@php.net so we can mail you a copy immediately. |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifndef incl_HPHP_EXT_DATETIME_H_
  18. #define incl_HPHP_EXT_DATETIME_H_
  19. #include "hphp/runtime/ext/extension.h"
  20. #include "hphp/runtime/base/timestamp.h"
  21. #include "hphp/runtime/base/datetime.h"
  22. #include "hphp/runtime/base/timezone.h"
  23. #include "hphp/runtime/base/dateinterval.h"
  24. #include "hphp/system/constants.h"
  25. namespace HPHP {
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // class DateTime
  28. extern const StaticString q_DateTime$$ATOM;
  29. extern const StaticString q_DateTime$$COOKIE;
  30. extern const StaticString q_DateTime$$ISO8601;
  31. extern const StaticString q_DateTime$$RFC822;
  32. extern const StaticString q_DateTime$$RFC850;
  33. extern const StaticString q_DateTime$$RFC1036;
  34. extern const StaticString q_DateTime$$RFC1123;
  35. extern const StaticString q_DateTime$$RFC2822;
  36. extern const StaticString q_DateTime$$RFC3339;
  37. extern const StaticString q_DateTime$$RSS;
  38. extern const StaticString q_DateTime$$W3C;
  39. class DateTimeData {
  40. public:
  41. DateTimeData() {}
  42. DateTimeData(const DateTimeData&) = delete;
  43. DateTimeData& operator=(const DateTimeData& other) {
  44. m_dt = other.m_dt->cloneDateTime();
  45. return *this;
  46. }
  47. Variant sleep() const {
  48. return init_null();
  49. }
  50. void wakeup(const Variant& content, ObjectData* obj) {}
  51. int64_t getTimestamp() const {
  52. bool err = false;
  53. return m_dt->toTimeStamp(err);
  54. }
  55. String format(const String& format) const {
  56. return m_dt->toString(format, false);
  57. }
  58. Array getDebugInfo() const;
  59. static int64_t getTimestamp(const Object& obj);
  60. static int64_t getTimestamp(const ObjectData* od);
  61. static Object wrap(SmartPtr<DateTime> dt);
  62. static SmartPtr<DateTime> unwrap(const Object& datetime);
  63. static Class* getClass();
  64. SmartPtr<DateTime> m_dt;
  65. static Class* s_class;
  66. static const StaticString s_className;
  67. };
  68. Object HHVM_METHOD(DateTime, add,
  69. const Object& interval);
  70. void HHVM_METHOD(DateTime, __construct,
  71. const String& time = "now",
  72. const Variant& timezone = null_variant);
  73. Variant HHVM_STATIC_METHOD(DateTime, createFromFormat,
  74. const String& format,
  75. const String& time,
  76. const Variant& timezone /*= null_variant */);
  77. Object HHVM_METHOD(DateTime, diff,
  78. const Variant& datetime2,
  79. const Variant& absolute);
  80. String HHVM_METHOD(DateTime, format,
  81. const Variant& format);
  82. Array HHVM_STATIC_METHOD(DateTime, getLastErrors);
  83. int64_t HHVM_METHOD(DateTime, getOffset);
  84. int64_t HHVM_METHOD(DateTime, gettimestamp);
  85. Variant HHVM_METHOD(DateTime, getTimezone);
  86. Object HHVM_METHOD(DateTime, modify,
  87. const String& modify);
  88. Object HHVM_METHOD(DateTime, setDate,
  89. int64_t year,
  90. int64_t month,
  91. int64_t day);
  92. Object HHVM_METHOD(DateTime, setISODate,
  93. int64_t year,
  94. int64_t week,
  95. int64_t day /*= 1*/);
  96. Object HHVM_METHOD(DateTime, setTime,
  97. int64_t hour,
  98. int64_t minute,
  99. int64_t second /*= 0*/);
  100. Object HHVM_METHOD(DateTime, setTimestamp,
  101. int64_t unixtimestamp);
  102. Object HHVM_METHOD(DateTime, setTimezone,
  103. const Object& timezone);
  104. Object HHVM_METHOD(DateTime, sub,
  105. const Object& interval);
  106. Array HHVM_METHOD(DateTime, __sleep);
  107. void HHVM_METHOD(DateTime, __wakeup);
  108. Array HHVM_METHOD(DateTime, __debuginfo);
  109. ///////////////////////////////////////////////////////////////////////////////
  110. // class DateTimeZone
  111. extern const int64_t q_DateTimeZone$$AFRICA;
  112. extern const int64_t q_DateTimeZone$$AMERICA;
  113. extern const int64_t q_DateTimeZone$$ANTARCTICA;
  114. extern const int64_t q_DateTimeZone$$ARCTIC;
  115. extern const int64_t q_DateTimeZone$$ASIA;
  116. extern const int64_t q_DateTimeZone$$ATLANTIC;
  117. extern const int64_t q_DateTimeZone$$AUSTRALIA;
  118. extern const int64_t q_DateTimeZone$$EUROPE;
  119. extern const int64_t q_DateTimeZone$$INDIAN;
  120. extern const int64_t q_DateTimeZone$$PACIFIC;
  121. extern const int64_t q_DateTimeZone$$UTC;
  122. extern const int64_t q_DateTimeZone$$ALL;
  123. extern const int64_t q_DateTimeZone$$ALL_WITH_BC;
  124. extern const int64_t q_DateTimeZone$$PER_COUNTRY;
  125. class DateTimeZoneData {
  126. public:
  127. DateTimeZoneData() {}
  128. DateTimeZoneData(const DateTimeZoneData&) = delete;
  129. DateTimeZoneData& operator=(const DateTimeZoneData& other) {
  130. m_tz = other.m_tz->cloneTimeZone();
  131. return *this;
  132. }
  133. String getName() const {
  134. return m_tz->name();
  135. }
  136. static Object wrap(SmartPtr<TimeZone> tz);
  137. static SmartPtr<TimeZone> unwrap(const Object& timezone);
  138. static Class* getClass();
  139. SmartPtr<TimeZone> m_tz;
  140. static Class* s_class;
  141. static const StaticString s_className;
  142. };
  143. void HHVM_METHOD(DateTimeZone, __construct,
  144. const String& timezone);
  145. Array HHVM_METHOD(DateTimeZone, getLocation);
  146. String HHVM_METHOD(DateTimeZone, getName);
  147. int64_t HHVM_METHOD(DateTimeZone, getOffset,
  148. const Object& datetime);
  149. Array HHVM_METHOD(DateTimeZone, getTransitions,
  150. int64_t timestamp_begin = k_PHP_INT_MIN,
  151. int64_t timestamp_end = k_PHP_INT_MAX);
  152. Array HHVM_STATIC_METHOD(DateTimeZone, listAbbreviations);
  153. Variant HHVM_STATIC_METHOD(DateTimeZone, listIdentifiers,
  154. int64_t what,
  155. const String& country);
  156. ///////////////////////////////////////////////////////////////////////////////
  157. // class DateInterval
  158. class DateIntervalData {
  159. public:
  160. DateIntervalData() {}
  161. DateIntervalData(const DateIntervalData&) = delete;
  162. DateIntervalData& operator=(const DateIntervalData& other) {
  163. m_di = other.m_di->cloneDateInterval();
  164. return *this;
  165. }
  166. static Object wrap(SmartPtr<DateInterval> di);
  167. static SmartPtr<DateInterval> unwrap(const Object& di);
  168. static Class* getClass();
  169. SmartPtr<DateInterval> m_di;
  170. static Class* s_class;
  171. static const StaticString s_className;
  172. };
  173. void HHVM_METHOD(DateInterval, __construct,
  174. const String& interval_spec);
  175. Variant HHVM_METHOD(DateInterval, __get,
  176. Variant member);
  177. Variant HHVM_METHOD(DateInterval, __set,
  178. Variant member,
  179. Variant value);
  180. Object HHVM_STATIC_METHOD(DateInterval, createFromDateString,
  181. const String& time);
  182. String HHVM_METHOD(DateInterval, format,
  183. const String& format);
  184. ///////////////////////////////////////////////////////////////////////////////
  185. // timestamp
  186. Variant HHVM_FUNCTION(gettimeofday,
  187. bool return_float = false);
  188. Variant HHVM_FUNCTION(microtime,
  189. bool get_as_float = false);
  190. int64_t HHVM_FUNCTION(time);
  191. Variant HHVM_FUNCTION(mktime,
  192. int64_t hour,
  193. int64_t minute,
  194. int64_t second,
  195. int64_t month,
  196. int64_t day,
  197. int64_t year);
  198. Variant HHVM_FUNCTION(gmmktime,
  199. int64_t hour,
  200. int64_t minute,
  201. int64_t second,
  202. int64_t month,
  203. int64_t day,
  204. int64_t year);
  205. TypedValue* HHVM_FN(idate)(ActRec* ar);
  206. TypedValue* HHVM_FN(date)(ActRec* ar);
  207. TypedValue* HHVM_FN(gmdate)(ActRec* ar);
  208. TypedValue* HHVM_FN(strftime)(ActRec* ar);
  209. TypedValue* HHVM_FN(gmstrftime)(ActRec* ar);
  210. TypedValue* HHVM_FN(getdate)(ActRec* ar);
  211. TypedValue* HHVM_FN(localtime)(ActRec* ar);
  212. Variant HHVM_FUNCTION(strptime,
  213. const String& date,
  214. const String& format);
  215. TypedValue* HHVM_FN(strtotime)(ActRec* ar);
  216. ///////////////////////////////////////////////////////////////////////////////
  217. // timezone
  218. String HHVM_FUNCTION(date_default_timezone_get);
  219. bool HHVM_FUNCTION(date_default_timezone_set,
  220. const String& name);
  221. Variant HHVM_FUNCTION(timezone_name_from_abbr,
  222. const String& abbr,
  223. int gmtoffset = -1,
  224. int isdst = 1);
  225. String HHVM_FUNCTION(timezone_version_get);
  226. ///////////////////////////////////////////////////////////////////////////////
  227. // datetime
  228. bool HHVM_FUNCTION(checkdate,
  229. int month,
  230. int day,
  231. int year);
  232. Variant HHVM_FUNCTION(date_create,
  233. const Variant& time = null_variant,
  234. const Variant& timezone = null_variant);
  235. String HHVM_FUNCTION(date_format,
  236. const Object& datetime,
  237. const String& format);
  238. Variant HHVM_FUNCTION(date_parse,
  239. const String& date);
  240. Object HHVM_FUNCTION(date_sub,
  241. const Object& datetime,
  242. const Object& interval);
  243. ///////////////////////////////////////////////////////////////////////////////
  244. // sun
  245. double get_date_default_latitude();
  246. double get_date_default_longitude();
  247. double get_date_default_sunset_zenith();
  248. double get_date_default_sunrise_zenith();
  249. double get_date_default_gmt_offset();
  250. Array HHVM_FUNCTION(date_sun_info,
  251. int64_t ts,
  252. double latitude,
  253. double longitude);
  254. TypedValue* HHVM_FN(date_sunrise)(ActRec* ar);
  255. TypedValue* HHVM_FN(date_sunset)(ActRec* ar);
  256. ///////////////////////////////////////////////////////////////////////////////
  257. }
  258. #endif // incl_HPHP_EXT_DATETIME_H_