diff options
author | Eike Rathke <erack@redhat.com> | 2021-09-23 01:20:57 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-09-23 10:28:11 +0200 |
commit | cda7dff78a113a18cdcc23274454cfef982a17c2 (patch) | |
tree | a2fe9c8d364dfa66ba3e40d62785619c6bc82c9b /svl | |
parent | 77b23d1b5979ce65058f845f73cb48894ba68325 (diff) |
Add not-quite-ISO date+time with space and milliseconds and locale's separator
NF_DATETIME_ISO_YYYYMMDD_HHMMSS000
YYYY-MM-DD HH:MM:SS.000
Users may expect to see that if they enter such, instead of the
real ISO 8601 "T" format.
Change-Id: Iad81750d1c74eedd8d4360163b29ecac98ef6824
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122502
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'svl')
-rw-r--r-- | svl/qa/unit/svl.cxx | 3 | ||||
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 25 |
2 files changed, 23 insertions, 5 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index 155fc9cbf1da..075515bca512 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -232,6 +232,7 @@ void Test::testNumberFormat() const char* pDateTimeExt2[] = { "YYYY-MM-DD HH:MM:SS", + "YYYY-MM-DD HH:MM:SS.000", "YYYY-MM-DD\"T\"HH:MM:SS", "YYYY-MM-DD\"T\"HH:MM:SS.000", nullptr @@ -265,7 +266,7 @@ void Test::testNumberFormat() { NF_TEXT, NF_TEXT, 1, pText }, { NF_DATETIME_SYS_DDMMYYYY_HHMM, NF_DATETIME_SYS_DDMMYYYY_HHMM, 1, pDateTimeExt1 }, { NF_FRACTION_3D, NF_FRACTION_100, 7, pFractionExt }, - { NF_DATETIME_ISO_YYYYMMDD_HHMMSS, NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, 3, pDateTimeExt2 } + { NF_DATETIME_ISO_YYYYMMDD_HHMMSS, NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, 4, pDateTimeExt2 } }; SvNumberFormatter aFormatter(m_xContext, eLang); diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index dca678d81abd..ae6710ee18f1 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -169,6 +169,7 @@ sal_uInt32 const indexTable[NF_INDEX_TABLE_ENTRIES] = { ZF_STANDARD_FRACTION + 7, // NF_FRACTION_10 ZF_STANDARD_FRACTION + 8, // NF_FRACTION_100 ZF_STANDARD_DATETIME + 2, // NF_DATETIME_ISO_YYYYMMDD_HHMMSS + ZF_STANDARD_DATETIME + 6, // NF_DATETIME_ISO_YYYYMMDD_HHMMSS000 ZF_STANDARD_DATETIME + 3, // NF_DATETIME_ISO_YYYYMMDDTHHMMSS ZF_STANDARD_DATETIME + 5 // NF_DATETIME_ISO_YYYYMMDDTHHMMSS000 }; @@ -1281,9 +1282,8 @@ bool SvNumberFormatter::IsNumberFormat(const OUString& sString, } else if (pStringScanner->CanForceToIso8601( DateOrder::Invalid)) { - /* TODO: add a millisecond format with space instead of 'T'? */ if (pStringScanner->GetDecPos()) - F_Index = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, ActLnge ); + F_Index = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, ActLnge ); else F_Index = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, ActLnge ); } @@ -1649,6 +1649,8 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS, eLang ); else if (nFIndex == GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, eLang)) nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, eLang ); + else if (nFIndex == GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, eLang)) + nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, eLang ); else if (nFIndex == GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eLang) || (pFormat && pFormat->IsIso8601( 0 ))) nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eLang ); else @@ -2887,8 +2889,23 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio rKeyword[NF_KEY_HH] + ":" + rKeyword[NF_KEY_MMI] + ":" + rKeyword[NF_KEY_SS]; - ImpInsertFormat( aSingleFormatCode, + SvNumberformat* pFormat = ImpInsertFormat( aSingleFormatCode, CLOffset + ZF_STANDARD_DATETIME+2 /* NF_DATETIME_ISO_YYYYMMDD_HHMMSS */ ); + assert(pFormat); + + // YYYY-MM-DD HH:MM:SS,000 ISO (with blank instead of 'T') and + // milliseconds and locale's time decimal separator + aSingleFormatCode.Code = + rKeyword[NF_KEY_YYYY] + "-" + + rKeyword[NF_KEY_MM] + "-" + + rKeyword[NF_KEY_DD] + " " + + rKeyword[NF_KEY_HH] + ":" + + rKeyword[NF_KEY_MMI] + ":" + + rKeyword[NF_KEY_SS] + GetLocaleData()->getTime100SecSep() + + "000"; + pFormat = ImpInsertFormat( aSingleFormatCode, + CLOffset + ZF_STANDARD_DATETIME+6 /* NF_DATETIME_ISO_YYYYMMDD_HHMMSS000 */ ); + assert(pFormat); // YYYY-MM-DD"T"HH:MM:SS ISO aSingleFormatCode.Code = @@ -2898,7 +2915,7 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio rKeyword[NF_KEY_HH] + ":" + rKeyword[NF_KEY_MMI] + ":" + rKeyword[NF_KEY_SS]; - SvNumberformat* pFormat = ImpInsertFormat( aSingleFormatCode, + pFormat = ImpInsertFormat( aSingleFormatCode, CLOffset + ZF_STANDARD_DATETIME+3 /* NF_DATETIME_ISO_YYYYMMDDTHHMMSS */ ); assert(pFormat); pFormat->SetComment("ISO 8601"); // not to be localized |