mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 449921 - Loosen requirements for characters directly following numbers r=arai,devtools-reviewers,nchevobbe
This patch newly allows cases such as MonDDYYYY and Mon.DD.YYYY. In adding tests for this patch, I noticed that the tests for parsing periods were broken and could not fail the way that they were written, so I fixed them. This patch also fixes a couple of other standing bugs... fixes Bug 485639 - for cases like "Aug 15 2015 10:00am" fixes Bug 1760290 - for YYYY.MM.DD Differential Revision: https://phabricator.services.mozilla.com/D186054
This commit is contained in:
parent
47ebb63d39
commit
6d90b57bac
@ -65,9 +65,9 @@ function naturalSort(a = "", b = "", sessionString, insensitive = false) {
|
||||
|
||||
// Hex or date detection.
|
||||
const aHexOrDate =
|
||||
parseInt(a.match(hexRx), 16) || (aChunks.length !== 1 && Date.parse(a));
|
||||
parseInt(a.match(hexRx), 16) || (aChunks.length > 3 && Date.parse(a));
|
||||
const bHexOrDate =
|
||||
parseInt(b.match(hexRx), 16) || (bChunks.length !== 1 && Date.parse(b));
|
||||
parseInt(b.match(hexRx), 16) || (bChunks.length > 3 && Date.parse(b));
|
||||
|
||||
if (
|
||||
(aHexOrDate || bHexOrDate) &&
|
||||
|
@ -36,6 +36,12 @@ function run_test() {
|
||||
["01/01/1991", "01/01/1992", "01/01/2008", "01/10/2008"],
|
||||
"similar dates"
|
||||
);
|
||||
// Years should expand to 0100, 2001, 2010
|
||||
runTest(
|
||||
["1/1/100", "1/1/1", "1/1/10"],
|
||||
["1/1/100", "1/1/1", "1/1/10"],
|
||||
"dates with short year formatting"
|
||||
);
|
||||
runTest(
|
||||
[
|
||||
"Wed Jan 01 2010 00:00:00 GMT-0800 (Pacific Standard Time)",
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "mozilla/TextUtils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
@ -1452,7 +1453,14 @@ static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
|
||||
return false;
|
||||
}
|
||||
} else if (index < length && c != ',' && c > ' ' && c != '-' &&
|
||||
c != '(') {
|
||||
c != '(' &&
|
||||
// Allow '.' after day of month i.e. DD.Mon.YYYY/Mon.DD.YYYY,
|
||||
// or after year/month in YYYY/MM/DD
|
||||
(c != '.' || mday != -1) &&
|
||||
// Allow month or AM/PM directly after a number
|
||||
(!IsAsciiAlpha(c) ||
|
||||
(mon != -1 && !(strchr("AaPp", c) && index < length - 1 &&
|
||||
strchr("Mm", s[index + 1]))))) {
|
||||
return false;
|
||||
} else if (seenPlusMinus && n < 60) { /* handle GMT-3:30 */
|
||||
if (tzOffset < 0) {
|
||||
|
44
js/src/tests/non262/Date/parse-num-preceding-alpha.js
Normal file
44
js/src/tests/non262/Date/parse-num-preceding-alpha.js
Normal file
@ -0,0 +1,44 @@
|
||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
assertEq(new Date("15AUG2015").getTime(),
|
||||
new Date(2015, Month.August, 15).getTime());
|
||||
|
||||
assertEq(new Date("Aug 15, 2015 10:00am").getTime(),
|
||||
new Date(2015, Month.August, 15, 10).getTime());
|
||||
assertEq(new Date("Aug 15, 2015 10:00pm").getTime(),
|
||||
new Date(2015, Month.August, 15, 22).getTime());
|
||||
|
||||
const rejects = [
|
||||
"2023+/08/12",
|
||||
"2023/08+/12",
|
||||
"12Aug2023Sat",
|
||||
"2023/08/12 12:34:56+0900+",
|
||||
"2023/08/12 12:34:56+0900-",
|
||||
"2023/08/12 12:34:56+09:00+",
|
||||
"2023/08/12 12:34:56+09:00-",
|
||||
"2023/08/12 12:34:56 +09:00+",
|
||||
"2023/08/12 12:34:56GMT+0900,",
|
||||
"2023/08/12 12:34:56GMT+0900.",
|
||||
"2023/08/12 12:34:56GMT+0900/",
|
||||
"2023/08/12 12:34:56GMT+0900+",
|
||||
"2023/08/12 12:34:56GMT+0900-",
|
||||
"2023/08/12 12:34:56GMT+09:30,",
|
||||
"2023/08/12 12:34:56GMT+09:30.",
|
||||
"2023/08/12 12:34:56GMT+09:30/",
|
||||
"2023/08/12 12:34:56GMT+09:30+",
|
||||
"2023/08/12 12:34:56GMT+09:30-",
|
||||
"2023/08/12 12:34:56 +09:30+",
|
||||
"2023/08/12 12:34:56 GMT+09:30+",
|
||||
"2023/08/12 12:34:56.",
|
||||
"2023/08/12 12:34:56.-0900",
|
||||
"2023/08/12 12:34:56PST",
|
||||
];
|
||||
for (const reject of rejects) {
|
||||
assertEq(isNaN(new Date(reject)), true, `"${reject}" should be rejected.`);
|
||||
}
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
@ -1,3 +1,4 @@
|
||||
// |reftest| skip-if(xulRuntime.OS=="WINNT") -- Windows doesn't accept IANA names for the TZ env variable
|
||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@ -6,16 +7,26 @@
|
||||
const tests = [
|
||||
"Aug. 15, 2015",
|
||||
"Aug.. 15, 2015",
|
||||
"Aug.15.2015",
|
||||
"15.Aug.2015",
|
||||
"Aug 15 2015 12:00 am.",
|
||||
"Sat. Aug 15 2015",
|
||||
]
|
||||
"2015.08.15",
|
||||
// These look weird but are accepted for Chrome parity
|
||||
"2015./08/15 00:00:00",
|
||||
"2015/08./15 00:00:00",
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
assertEq(Date.parse("Aug 15, 2015"), Date.parse(test));
|
||||
assertEq(new Date(test).getTime(),
|
||||
new Date(2015, Month.August, 15).getTime(),
|
||||
`"${test}" should be accepted.`);
|
||||
}
|
||||
|
||||
assertEq(Date.parse("Aug 15 2015 GMT."),
|
||||
Date.parse("Aug 15 2015 GMT"));
|
||||
inTimeZone("Etc/GMT-1", () => {
|
||||
let dt = new Date("Aug 15 2015 GMT.");
|
||||
assertEq(dt.getTime(), new Date(2015, Month.August, 15, 1).getTime());
|
||||
});
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
Loading…
Reference in New Issue
Block a user