PageRenderTime 52ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/soitun/hiphop-php
C Header | 256 lines | 196 code | 29 blank | 31 comment | 0 complexity | 4f704ac67058b8b3fb3a97bf259a1713 MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010-present 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. #pragma once
  18. #include "hphp/runtime/ext/extension.h"
  19. #include "hphp/runtime/base/timestamp.h"
  20. #include "hphp/runtime/base/datetime.h"
  21. #include "hphp/runtime/base/timezone.h"
  22. #include "hphp/runtime/base/dateinterval.h"
  23. #include "hphp/runtime/ext/std/ext_std_misc.h"
  24. namespace HPHP {
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // class DateTime
  27. struct DateTimeData {
  28. DateTimeData() {}
  29. DateTimeData(const DateTimeData&) = delete;
  30. DateTimeData& operator=(const DateTimeData& other) {
  31. m_dt = other.m_dt ? other.m_dt->cloneDateTime() : req::ptr<DateTime>{};
  32. return *this;
  33. }
  34. Variant sleep() const {
  35. return init_null();
  36. }
  37. void wakeup(const Variant& /*content*/, ObjectData* /*obj*/) {}
  38. int64_t getTimestamp() const {
  39. assertx(m_dt);
  40. bool err = false;
  41. return m_dt->toTimeStamp(err);
  42. }
  43. String format(const String& format) const {
  44. assertx(m_dt);
  45. return m_dt->toString(format, false);
  46. }
  47. Array getDebugInfo() const;
  48. static int64_t getTimestamp(const Object& obj);
  49. static int64_t getTimestamp(const ObjectData* od);
  50. static int compare(const Object& left, const Object& right);
  51. static int compare(const ObjectData* left, const ObjectData* right);
  52. static Object wrap(req::ptr<DateTime> dt);
  53. static req::ptr<DateTime> unwrap(const Object& datetime);
  54. static Class* getClass();
  55. req::ptr<DateTime> m_dt;
  56. static Class* s_class;
  57. static const StaticString s_className;
  58. };
  59. void HHVM_METHOD(DateTime, __construct,
  60. const String& time = "now",
  61. const Variant& timezone = uninit_variant);
  62. Variant HHVM_STATIC_METHOD(DateTime, createFromFormat,
  63. const String& format,
  64. const String& time,
  65. const Variant& timezone /*= uninit_variant */);
  66. Variant HHVM_METHOD(DateTime, diff,
  67. const Variant& datetime2,
  68. const Variant& absolute);
  69. String HHVM_METHOD(DateTime, format,
  70. const Variant& format);
  71. Array HHVM_STATIC_METHOD(DateTime, getLastErrors);
  72. int64_t HHVM_METHOD(DateTime, getOffset);
  73. int64_t HHVM_METHOD(DateTime, gettimestamp);
  74. Variant HHVM_METHOD(DateTime, getTimezone);
  75. Variant HHVM_METHOD(DateTime, modify,
  76. const String& modify);
  77. Object HHVM_METHOD(DateTime, setDate,
  78. int64_t year,
  79. int64_t month,
  80. int64_t day);
  81. Object HHVM_METHOD(DateTime, setISODate,
  82. int64_t year,
  83. int64_t week,
  84. int64_t day /*= 1*/);
  85. Object HHVM_METHOD(DateTime, setTime,
  86. int64_t hour,
  87. int64_t minute,
  88. int64_t second /*= 0*/);
  89. Object HHVM_METHOD(DateTime, setTimestamp,
  90. int64_t unixtimestamp);
  91. Variant HHVM_METHOD(DateTime, setTimezone,
  92. const Object& timezone);
  93. Variant HHVM_METHOD(DateTime, add,
  94. const Object& interval);
  95. Variant HHVM_METHOD(DateTime, sub,
  96. const Object& interval);
  97. Array HHVM_METHOD(DateTime, __sleep);
  98. void HHVM_METHOD(DateTime, __wakeup);
  99. Array HHVM_METHOD(DateTime, __debugInfo);
  100. ///////////////////////////////////////////////////////////////////////////////
  101. // class DateTimeZone
  102. struct DateTimeZoneData {
  103. DateTimeZoneData() {}
  104. DateTimeZoneData(const DateTimeZoneData&) = delete;
  105. DateTimeZoneData& operator=(const DateTimeZoneData& other) {
  106. m_tz = other.m_tz ? other.m_tz->cloneTimeZone() : req::ptr<TimeZone>{};
  107. return *this;
  108. }
  109. String getName() const {
  110. assertx(m_tz);
  111. return m_tz->name();
  112. }
  113. Array getDebugInfo() const;
  114. static Object wrap(req::ptr<TimeZone> tz);
  115. static req::ptr<TimeZone> unwrap(const Object& timezone);
  116. static Class* getClass();
  117. req::ptr<TimeZone> m_tz;
  118. static Class* s_class;
  119. static const StaticString s_className;
  120. static const int64_t AFRICA = 1;
  121. static const int64_t AMERICA = 2;
  122. static const int64_t ANTARCTICA = 4;
  123. static const int64_t ARCTIC = 8;
  124. static const int64_t ASIA = 16;
  125. static const int64_t ATLANTIC = 32;
  126. static const int64_t AUSTRALIA = 64;
  127. static const int64_t EUROPE = 128;
  128. static const int64_t INDIAN = 256;
  129. static const int64_t PACIFIC = 512;
  130. static const int64_t UTC = 1024;
  131. static const int64_t ALL = 2047;
  132. static const int64_t ALL_WITH_BC = 4095;
  133. static const int64_t PER_COUNTRY = 4096;
  134. };
  135. void HHVM_METHOD(DateTimeZone, __construct,
  136. const String& timezone);
  137. Array HHVM_METHOD(DateTimeZone, getLocation);
  138. String HHVM_METHOD(DateTimeZone, getName);
  139. Array HHVM_METHOD(DateTimeZone, __debugInfo);
  140. Variant HHVM_METHOD(DateTimeZone, getOffset,
  141. const Object& datetime);
  142. TypedValue HHVM_METHOD(DateTimeZone, getTransitions,
  143. int64_t timestamp_begin = k_PHP_INT_MIN,
  144. int64_t timestamp_end = k_PHP_INT_MAX);
  145. Array HHVM_STATIC_METHOD(DateTimeZone, listAbbreviations);
  146. Variant HHVM_STATIC_METHOD(DateTimeZone, listIdentifiers,
  147. int64_t what,
  148. const String& country);
  149. ///////////////////////////////////////////////////////////////////////////////
  150. // class DateInterval
  151. struct DateIntervalData {
  152. DateIntervalData() {}
  153. DateIntervalData(const DateIntervalData&) = delete;
  154. DateIntervalData& operator=(const DateIntervalData& other) {
  155. m_di =
  156. other.m_di ? other.m_di->cloneDateInterval() : req::ptr<DateInterval>{};
  157. return *this;
  158. }
  159. static Object wrap(req::ptr<DateInterval> di);
  160. static req::ptr<DateInterval> unwrap(const Object& di);
  161. static Class* getClass();
  162. req::ptr<DateInterval> m_di;
  163. static Class* s_class;
  164. static const StaticString s_className;
  165. };
  166. void HHVM_METHOD(DateInterval, __construct,
  167. const String& interval_spec);
  168. Object HHVM_STATIC_METHOD(DateInterval, createFromDateString,
  169. const String& time);
  170. String HHVM_METHOD(DateInterval, format,
  171. const String& format);
  172. ///////////////////////////////////////////////////////////////////////////////
  173. // timestamp
  174. Variant HHVM_FUNCTION(gettimeofday,
  175. bool return_float = false);
  176. Variant HHVM_FUNCTION(microtime,
  177. bool get_as_float = false);
  178. int64_t HHVM_FUNCTION(time);
  179. Variant HHVM_FUNCTION(mktime,
  180. int64_t hour,
  181. int64_t minute,
  182. int64_t second,
  183. int64_t month,
  184. int64_t day,
  185. int64_t year);
  186. Variant HHVM_FUNCTION(gmmktime,
  187. int64_t hour,
  188. int64_t minute,
  189. int64_t second,
  190. int64_t month,
  191. int64_t day,
  192. int64_t year);
  193. Variant HHVM_FUNCTION(strptime,
  194. const String& date,
  195. const String& format);
  196. ///////////////////////////////////////////////////////////////////////////////
  197. // timezone
  198. String HHVM_FUNCTION(date_default_timezone_get);
  199. bool HHVM_FUNCTION(date_default_timezone_set,
  200. const String& name);
  201. Variant HHVM_FUNCTION(timezone_name_from_abbr,
  202. const String& abbr,
  203. int64_t gmtoffset = -1,
  204. int64_t isdst = 1);
  205. String HHVM_FUNCTION(timezone_version_get);
  206. ///////////////////////////////////////////////////////////////////////////////
  207. // datetime
  208. bool HHVM_FUNCTION(checkdate,
  209. int64_t month,
  210. int64_t day,
  211. int64_t year);
  212. Variant HHVM_FUNCTION(date_create,
  213. const Variant& time = uninit_variant,
  214. const Variant& timezone = uninit_variant);
  215. Variant HHVM_FUNCTION(date_format,
  216. const Object& datetime,
  217. const String& format);
  218. Variant HHVM_FUNCTION(date_parse,
  219. const String& date);
  220. ///////////////////////////////////////////////////////////////////////////////
  221. // sun
  222. Array HHVM_FUNCTION(date_sun_info,
  223. int64_t ts,
  224. double latitude,
  225. double longitude);
  226. ///////////////////////////////////////////////////////////////////////////////
  227. }