Resolves: tdf#164239 Can force Y-M-D to ISO 8601 if no date acceptance pattern

... was matched at all, even for a-b-c with MDY a<=12 or DMY a<=31.

Change-Id: Ie2d62c73c91794a96114b787d6ad2357c7affb2a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178171
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
This commit is contained in:
Eike Rathke 2024-12-09 19:03:44 +01:00
parent 8f7294223a
commit 47b4b1633a
2 changed files with 16 additions and 9 deletions

View file

@ -1170,7 +1170,7 @@ void Test::testIsNumberFormat()
{ "Sept 1", true }, //tdf#127363 { "Sept 1", true }, //tdf#127363
{ "5/d", false }, //tdf#143165 { "5/d", false }, //tdf#143165
{ "Jan 1 2000", true }, { "Jan 1 2000", true },
{ "5-12-14", false }, { "5-12-14", true }, // tdf#164239
{ "005-12-14", true }, { "005-12-14", true },
{ "15-10-30", true }, { "15-10-30", true },
{ "2015-10-30", true }, { "2015-10-30", true },
@ -1232,12 +1232,13 @@ void checkSpecificNumberFormats( SvNumberFormatter& rFormatter,
void Test::testIsNumberFormatSpecific() void Test::testIsNumberFormatSpecific()
{ {
{ {
// en-US uses M/D/Y format, test that a-b-c input with a<=31 and b<=12 // en-US uses M/D/Y format, test that without Y-M-D pattern an a-b-c
// does not lead to a/b/c date output // input with a<=12 leads to ISO a-b-c date output.
SvNumberFormatter aFormatter(m_xContext, LANGUAGE_ENGLISH_US); SvNumberFormatter aFormatter(m_xContext, LANGUAGE_ENGLISH_US);
std::vector<FormatInputOutput> aIO = { std::vector<FormatInputOutput> aIO = {
{ "5-12-14", false, "", 0 }, { "005-12-14", true, "0005-12-14", 0 },
{ "5-12-14", true, "2005-12-14", 0 },
{ "32-12-14", true, "1932-12-14", 0 } { "32-12-14", true, "1932-12-14", 0 }
}; };
@ -1245,12 +1246,13 @@ void Test::testIsNumberFormatSpecific()
} }
{ {
// de-DE uses D.M.Y format, test that a-b-c input with a<=31 and b<=12 // de-DE uses D.M.Y format, test that without Y-M-D pattern an a-b-c
// does not lead to a.b.c date output // input with a<=31 leads to ISO a-b-c date output.
SvNumberFormatter aFormatter(m_xContext, LANGUAGE_GERMAN); SvNumberFormatter aFormatter(m_xContext, LANGUAGE_GERMAN);
std::vector<FormatInputOutput> aIO = { std::vector<FormatInputOutput> aIO = {
{ "5-12-14", false, "", 0 }, { "005-12-14", true, "0005-12-14", 0 },
{ "5-12-14", true, "2005-12-14", 0 },
{ "32-12-14", true, "1932-12-14", 0 } { "32-12-14", true, "1932-12-14", 0 }
}; };
@ -1263,6 +1265,7 @@ void Test::testIsNumberFormatSpecific()
SvNumberFormatter aFormatter(m_xContext, LANGUAGE_DUTCH); SvNumberFormatter aFormatter(m_xContext, LANGUAGE_DUTCH);
std::vector<FormatInputOutput> aIO = { std::vector<FormatInputOutput> aIO = {
{ "001-2-11", true, "0001-02-11", 0 },
{ "22-11-1999", true, "22-11-99", 0 }, // if default YY changes to YYYY adapt this { "22-11-1999", true, "22-11-99", 0 }, // if default YY changes to YYYY adapt this
{ "1999-11-22", true, "1999-11-22", 0 }, { "1999-11-22", true, "1999-11-22", 0 },
{ "1-2-11", true, "01-02-11", 0 }, // if default YY changes to YYYY adapt this { "1-2-11", true, "01-02-11", 0 }, // if default YY changes to YYYY adapt this

View file

@ -1172,6 +1172,10 @@ bool ImpSvNumberInputScan::CanForceToIso8601( DateOrder eDateOrder )
eDateOrder = GetDateOrder(); eDateOrder = GetDateOrder();
} }
// No date pattern matched at all can be forced to ISO 8601 here as is.
if (GetDatePatternNumbers() == 0)
return true;
nCanForceToIso8601 = 1; nCanForceToIso8601 = 1;
} }