Closed rxaviers closed 7 years ago
Some ideas... We could add an option to parseDate() to modify the lenient behavior, e.g., options.lenientZeroPadding
that takes true
or false
(default). Or the inverse, e.g., options.strictZeroPadding
that also takes a boolean where false
is default. Or even to make it lenient by default and don't care with the strict zero padding parsing for now.
Or even to make it lenient by default and don't care with the strict zero padding parsing for now.
Would be interesting how the current test suite "reacts" to that. Even if that comes up without regressions, it might justify a major release.
options.lenientZeroPadding
that takes true
or false
(default) - This is backward compatible.options.strictZeroPadding
that also takes a boolean where false
is default - This isn't backward compatible, although could be the desired behavior.The question is should we favor backward compatibility (a) or to consider it a bug an eventually implement a options.strictZeroPadding
if it's clear we have both use cases (b).
Options for behaviour that looks like a bug vs breaking backwards compatibility? Not a great choice either way.
I still wonder how likely a bugfix is to actually break anything. That would be the case if an app expects Globalize('pt').parseDate('23/2/2017');
to return null and would break otherwise, right?
Yeap, I also can't think if a case where one would expect Globalize('pt').parseDate('23/2/2017')
to return null
. Some additional points…
We already do the opposite, i.e., we parse zero-padded numberic dates for non-zero-padded numbers formats (e.g., en-US):
Globalize('en').parseDate('1/31/09', {date: 'short'});
// > 2009-01-30T16:00:00.000Z
// Works fine too
Globalize('en').parseDate('01/31/09', {date: 'short'});
// > 2009-01-30T16:00:00.000Z
CLDR’s “Parsing Dates and Times” http://www.unicode.org/reports/tr35/tr35-dates.html#Parsing_Dates_Times suggests an even more loose parsing, so it should be ok to be lenient about the zero-padded numbers.
I’m inclined to consider it a bug and make a patch.
Date parser is strict about parsing zero-padded date fields, for example parsing
yMd
skeleton forpt
(that means patterndd/MM/y
), we have:Though it's impossible to set parser to parse non-zero-padded day and month for
pt
unless it's usedraw
to pass the pattern itself (which is not recommended). Therefore, parser should be lenient about parsing those date fields, specially the ones below for the analogous reason.date: "short"
may includey
oryy
, alsoy
isn't the non-zero-padded foryy
, what makes it even more mandatory to have a way to parse non-zero-addedyy
.skeleton: "yMd"
(i.e., oneM
) may includeMM
as the pattern); similarlyL
.skeleton: "yMd"
(i.e., oned
) may included
ordd
skeleton: "hms"
(i.e., oneh
) may includeh
orhh
; similarlyHKk
.skeleton: "hms"
(i.e., onem
) always includesmm
skeleton: "hms"
(i.e., ones
) always includesss