Skip to content

Commit 73b17dd

Browse files
committed
fixes #5502 date parse to accept time zone offset
1 parent 19738b7 commit 73b17dd

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/Runtime/Library/DateImplementation.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,13 +1266,23 @@ namespace Js {
12661266
goto LError;
12671267
}
12681268

1269-
for (lwT = ch - '0'; !FBig(*pch) && isdigit(*pch); pch++)
1269+
for (lwT = ch - '0'; ; pch++)
12701270
{
1271+
// for time zone offset HH:mm, we already got HH so skip ':' and grab mm
1272+
if (((ss == ssAddOffset) || (ss == ssSubOffset)) && (*pch == ':'))
1273+
{
1274+
continue;
1275+
}
1276+
if (FBig(*pch) || !isdigit(*pch))
1277+
{
1278+
break;
1279+
}
12711280
// to avoid overflow
12721281
if (pch - pchBase > 6)
12731282
{
12741283
goto LError;
12751284
}
1285+
// convert string to number, e.g. 07:30 -> 730
12761286
lwT = lwT * 10 + *pch - '0';
12771287
}
12781288

@@ -1292,6 +1302,7 @@ namespace Js {
12921302

12931303
if (lwNil != lwOffset)
12941304
goto LError;
1305+
// convert into minutes, e.g. 730 -> 7*60+30
12951306
lwOffset = lwT < 24 ? lwT * 60 :
12961307
(lwT % 100) + (lwT / 100) * 60;
12971308
if (ssSubOffset == ss)

test/Date/parseInvalidISO.baseline

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ Invalid Date
1919
Invalid Date
2020

2121
0001-01-01T01:01:01.001+25:00
22-
Invalid Date
22+
0000-12-31T00:01:01.001Z
23+
-62135683138999 === -62135683138999
2324

2425
0001-01-01T01:60:01.001Z
2526
Invalid Date
2627

2728
0001-01-01T01:01:01.001+00:60
28-
Invalid Date
29+
0001-01-01T00:01:01.001Z
30+
-62135596738999 === -62135596738999
2931

3032
0001-01-01T01:01:60.001Z
3133
Invalid Date
@@ -39,8 +41,8 @@ Invalid Date
3941
Invalid Date
4042

4143
Total: 11
42-
Accepted: 0
43-
Rejected: 11
44+
Accepted: 2
45+
Rejected: 9
4446
Failed: 0
4547

4648
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)