summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorLaurent BP <laurent.balland-poirier@laposte.net>2020-05-24 22:30:41 +0200
committerEike Rathke <erack@redhat.com>2020-06-15 19:37:12 +0200
commit1861363d623963461905f42aa0b9dc2301f2eaaa (patch)
treed728c2e2c8f66dcb9cedc00bdcbabe646803c905 /svl
parente542b622aeb70230365971cab4838dbe0b6e0a93 (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>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/numbers/zforlist.cxx8
-rw-r--r--svl/source/numbers/zformat.cxx43
2 files changed, 49 insertions, 2 deletions
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index fa501943c341..5a8b5c4744ce 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -3046,7 +3046,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('#');
@@ -3086,7 +3090,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 f683b4c62f12..33026a8508b5 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();