[Libreoffice-commits] core.git: Branch 'libreoffice-7-1' - sc/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Thu Jun 24 08:57:19 UTC 2021


 sc/source/ui/docshell/impex.cxx |   32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

New commits:
commit 62f01b4c91d402e1828f8ad6b007d0a3594d2d3e
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Wed Jun 23 19:41:46 2021 +0200
Commit:     Michael Stahl <michael.stahl at allotropia.de>
CommitDate: Thu Jun 24 10:56:39 2021 +0200

    Resolves: tdf#143008 Evaluate AM/PM for type date+time text-to-column and CSV
    
    Change-Id: Ib760b9a103ab4b8ce7f5a158b09fbe11c6617f2a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117747
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit d81775f5b12080676ebaf659c5a4c10d64a9074b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117720
    Reviewed-by: Michael Stahl <michael.stahl at allotropia.de>

diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 43d77256a08a..3f86cc86edb7 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1036,7 +1036,7 @@ static bool lcl_PutString(
     else if ( nColFormat != SC_COL_STANDARD ) // Datumformats
     {
         const sal_uInt16 nMaxNumberParts = 7; // Y-M-D h:m:s.t
-        sal_Int32 nLen = rStr.getLength();
+        const sal_Int32 nLen = rStr.getLength();
         sal_Int32 nStart[nMaxNumberParts];
         sal_Int32 nEnd[nMaxNumberParts];
 
@@ -1193,6 +1193,36 @@ static bool lcl_PutString(
                     if (eStatus == rtl_math_ConversionStatus_Ok)
                         fFrac = fV / 86400.0;
                 }
+                sal_Int32 nPos;
+                if (nFound > 3 && 1 <= nHour && nHour <= 12  // nHour 0 and >=13 can't be AM/PM
+                        && (nPos = nEnd[nFound-1] + 1) < nLen)
+                {
+                    // Dreaded AM/PM may be following.
+                    while (nPos < nLen && rStr[nPos] == ' ')
+                        ++nPos;
+                    if (nPos < nLen)
+                    {
+                        sal_Int32 nStop = nPos;
+                        while (nStop < nLen && rStr[nStop] != ' ')
+                            ++nStop;
+                        OUString aAmPm = rStr.copy( nPos, nStop - nPos);
+                        // For AM only 12 needs to be treated, whereas for PM
+                        // it must not. Check both, locale and second/English
+                        // strings.
+                        if (nHour == 12 &&
+                                (rTransliteration.isEqual( aAmPm, pFormatter->GetLocaleData()->getTimeAM()) ||
+                                 (pSecondTransliteration && pSecondTransliteration->isEqual( aAmPm, "AM"))))
+                        {
+                            nHour = 0;
+                        }
+                        else if (nHour < 12 &&
+                                (rTransliteration.isEqual( aAmPm, pFormatter->GetLocaleData()->getTimePM()) ||
+                                 (pSecondTransliteration && pSecondTransliteration->isEqual( aAmPm, "PM"))))
+                        {
+                            nHour += 12;
+                        }
+                    }
+                }
                 pCalendar->setValue( i18n::CalendarFieldIndex::HOUR, nHour );
                 pCalendar->setValue( i18n::CalendarFieldIndex::MINUTE, nMinute );
                 pCalendar->setValue( i18n::CalendarFieldIndex::SECOND, nSecond );


More information about the Libreoffice-commits mailing list