| 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/globals.h" | 10 #include "src/globals.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return base::OS::LocalTimezone(static_cast<double>(time_ms), tz_cache_); | 96 return base::OS::LocalTimezone(static_cast<double>(time_ms), tz_cache_); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // ECMA 262 - 15.9.5.26 | 99 // ECMA 262 - 15.9.5.26 |
| 100 int TimezoneOffset(int64_t time_ms) { | 100 int TimezoneOffset(int64_t time_ms) { |
| 101 int64_t local_ms = ToLocal(time_ms); | 101 int64_t local_ms = ToLocal(time_ms); |
| 102 return static_cast<int>((time_ms - local_ms) / kMsPerMin); | 102 return static_cast<int>((time_ms - local_ms) / kMsPerMin); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // ECMA 262 - 15.9.1.9 | 105 // ECMA 262 - 15.9.1.9 |
| 106 // LocalTime(t) = t + LocalTZA + DaylightSavingTA(t) |
| 107 // ECMA 262 assumes that DaylightSavingTA is computed using UTC time, |
| 108 // but we fetch DST from OS using local time, therefore we need: |
| 109 // LocalTime(t) = t + LocalTZA + DaylightSavingTA(t + LocalTZA). |
| 106 int64_t ToLocal(int64_t time_ms) { | 110 int64_t ToLocal(int64_t time_ms) { |
| 107 return time_ms + LocalOffsetInMs() + DaylightSavingsOffsetInMs(time_ms); | 111 time_ms += LocalOffsetInMs(); |
| 112 return time_ms + DaylightSavingsOffsetInMs(time_ms); |
| 108 } | 113 } |
| 109 | 114 |
| 110 // ECMA 262 - 15.9.1.9 | 115 // ECMA 262 - 15.9.1.9 |
| 116 // UTC(t) = t - LocalTZA - DaylightSavingTA(t - LocalTZA) |
| 117 // ECMA 262 assumes that DaylightSavingTA is computed using UTC time, |
| 118 // but we fetch DST from OS using local time, therefore we need: |
| 119 // UTC(t) = t - LocalTZA - DaylightSavingTA(t). |
| 111 int64_t ToUTC(int64_t time_ms) { | 120 int64_t ToUTC(int64_t time_ms) { |
| 112 time_ms -= LocalOffsetInMs(); | 121 return time_ms - LocalOffsetInMs() - DaylightSavingsOffsetInMs(time_ms); |
| 113 return time_ms - DaylightSavingsOffsetInMs(time_ms); | |
| 114 } | 122 } |
| 115 | 123 |
| 116 | 124 |
| 117 // Computes a time equivalent to the given time according | 125 // Computes a time equivalent to the given time according |
| 118 // to ECMA 262 - 15.9.1.9. | 126 // to ECMA 262 - 15.9.1.9. |
| 119 // The issue here is that some library calls don't work right for dates | 127 // The issue here is that some library calls don't work right for dates |
| 120 // that cannot be represented using a non-negative signed 32 bit integer | 128 // that cannot be represented using a non-negative signed 32 bit integer |
| 121 // (measured in whole seconds based on the 1970 epoch). | 129 // (measured in whole seconds based on the 1970 epoch). |
| 122 // We solve this by mapping the time to a year with same leap-year-ness | 130 // We solve this by mapping the time to a year with same leap-year-ness |
| 123 // and same starting day for the year. The ECMAscript specification says | 131 // and same starting day for the year. The ECMAscript specification says |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 int ymd_year_; | 242 int ymd_year_; |
| 235 int ymd_month_; | 243 int ymd_month_; |
| 236 int ymd_day_; | 244 int ymd_day_; |
| 237 | 245 |
| 238 base::TimezoneCache* tz_cache_; | 246 base::TimezoneCache* tz_cache_; |
| 239 }; | 247 }; |
| 240 | 248 |
| 241 } } // namespace v8::internal | 249 } } // namespace v8::internal |
| 242 | 250 |
| 243 #endif | 251 #endif |
| OLD | NEW |