Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: runtime/lib/date_patch.dart

Issue 1845483002: Fix core lib DateTime in the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: adress comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/date.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/date_patch.dart
diff --git a/runtime/lib/date_patch.dart b/runtime/lib/date_patch.dart
index 4697901739fb7b71363e9c8f1cd84358c5ec6d07..1ecf8129949739a0477559b80a3b75530fde585a 100644
--- a/runtime/lib/date_patch.dart
+++ b/runtime/lib/date_patch.dart
@@ -284,14 +284,24 @@ patch class DateTime {
}
if (!isUtc) {
- // Note that we need to remove the local timezone adjustement before
+ // Note that we need to remove the local timezone adjustment before
// asking for the correct zone offset.
int adjustment = _localTimeZoneAdjustmentInSeconds() *
Duration.MICROSECONDS_PER_SECOND;
+ // The adjustment is independent of the actual date and of the daylight
+ // saving time. It is positive east of the Prime Meridian and negative
+ // west of it, e.g. -28800 sec for America/Los_Angeles timezone.
int zoneOffset =
_timeZoneOffsetInSeconds(microsecondsSinceEpoch - adjustment);
+ // The zoneOffset depends on the actual date and reflects any daylight
+ // saving time and/or historical deviation relative to UTC time.
+ // It is positive east of the Prime Meridian and negative west of it,
+ // e.g. -25200 sec for America/Los_Angeles timezone during DST.
microsecondsSinceEpoch -= zoneOffset * Duration.MICROSECONDS_PER_SECOND;
+ // The resulting microsecondsSinceEpoch value is therefore the calculated
+ // UTC value decreased by a (positive if east of GMT) timezone adjustment
+ // and decreased by typically one hour if DST is in effect.
}
if (microsecondsSinceEpoch.abs() >
_MAX_MILLISECONDS_SINCE_EPOCH * Duration.MICROSECONDS_PER_MILLISECOND) {
@@ -314,7 +324,8 @@ patch class DateTime {
* Adapted from V8's date implementation. See ECMA 262 - 15.9.1.9.
*/
static int _equivalentYear(int year) {
- // Returns the week day (in range 0 - 6).
+ // Returns year y so that _weekDay(y) == _weekDay(year).
+ // _weekDay returns the week day (in range 0 - 6).
// 1/1/1956 was a Sunday (i.e. weekday 0). 1956 was a leap-year.
// 1/1/1967 was a Sunday (i.e. weekday 0).
// Without leap years a subsequent year has a week day + 1 (for example
@@ -352,22 +363,24 @@ patch class DateTime {
}
/**
- * Returns a date in seconds that is equivalent to the current date. An
- * equivalent date has the same fields (`month`, `day`, etc.) as the
- * [this], but the `year` is in the range [1970..2037].
+ * Returns a date in seconds that is equivalent to the given
+ * date in microseconds [microsecondsSinceEpoch]. An equivalent
+ * date has the same fields (`month`, `day`, etc.) as the given
+ * date, but the `year` is in the range [1901..2038].
*
* * The time since the beginning of the year is the same.
- * * If [this] is in a leap year then the returned seconds are in a leap
- * year, too.
- * * The week day of [this] is the same as the one for the returned date.
+ * * If the given date is in a leap year then the returned
+ * seconds are in a leap year, too.
+ * * The week day of given date is the same as the one for the
+ * returned date.
*/
static int _equivalentSeconds(int microsecondsSinceEpoch) {
- const int CUT_OFF_SECONDS = 2100000000;
+ const int CUT_OFF_SECONDS = 0x7FFFFFFF;
int secondsSinceEpoch = _flooredDivision(microsecondsSinceEpoch,
Duration.MICROSECONDS_PER_SECOND);
- if (secondsSinceEpoch < 0 || secondsSinceEpoch >= CUT_OFF_SECONDS) {
+ if (secondsSinceEpoch.abs() > CUT_OFF_SECONDS) {
int year = _yearsFromSecondsSinceEpoch(secondsSinceEpoch);
int days = _dayFromYear(year);
int equivalentYear = _equivalentYear(year);
« no previous file with comments | « runtime/lib/date.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698