sc/source/ui/docshell/impex.cxx |   43 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

New commits:
commit 99adfcad3517de6530c9a2f025c528001f543ae2
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Fri Oct 15 11:53:17 2021 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Fri Oct 15 13:18:29 2021 +0200

    Resolves: tdf#88359 CSV: import strict ISO date(+time) with standard 
settings
    
    i.e. without having to activate "Detect special numbers".
    
    Now that we have NF_DATETIME_ISO_YYYYMMDDTHHMMSS000 for resulting
    formats this is possible without losing details.
    
    Only strict ISO 8601 extended separated format is converted, if
    date+time then the T separator must be present, a space character
    is not accepted instead.
    
    Change-Id: I6126cae743ed55fa77915c730114c3f8f5baee8e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123652
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 714066c9fafd..382b3f64b19a 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -63,6 +63,7 @@
 #include <editeng/editobj.hxx>
 #include <svl/numformat.hxx>
 #include <rtl/character.hxx>
+#include <sax/tools/converter.hxx>
 
 #include <memory>
 #include <string_view>
@@ -1406,6 +1407,48 @@ static bool lcl_PutString(
     // Standard or date not determined -> SetString / EditCell
     if( rStr.indexOf( '\n' ) == -1 )
     {
+        if (!bDetectNumFormat && nColFormat == SC_COL_STANDARD)
+        {
+            // Import a strict ISO 8601 date(+time) string even without
+            // "Detect special numbers" or "Date (YMD)".
+            do
+            {
+                // Simple pre-check before calling more expensive parser.
+                // ([+-])(Y)YYYY-MM-DD
+                if (rStr.getLength() < 10)
+                    break;
+                const sal_Int32 n1 = rStr.indexOf('-', 1);
+                if (n1 < 4)
+                    break;
+                const sal_Int32 n2 = rStr.indexOf('-', n1 + 1);
+                if (n2 < 7 || n1 + 3 < n2)
+                    break;
+
+                css::util::DateTime aDateTime;
+                if (!sax::Converter::parseDateTime( aDateTime, rStr))
+                    break;
+
+                sal_uInt32 nFormat = 0;
+                double fVal = 0.0;
+                SvNumberFormatter* pDocFormatter = rDoc.GetFormatTable();
+                if (pDocFormatter->IsNumberFormat( rStr, nFormat, fVal))
+                {
+                    if (pDocFormatter->GetType(nFormat) & 
SvNumFormatType::DATE)
+                    {
+                        ScAddress aPos(nCol,nRow,nTab);
+                        if (bUseDocImport)
+                            rDocImport.setNumericCell(aPos, fVal);
+                        else
+                            rDoc.SetValue(aPos, fVal);
+                        rDoc.SetNumberFormat(aPos, nFormat);
+
+                        return bMultiLine;     // success
+                    }
+                }
+            }
+            while(false);
+        }
+
         ScSetStringParam aParam;
         aParam.mpNumFormatter = pFormatter;
         aParam.mbDetectNumberFormat = bDetectNumFormat;

Reply via email to