summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2019-10-19 01:06:24 +0200
committerEike Rathke <erack@redhat.com>2019-10-19 11:02:57 +0200
commit87660c3334c5150f20f3a7dbcd8f660922a203a5 (patch)
treebdc0103f9cd38c5fdcceb3c21daff3e0888fed62 /svl
parent2b660f0bd0867bdd89f611e7ee60362b11be1874 (diff)
Resolves: tdf#76441 accept two digit groups MM:SS input if formatted as such
... instead of producing the usual HH:MM:00 Works on the formats MM:SS [MM]:SS MM:SS.00 [MM]:SS.00 and even MM:[SS] MM:[SS].00 although these two don't make much sense except of displaying leading 00:, but were always accepted. Change-Id: I1dbe147cafaa934efa1d86b187eaab61f0981fca Reviewed-on: https://gerrit.libreoffice.org/81117 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'svl')
-rw-r--r--svl/source/numbers/zforfind.cxx5
-rw-r--r--svl/source/numbers/zformat.cxx80
2 files changed, 85 insertions, 0 deletions
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 2ad9bfea50df..90debaadb205 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -962,6 +962,11 @@ bool ImpSvNumberInputScan::GetTimeRef( double& fOutNumber,
{
nHour = 0;
}
+ else if (mpFormat && nDecPos == 0 && nCnt == 2 && mpFormat->IsMinuteSecondFormat())
+ {
+ // Input on MM:SS format, instead of doing HH:MM:00
+ nHour = 0;
+ }
else if (nIndex - nStartIndex < nCnt)
{
nHour = static_cast<sal_uInt16>(sStrArray[nNums[nIndex++]].toInt32());
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index dfb41fb0f496..e215ca40f84c 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -5754,6 +5754,86 @@ sal_uInt16 SvNumberformat::ImpGetNumForStringElementCount( sal_uInt16 nNumFor )
return nCnt;
}
+bool SvNumberformat::IsMinuteSecondFormat() const
+{
+ if (GetMaskedType() != SvNumFormatType::TIME)
+ return false;
+
+ constexpr sal_uInt16 k00 = 0x00; // Nada, Nilch
+ constexpr sal_uInt16 kLB = 0x01; // '[' Left Bracket
+ constexpr sal_uInt16 kRB = 0x02; // ']' Right Bracket
+ constexpr sal_uInt16 kMM = 0x04; // M or MM
+ constexpr sal_uInt16 kTS = 0x08; // Time Separator
+ constexpr sal_uInt16 kSS = 0x10; // S or SS
+#define HAS_MINUTE_SECOND(state) ((state) == (kMM|kTS|kSS) || (state) == (kLB|kMM|kRB|kTS|kSS))
+ // Also (kMM|kTS|kLB|kSS|kRB) but those are the same bits.
+
+ sal_uInt16 nState = k00;
+ bool bSep = false;
+ 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_SYMBOLTYPE_DEL:
+ {
+ // '[' or ']' before/after MM or SS
+ const OUString& rStr = NumFor[0].Info().sStrArray[j];
+ if (rStr == "[")
+ {
+ if (nState != k00 && nState != (kMM|kTS))
+ return false;
+ nState |= kLB;
+ }
+ else if (rStr == "]")
+ {
+ if (nState != (kLB|kMM) && nState != (kMM|kTS|kLB|kSS))
+ return false;
+ nState |= kRB;
+ }
+ else
+ return false;
+ }
+ break;
+ case NF_KEY_MI:
+ case NF_KEY_MMI:
+ if (nState != k00 && nState != kLB)
+ return false;
+ nState |= kMM;
+ break;
+ case NF_SYMBOLTYPE_TIMESEP:
+ if (nState != kMM && nState != (kLB|kMM|kRB))
+ return false;
+ nState |= kTS;
+ break;
+ case NF_KEY_S:
+ case NF_KEY_SS:
+ if (nState != (kMM|kTS) && nState != (kLB|kMM|kRB|kTS) && nState != (kMM|kTS|kLB))
+ return false;
+ nState |= kSS;
+ break;
+ case NF_SYMBOLTYPE_TIME100SECSEP:
+ // Trailing fraction of seconds allowed.
+ if (!HAS_MINUTE_SECOND(nState))
+ return false;
+ bSep = true;
+ break;
+ case NF_SYMBOLTYPE_DIGIT:
+ if (!bSep)
+ return false;
+ break;
+ case NF_SYMBOLTYPE_STRING:
+ // nothing, display literal
+ break;
+ default:
+ return false;
+ }
+ }
+ return HAS_MINUTE_SECOND(nState);
+#undef HAS_MINUTE_SECOND
+}
+
const CharClass& SvNumberformat::rChrCls() const
{
return rScan.GetChrCls();