Skip to content

Commit 8b8137b

Browse files
committed
Adding extended versions of without-utc-offset test.
1 parent dcf25f1 commit 8b8137b

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* This test is an extension of
10+
* https://github.com/tc39/test262/blob/main/test/built-ins/Date/parse/without-utc-offset.js
11+
* This extension checks also the desired behaviour for legacy dates
12+
* (that are not covered by the specification).
13+
*/
14+
15+
load('assert.js');
16+
17+
const timezoneOffsetMS = new Date(0).getTimezoneOffset() * 60000;
18+
19+
function check(string, expected) {
20+
assertSame(expected, Date.parse(string));
21+
assertSame(expected, new Date(string).getTime());
22+
}
23+
24+
check('1970-01-01T00:00:00', timezoneOffsetMS);
25+
check('1970-01-01', 0);
26+
check('1970-01', 0);
27+
check('1970', 0);
28+
29+
// Legacy format
30+
check('1-1-1970', 0);
31+
check('1-1-1970 00:00:00', timezoneOffsetMS);
32+
check('1/1/1970', 0);
33+
check('1/1/1970 00:00:00', timezoneOffsetMS);
34+
check('1970-01-1', 0);
35+
check('1970-1-01', 0);
36+
check('1970-1-1', 0);
37+
check('1970-1', 0);
38+
39+
true;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* This test is an extension of
10+
* https://github.com/tc39/test262/blob/main/test/built-ins/Date/parse/without-utc-offset.js
11+
* This extension checks also the desired behaviour for legacy dates
12+
* (that are not covered by the specification).
13+
*
14+
* @option use-utc-for-legacy-dates=false
15+
*/
16+
17+
load('assert.js');
18+
19+
const timezoneOffsetMS = new Date(0).getTimezoneOffset() * 60000;
20+
21+
function check(string, expected) {
22+
assertSame(expected, Date.parse(string));
23+
assertSame(expected, new Date(string).getTime());
24+
}
25+
26+
check('1970-01-01T00:00:00', timezoneOffsetMS);
27+
check('1970-01-01', 0);
28+
check('1970-01', 0);
29+
check('1970', 0);
30+
31+
// Legacy format
32+
check('1-1-1970', timezoneOffsetMS);
33+
check('1-1-1970 00:00:00', timezoneOffsetMS);
34+
check('1/1/1970', timezoneOffsetMS);
35+
check('1/1/1970 00:00:00', timezoneOffsetMS);
36+
check('1970-01-1', timezoneOffsetMS);
37+
check('1970-1-01', timezoneOffsetMS);
38+
check('1970-1-1', timezoneOffsetMS);
39+
check('1970-1', timezoneOffsetMS);
40+
41+
true;

0 commit comments

Comments
 (0)