diff options
author | Laurent Balland-Poirier <laurent.balland-poirier@laposte.net> | 2016-07-27 09:02:46 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-08-01 08:57:54 +0000 |
commit | aa6bca0dfa0a58aae91eb5fa3564add642cd4238 (patch) | |
tree | 16698565d9b0e5637d6f6b37bb17f831c5cf137b | |
parent | 0db0fda5a1f77872ca26a4407c88b49a7327c84b (diff) |
tdf#101147 Improve (again) minute/month detection
For format like HH:MM:SS MM/DD
second MM is detected as minute: see tdf#95339
New rules:
- first M following each H is minute
- first M following first S is minute
Detection Month/minute now fully compatible with Excel even with unwanted detection:
SS:MM:HH DD/MM/YY
second MM is minute even if user would expect month
Change-Id: Ia789fbc2dbd6d2dcbe9b9c34d3f288674966dd10
Reviewed-on: https://gerrit.libreoffice.org/27560
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r-- | svl/qa/unit/svl.cxx | 4 | ||||
-rw-r--r-- | svl/source/numbers/zforscan.cxx | 19 |
2 files changed, 16 insertions, 7 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index 4522516b3075..6af6566b9b43 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -1132,8 +1132,8 @@ void Test::testUserDefinedNumberFormats() checkPreviewString(aFormatter, sCode, -12.0, eLang, sExpected); } { // tdf#995339: detect SSMM as second minute - sCode = "SS:MM:HH DD/MM/YY"; - sExpected = "54:23:03 02/01/00"; + sCode = "SS:MM:HH DD/MM/YY"; // Month not detected by Excel, so we do not neither to keep compatibility + sExpected = "54:23:03 02/23/00"; checkPreviewString(aFormatter, sCode, M_PI, eLang, sExpected); } { // tdf#99996: better algorithm for fraction representation diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx index 33eda8f4db27..8de7ac782feb 100644 --- a/svl/source/numbers/zforscan.cxx +++ b/svl/source/numbers/zforscan.cxx @@ -1121,6 +1121,8 @@ sal_Int32 ImpSvNumberformatScan::ScanType() short eNewType; bool bMatchBracket = false; bool bHaveGeneral = false; // if General/Standard encountered + bool bIsTimeDetected =false; // hour or second found in format + bool bHaveMinute = false; SkipStrings(i, nPos); while (i < nAnzStrings) @@ -1135,20 +1137,26 @@ sal_Int32 ImpSvNumberformatScan::ScanType() case NF_KEY_E: // E eNewType = css::util::NumberFormat::SCIENTIFIC; break; - case NF_KEY_AMPM: // AM,A,PM,P - case NF_KEY_AP: case NF_KEY_H: // H case NF_KEY_HH: // HH + bIsTimeDetected = true; + SAL_FALLTHROUGH; case NF_KEY_S: // S case NF_KEY_SS: // SS + if ( !bHaveMinute ) + bIsTimeDetected = true; + SAL_FALLTHROUGH; + case NF_KEY_AMPM: // AM,A,PM,P + case NF_KEY_AP: eNewType = css::util::NumberFormat::TIME; break; case NF_KEY_M: // M case NF_KEY_MM: // MM /* Minute or month. Minute if one of: - * preceded by time keyword H or S (ignoring separators) + * preceded by time keyword H (ignoring separators) * followed by time keyword S (ignoring separators) + * H or S was detected * preceded by '[' amount bracket Else month. */ @@ -1156,14 +1164,15 @@ sal_Int32 ImpSvNumberformatScan::ScanType() nIndexNex = NextKeyword(i); if (nIndexPre == NF_KEY_H || // H nIndexPre == NF_KEY_HH || // HH - nIndexPre == NF_KEY_S || // S before M tdf#95339 - nIndexPre == NF_KEY_SS || // SS nIndexNex == NF_KEY_S || // S nIndexNex == NF_KEY_SS || // SS + bIsTimeDetected || // tdf#101147 PreviousChar(i) == '[' ) // [M { eNewType = css::util::NumberFormat::TIME; nTypeArray[i] -= 2; // 6 -> 4, 7 -> 5 + bIsTimeDetected = false; // next M should be month + bHaveMinute = true; } else { |