From 3577378ef8a3baa7fc034de6f09e50571a20466d Mon Sep 17 00:00:00 2001 From: Benjamin Pike Date: Fri, 10 May 2024 02:35:30 +0200 Subject: [PATCH 1/2] add lowercase t and z to ISO parsing regexes --- src/impl/regexParser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/impl/regexParser.js b/src/impl/regexParser.js index ab095864d..6710d64ea 100644 --- a/src/impl/regexParser.js +++ b/src/impl/regexParser.js @@ -67,11 +67,11 @@ function simpleParse(...keys) { } // ISO and SQL parsing -const offsetRegex = /(?:(Z)|([+-]\d\d)(?::?(\d\d))?)/; +const offsetRegex = /(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/; const isoExtendedZone = `(?:${offsetRegex.source}?(?:\\[(${ianaRegex.source})\\])?)?`; const isoTimeBaseRegex = /(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/; const isoTimeRegex = RegExp(`${isoTimeBaseRegex.source}${isoExtendedZone}`); -const isoTimeExtensionRegex = RegExp(`(?:T${isoTimeRegex.source})?`); +const isoTimeExtensionRegex = RegExp(`(?:[Tt]${isoTimeRegex.source})?`); const isoYmdRegex = /([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/; const isoWeekRegex = /(\d{4})-?W(\d\d)(?:-?(\d))?/; const isoOrdinalRegex = /(\d{4})-?(\d{3})/; From df1f62c1cafa659ad7a4b6f60368d23be77bf27c Mon Sep 17 00:00:00 2001 From: dobon Date: Thu, 21 Nov 2024 10:15:11 +0000 Subject: [PATCH 2/2] add unit tests for fromISO capitalization on t and z indifference --- test/datetime/regexParse.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/datetime/regexParse.test.js b/test/datetime/regexParse.test.js index db84b968f..50d36b709 100644 --- a/test/datetime/regexParse.test.js +++ b/test/datetime/regexParse.test.js @@ -114,6 +114,18 @@ test("DateTime.fromISO() can optionally specify a zone", () => { const isSame = (s, expected) => expect(DateTime.fromISO(s).toObject()).toEqual(expected); +test("DateTime.fromISO() accepts both capital T and lowercase t", () => { + // #1610 + let dt = DateTime.fromISO("2016-05-25T09:08:34.123+06:00"); + isSame("2016-05-25t09:08:34.123+06:00", dt.toObject()); +}); + +test("DateTime.fromISO() accepts both capital Z and lowercase z", () => { + // #1610 + let dt = DateTime.fromISO("2016-05-25T09:08:34.123Z"); + isSame("2016-05-25T09:08:34.123z", dt.toObject()); +}); + test("DateTime.fromISO() accepts just the year", () => { isSame("2016", { year: 2016,