2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
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 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_TIMEZONE_H_
18 #define incl_HPHP_TIMEZONE_H_
20 #include "hphp/runtime/base/resource-data.h"
21 #include "hphp/runtime/base/type-string.h"
22 #include "hphp/runtime/ext/std/ext_std_misc.h"
35 ///////////////////////////////////////////////////////////////////////////////
38 * Handles all timezone related functions.
40 struct TimeZone
: SweepableResourceData
{
41 DECLARE_RESOURCE_ALLOCATION(TimeZone
);
44 * Get/set current timezone that controls how local time is interpreted.
46 static String
CurrentName(); // current timezone's name
47 static req::ptr
<TimeZone
> Current(); // current timezone
48 static bool SetCurrent(const char* name
); // returns false if invalid
51 * TimeZone database queries.
53 static bool IsValid(const char* name
);
54 static Array
GetAbbreviations();
55 static String
AbbreviationToName(String abbr
, int utcoffset
= -1,
60 * Constructing a timezone object by name or a raw pointer (internal).
63 explicit TimeZone(const String
& name
);
64 explicit TimeZone(timelib_tzinfo
*tzi
);
66 static StaticString
& classnameof() {
67 static StaticString
result("TimeZone");
70 // overriding ResourceData
71 const String
& o_getClassNameHook() const override
{ return classnameof(); }
74 * Whether this represents a valid timezone.
76 bool isValid() const {
80 case TIMELIB_ZONETYPE_ID
:
82 case TIMELIB_ZONETYPE_OFFSET
:
83 case TIMELIB_ZONETYPE_ABBR
:
86 always_assert(false && "invalid tztype");
90 * Get timezone's name or abbreviation.
93 String
abbr(int type
= 0) const;
97 * Get offset from UTC at the specified timestamp under this timezone.
99 int offset(int64_t timestamp
) const;
102 * Test whether it was running under DST at specified timestamp.
104 bool dst(int64_t timestamp
) const;
107 * Query transition times for DST.
109 Array
transitions(int64_t timestamp_begin
= k_PHP_INT_MIN
,
110 int64_t timestamp_end
= k_PHP_INT_MAX
) const;
113 * Get information about a timezone
115 Array
getLocation() const;
118 * Timezone Database version
120 static String
getVersion() {
121 const timelib_tzdb
* db
= GetDatabase();
122 return String(db
->version
, CopyString
);
126 * Make a copy of this timezone object, so it can be changed independently.
128 req::ptr
<TimeZone
> cloneTimeZone() const;
131 friend struct DateTime
;
132 friend struct TimeStamp
;
133 friend struct DateInterval
;
136 * Returns raw pointer. For internal use only.
138 * If type() !== TIMELIB_ZONETYPE_ID, this will definitely return nullptr,
141 timelib_tzinfo
*getTZInfo() const { return m_tzi
; }
144 static const timelib_tzdb
*GetDatabase();
147 * Look up cache and if found return it, otherwise, read it from database.
149 static timelib_tzinfo
* GetTimeZoneInfoRaw(char* name
, const timelib_tzdb
* db
);
151 unsigned int m_tztype
= 0;
152 timelib_tzinfo
* m_tzi
= nullptr;
158 ///////////////////////////////////////////////////////////////////////////////
160 void timezone_init();
161 const timelib_tzdb
* timezone_get_tzdb();
162 extern const timelib_tzdb
* (*timezone_raw_get_tzdb
)();
164 ///////////////////////////////////////////////////////////////////////////////
167 #endif // incl_HPHP_TIMEZONE_H_