34 using namespace v8::internal;
39 int year, start_month, start_day, end_month, end_day, offset_sec;
43 : local_offset_(local_offset), rules_(rules), rules_count_(rules_count) {}
47 int days = DaysFromTime(time_sec * 1000);
48 int time_in_day_sec = TimeInDay(time_sec * 1000, days) / 1000;
50 YearMonthDayFromDays(days, &year, &month, &day);
51 Rule* rule = FindRuleFor(year, month, day, time_in_day_sec);
61 Rule* FindRuleFor(
int year,
int month,
int day,
int time_in_day_sec) {
63 for (
int i = 0; i < rules_count_; i++)
64 if (Match(&rules_[i], year, month, day, time_in_day_sec)) {
71 bool Match(Rule* rule,
int year,
int month,
int day,
int time_in_day_sec) {
72 if (rule->year != 0 && rule->year != year)
return false;
73 if (rule->start_month > month)
return false;
74 if (rule->end_month < month)
return false;
75 int start_day = ComputeRuleDay(year, rule->start_month, rule->start_day);
76 if (rule->start_month == month && start_day > day)
return false;
77 if (rule->start_month == month && start_day == day &&
78 2 * 3600 > time_in_day_sec)
80 int end_day = ComputeRuleDay(year, rule->end_month, rule->end_day);
81 if (rule->end_month == month && end_day < day)
return false;
82 if (rule->end_month == month && end_day == day &&
83 2 * 3600 <= time_in_day_sec)
89 int ComputeRuleDay(
int year,
int month,
int day) {
90 if (day != 0)
return day;
91 int days = DaysFromYearMonth(year, month);
93 while (Weekday(days + day) != 6) day++;
102 static int64_t TimeFromYearMonthDay(
DateCache* date_cache,
111 static void CheckDST(int64_t time) {
114 int64_t actual = date_cache->
ToLocal(time);
126 {0, 2, 0, 10, 0, 3600},
127 {2010, 2, 0, 7, 20, 3600},
128 {2010, 7, 20, 8, 10, 0},
129 {2010, 8, 10, 10, 0, 3600},
132 int local_offset_ms = -36000000;
137 reinterpret_cast<Isolate*
>(isolate)->set_date_cache(date_cache);
139 int64_t start_of_2010 = TimeFromYearMonthDay(date_cache, 2010, 0, 1);
140 int64_t start_of_2011 = TimeFromYearMonthDay(date_cache, 2011, 0, 1);
141 int64_t august_20 = TimeFromYearMonthDay(date_cache, 2010, 7, 20);
142 int64_t september_10 = TimeFromYearMonthDay(date_cache, 2010, 8, 10);
143 CheckDST((august_20 + september_10) / 2);
144 CheckDST(september_10);
145 CheckDST(september_10 + 2 * 3600);
146 CheckDST(september_10 + 2 * 3600 - 1000);
147 CheckDST(august_20 + 2 * 3600);
148 CheckDST(august_20 + 2 * 3600 - 1000);
151 for (int64_t time = start_of_2011 + 2 * 3600;
152 time >= start_of_2010;
155 CheckDST(time - 1000);
156 CheckDST(time + 1000);
159 for (
int year = 2100; year >= 2010; year--) {
160 CheckDST(TimeFromYearMonthDay(date_cache, year, 5, 5));
162 CheckDST((august_20 + september_10) / 2);
163 CheckDST(september_10);
164 CheckDST(september_10 + 2 * 3600);
165 CheckDST(september_10 + 2 * 3600 - 1000);
166 CheckDST(august_20 + 2 * 3600);
167 CheckDST(august_20 + 2 * 3600 - 1000);
173 FLAG_allow_natives_syntax =
true;
183 CHECK(date_cache_version->
Get(0)->IsNumber());
184 CHECK_EQ(0.0, date_cache_version->
Get(0)->NumberValue());
189 CHECK(date_cache_version->
Get(0)->IsNumber());
190 CHECK_EQ(1.0, date_cache_version->
Get(0)->NumberValue());
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
#define CHECK_EQ(expected, value)
Local< Value > Get(Handle< Value > key)
DateCacheMock(int local_offset, Rule *rules, int rules_count)
virtual int GetLocalOffsetFromOS()
virtual int GetDaylightSavingsOffsetFromOS(int64_t time_sec)
v8::Isolate * GetIsolate()
virtual int GetLocalOffsetFromOS()
static V8_INLINE Handle< T > Cast(Handle< S > that)
virtual int GetDaylightSavingsOffsetFromOS(int64_t time_sec)
static i::Isolate * i_isolate()
int DaysFromYearMonth(int year, int month)
static const int64_t kMsPerDay
static Local< Context > New(Isolate *isolate, ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
static void DateTimeConfigurationChangeNotification(Isolate *isolate)
int64_t ToLocal(int64_t time_ms)
static v8::Isolate * isolate()