v8/test/mjsunit/tzoffset-transition-moscow.js
Jungshik Shin 1d3a87bd1c Reland "Implement a new spec for timezone offset calculation"
This is a reland of dbdede0101
after a webkit layout test (geolocation-api/timestamp.html) was
fixed by
https://chromium-review.googlesource.com/c/chromium/src/+/994343 .

Original change's description:
> Implement a new spec for timezone offset calculation
>
> https://github.com/tc39/ecma262/pull/778 was recently merged
> to Ecma 262.
>
> It changes the way to convert between "local time" and UTC in such
> a way that it'd work for all timezones whether or not there has
> been any change in the timezone offset of the standard time. For
> instance, Europe/Moscow and some parts of US state of Indiana have
> changed the standard (non-DST) timezone offset a few times. The
> previous spec assumes that the the standard timezone offset is
> constant, but the new spec take into account the offset change
> history.
>
> In addition, it specifies a new way to calculate the timezone
> offset during a timezone transition (either in and
> out of DST or timezone offset shift).
>
> During a negative transition (e.g.  fall backward / getting
> out of DST), repeated times are to be interpreted as if the
> offset before the transition is in effect.
>
> During a positive transition (e.g. spring forward / getting
> into DST), skipped times are to be treated similarly. That
> is, they are to be interpreted as if the offset before the
> transition is in effect.
>
> With icu-timezone-data, v8 is compliant to the new spec for the
> past and the future as well as now whether or not the standard
> timezone offset of a given timezone has changed over time
> (e.g. Europe/Moscow, Pacific/Apia). With icu-timezone-data,
> Australia/Lord_Howe (30 minute DST change) also works per spec.
>
> Without icu-timezone-data, it works only for timezones of which
> the standard timezone offset is the same as the current offset
> (e.g. most North American timezones other than parts of Indiana)
> and of which the DST shift is an hour. For instance, it doesn't work
> for Europe/Moscow in 2010 when the standard timezone offset was
> +4h because the current (2018) standard timezone offset is +3h. Neither
> does it for Lord Howe in Australia with the DST shift of 0.5 hr.
>
> This CL used to require one of the two ICU CLs below, but not
> any more.
>
>   https://chromium-review.googlesource.com/c/chromium/deps/icu/+/572652
>   https://chromium-review.googlesource.com/851265  (a proposed CL to the
>   upstream ICU).
>
> Bug: v8:3547,chromium:417640,v8:5714
> Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
> Change-Id: Ib162295da5bee31b2390bd0918157014aebd3e33
> Reviewed-on: https://chromium-review.googlesource.com/572148
> Commit-Queue: Jungshik Shin <jshin@chromium.org>
> Reviewed-by: Daniel Ehrenberg <littledan@chromium.org>
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#52332}

Bug: v8:3547, chromium:417640, v8:5714
Change-Id: I47536c111143f75e3cfeecf5d9761c43a98a10f5
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Reviewed-on: https://chromium-review.googlesource.com/995971
Commit-Queue: Jungshik Shin <jshin@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52372}
2018-04-04 22:42:30 +00:00

