Add sub-controls for Hack array compat runtime checks
[hiphop-php.git] / hphp / runtime / base / timezone.h
blobf159dd0e98a508d91427c0d56f94f6c5343c8dd3
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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"
24 #include <map>
25 #include <memory>
27 extern "C" {
28 #include <timelib.h>
31 namespace HPHP {
33 struct Array;
35 ///////////////////////////////////////////////////////////////////////////////
37 /**
38 * Handles all timezone related functions.
40 struct TimeZone : SweepableResourceData {
41 DECLARE_RESOURCE_ALLOCATION(TimeZone);
43 /**
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
50 /**
51 * TimeZone database queries.
53 static bool IsValid(const char* name);
54 static Array GetAbbreviations();
55 static String AbbreviationToName(String abbr, int utcoffset = -1,
56 int isdst = 1);
58 public:
59 /**
60 * Constructing a timezone object by name or a raw pointer (internal).
62 TimeZone();
63 explicit TimeZone(const String& name);
64 explicit TimeZone(timelib_tzinfo *tzi);
66 static StaticString& classnameof() {
67 static StaticString result("TimeZone");
68 return result;
70 // overriding ResourceData
71 const String& o_getClassNameHook() const override { return classnameof(); }
73 /**
74 * Whether this represents a valid timezone.
76 bool isValid() const { return get();}
78 /**
79 * Get timezone's name or abbreviation.
81 String name() const;
82 String abbr(int type = 0) const;
84 /**
85 * Get offset from UTC at the specified timestamp under this timezone.
87 int offset(int64_t timestamp) const;
89 /**
90 * Test whether it was running under DST at specified timestamp.
92 bool dst(int64_t timestamp) const;
94 /**
95 * Query transition times for DST.
97 Array transitions(int64_t timestamp_begin = k_PHP_INT_MIN,
98 int64_t timestamp_end = k_PHP_INT_MAX) const;
101 * Get information about a timezone
103 Array getLocation() const;
106 * Timezone Database version
108 static String getVersion() {
109 const timelib_tzdb* db = GetDatabase();
110 return String(db->version, CopyString);
114 * Make a copy of this timezone object, so it can be changed independently.
116 req::ptr<TimeZone> cloneTimeZone() const;
118 protected:
119 friend struct DateTime;
120 friend struct TimeStamp;
121 friend struct DateInterval;
124 * Returns raw pointer. For internal use only.
126 timelib_tzinfo *get() const { return m_tzi; }
128 private:
129 static const timelib_tzdb *GetDatabase();
132 * Look up cache and if found return it, otherwise, read it from database.
134 static timelib_tzinfo* GetTimeZoneInfoRaw(char* name, const timelib_tzdb* db);
136 timelib_tzinfo* m_tzi;
139 ///////////////////////////////////////////////////////////////////////////////
141 void timezone_init();
142 const timelib_tzdb* timezone_get_tzdb();
143 extern const timelib_tzdb* (*timezone_raw_get_tzdb)();
145 ///////////////////////////////////////////////////////////////////////////////
148 #endif // incl_HPHP_TIMEZONE_H_