OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_DATE_H_ | 5 #ifndef V8_DATE_H_ |
6 #define V8_DATE_H_ | 6 #define V8_DATE_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/base/timezone-cache.h" | 10 #include "src/base/timezone-cache.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 local_offset_ms_ = GetLocalOffsetFromOS(); | 86 local_offset_ms_ = GetLocalOffsetFromOS(); |
87 } | 87 } |
88 return local_offset_ms_; | 88 return local_offset_ms_; |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 const char* LocalTimezone(int64_t time_ms) { | 92 const char* LocalTimezone(int64_t time_ms) { |
93 if (time_ms < 0 || time_ms > kMaxEpochTimeInMs) { | 93 if (time_ms < 0 || time_ms > kMaxEpochTimeInMs) { |
94 time_ms = EquivalentTime(time_ms); | 94 time_ms = EquivalentTime(time_ms); |
95 } | 95 } |
96 return tz_cache_->LocalTimezone(static_cast<double>(time_ms)); | 96 bool is_dst = DaylightSavingsOffsetInMs(time_ms) != 0; |
| 97 const char** name = is_dst ? &dst_tz_name_ : &tz_name_; |
| 98 if (*name == nullptr) { |
| 99 *name = tz_cache_->LocalTimezone(static_cast<double>(time_ms)); |
| 100 } |
| 101 return *name; |
97 } | 102 } |
98 | 103 |
99 // ECMA 262 - 15.9.5.26 | 104 // ECMA 262 - 15.9.5.26 |
100 int TimezoneOffset(int64_t time_ms) { | 105 int TimezoneOffset(int64_t time_ms) { |
101 int64_t local_ms = ToLocal(time_ms); | 106 int64_t local_ms = ToLocal(time_ms); |
102 return static_cast<int>((time_ms - local_ms) / kMsPerMin); | 107 return static_cast<int>((time_ms - local_ms) / kMsPerMin); |
103 } | 108 } |
104 | 109 |
105 // ECMA 262 - 15.9.1.9 | 110 // ECMA 262 - 15.9.1.9 |
106 // LocalTime(t) = t + LocalTZA + DaylightSavingTA(t) | 111 // LocalTime(t) = t + LocalTZA + DaylightSavingTA(t) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 274 |
270 int local_offset_ms_; | 275 int local_offset_ms_; |
271 | 276 |
272 // Year/Month/Day cache. | 277 // Year/Month/Day cache. |
273 bool ymd_valid_; | 278 bool ymd_valid_; |
274 int ymd_days_; | 279 int ymd_days_; |
275 int ymd_year_; | 280 int ymd_year_; |
276 int ymd_month_; | 281 int ymd_month_; |
277 int ymd_day_; | 282 int ymd_day_; |
278 | 283 |
| 284 // Timezone name cache |
| 285 const char* tz_name_; |
| 286 const char* dst_tz_name_; |
| 287 |
279 base::TimezoneCache* tz_cache_; | 288 base::TimezoneCache* tz_cache_; |
280 }; | 289 }; |
281 | 290 |
282 } // namespace internal | 291 } // namespace internal |
283 } // namespace v8 | 292 } // namespace v8 |
284 | 293 |
285 #endif | 294 #endif |
OLD | NEW |