86 lines
3.3 KiB
JavaScript

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --icu-timezone-data
// Environment Variables: TZ=Europe/Moscow
// https://www.timeanddate.com/time/zone/russia/moscow
// 2010-03-28T02:00 : UTC+3 => UTC+4
assertEquals(new Date(Date.UTC(2010, 2, 27, 22, 59)),
new Date(2010, 2, 28, 1, 59));
assertEquals(new Date(Date.UTC(2010, 2, 27, 23)),
new Date(2010, 2, 28, 2));
assertEquals(new Date(Date.UTC(2010, 2, 27, 23, 30)),
new Date(2010, 2, 28, 2, 30));
assertEquals(new Date(Date.UTC(2010, 2, 27, 23)),
new Date(2010, 2, 28, 3));
assertEquals(new Date(Date.UTC(2010, 2, 27, 23, 30)),
new Date(2010, 2, 28, 3, 30));
assertEquals((new Date(2010, 2, 28, 3, 30)).getTimezoneOffset(),
(new Date(2010, 2, 28, 2, 30)).getTimezoneOffset());
// 2010-10-31T03:00 : UTC+4 => UTC+3
assertEquals(new Date(Date.UTC(2010, 9, 30, 21, 59)),
new Date(2010, 9, 31, 1, 59));
assertEquals(new Date(Date.UTC(2010, 9, 30, 22)),
new Date(2010, 9, 31, 2));
assertEquals(new Date(Date.UTC(2010, 9, 30, 22, 30)),
new Date(2010, 9, 31, 2, 30));
assertEquals(new Date(Date.UTC(2010, 9, 30, 22, 59)),
new Date(2010, 9, 31, 2, 59))
assertEquals(new Date(Date.UTC(2010, 9, 31, 0)),
new Date(2010, 9, 31, 3))
assertEquals(new Date(Date.UTC(2010, 9, 31, 0, 30)),
new Date(2010, 9, 31, 3, 30))
// 2011-03-27T02:00 : UTC+3 => UTC+4
assertEquals(new Date(Date.UTC(2011, 2, 26, 22, 59)),
new Date(2011, 2, 27, 1, 59))
assertEquals(new Date(Date.UTC(2011, 2, 26, 23)),
new Date(2011, 2, 27, 2));
assertEquals(new Date(Date.UTC(2011, 2, 26, 23, 30)),
new Date(2011, 2, 27, 2, 30));
assertEquals(new Date(Date.UTC(2011, 2, 26, 23)),
new Date(2011, 2, 27, 3));
assertEquals(new Date(Date.UTC(2011, 2, 26, 23, 30)),
new Date(2011, 2, 27, 3, 30));
assertEquals((new Date(2011, 2, 27, 3, 30)).getTimezoneOffset(),
(new Date(2011, 2, 27, 2, 30)).getTimezoneOffset());
// No daylight saving time in 2012, 2013: UTC+4 year-round
assertEquals(new Date(Date.UTC(2012, 5, 21, 0)),
new Date(2012, 5, 21, 4))
assertEquals(new Date(Date.UTC(2012, 11, 21, 0)),
new Date(2012, 11, 21, 4))
assertEquals(new Date(Date.UTC(2013, 5, 21, 0)),
new Date(2013, 5, 21, 4))
assertEquals(new Date(Date.UTC(2013, 11, 21, 0)),
new Date(2013, 11, 21, 4))
// 2014-10-26T0200: UTC+4 => UTC+3 (year-round)
assertEquals(new Date(Date.UTC(2014, 9, 25, 20, 59)),
new Date(2014, 9, 26, 0, 59));
assertEquals(new Date(Date.UTC(2014, 9, 25, 21)),
new Date(2014, 9, 26, 1));
assertEquals(new Date(Date.UTC(2014, 9, 25, 21, 30)),
new Date(2014, 9, 26, 1, 30));
assertEquals(new Date(Date.UTC(2014, 9, 25, 21, 59)),
new Date(2014, 9, 26, 1, 59))
assertEquals(new Date(Date.UTC(2014, 9, 25, 23)),
new Date(2014, 9, 26, 2))
assertEquals(new Date(Date.UTC(2014, 9, 25, 23, 1)),
new Date(2014, 9, 26, 2, 1))
assertEquals(new Date(Date.UTC(2014, 11, 21, 0)),
new Date(2014, 11, 21, 3))
assertEquals(new Date(Date.UTC(2015, 5, 21, 0)),
new Date(2015, 5, 21, 3))
assertEquals(new Date(Date.UTC(2015, 11, 21, 0)),
new Date(2015, 11, 21, 3))
assertEquals(new Date(Date.UTC(2016, 5, 21, 0)),
new Date(2016, 5, 21, 3))
assertEquals(new Date(Date.UTC(2015, 11, 21, 0)),
new Date(2015, 11, 21, 3))