diff options
author | Laurent BP <laurent.balland-poirier@laposte.net> | 2020-05-24 22:30:41 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2020-06-16 13:36:11 +0200 |
commit | 82365fe69c15c65589f709d539ed8e9c4f86a48e (patch) | |
tree | f6b0eb089a221aa4d1e02a60cc970646e26d98db /svl | |
parent | e0ba88a08c9c16fd805e13956ac9676f4ddfd377 (diff) |
tdf#103414 Add/Delete decimal for 100th second
Use Add/Delete decimal to change precision of time and duration
Apply only to 100th second
Change-Id: I2ff1b01db7ee67645511fcf7ea6bf65055e92a8c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94765
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
(cherry picked from commit 1861363d623963461905f42aa0b9dc2301f2eaaa)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96349
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 8 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 43 |
2 files changed, 49 insertions, 2 deletions
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index f8652a0c1284..44150046469e 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -3047,7 +3047,11 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, OUStringBuffer sString; using comphelper::string::padToLength; - if (nLeadingZeros == 0) + if (eType & SvNumFormatType::TIME) + { + sString = pFormat->GetFormatStringForTimePrecision( nPrecision ); + } + else if (nLeadingZeros == 0) { if (!bThousand) sString.append('#'); @@ -3087,7 +3091,7 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, } } } - if (nPrecision > 0 && eType != SvNumFormatType::FRACTION ) + if (nPrecision > 0 && eType != SvNumFormatType::FRACTION && !( eType & SvNumFormatType::TIME ) ) { sString.append(GetNumDecimalSep()); padToLength(sString, sString.getLength() + nPrecision, '0'); diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 774b8fdd0d42..534bb006a1dc 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -5848,6 +5848,49 @@ bool SvNumberformat::IsMinuteSecondFormat() const #undef HAS_MINUTE_SECOND } +OUString SvNumberformat::GetFormatStringForTimePrecision( int nPrecision ) const +{ + OUStringBuffer sString; + using comphelper::string::padToLength; + + sal_uInt16 nNumForCnt = NumFor[0].GetCount(); + auto const & rTypeArray = NumFor[0].Info().nTypeArray; + for (sal_uInt16 j=0; j < nNumForCnt; ++j) + { + switch (rTypeArray[j]) + { + case NF_KEY_S : + case NF_KEY_SS: + sString.append( NumFor[0].Info().sStrArray[j] ); + if ( j > 0 && rTypeArray[j-1] == NF_SYMBOLTYPE_DEL && j < nNumForCnt-1 ) + { + j++; + sString.append( NumFor[0].Info().sStrArray[j] ); + } + if (nPrecision > 0) + { + sString.append( rLoc().getTime100SecSep() ); + padToLength(sString, sString.getLength() + nPrecision, '0'); + } + break; + case NF_SYMBOLTYPE_TIME100SECSEP: + case NF_SYMBOLTYPE_DIGIT: + break; + case NF_SYMBOLTYPE_STRING: + sString.append( "\"" ); + [[fallthrough]]; + default: + sString.append( NumFor[0].Info().sStrArray[j] ); + if (rTypeArray[j] == NF_SYMBOLTYPE_STRING) + { + sString.append( "\"" ); + } + } + } + + return sString.makeStringAndClear(); +} + const CharClass& SvNumberformat::rChrCls() const { return rScan.GetChrCls(); |