connectivity/source/commontools/dbconversion.cxx |    2 +-
 dbaccess/source/ui/control/FieldDescControl.cxx  |   15 ++++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

New commits:
commit 5b808448dc79e996efa7cb5082145d4e5803daa6
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Jul 20 23:27:26 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Jul 21 08:18:18 2025 +0200

    Related: tdf#167591 Make STANDARD_DB_DATE more standard
    
    For some reason, STANDARD_DB_DATE was 1900-01-01, which differs from
    the most used epoch of 1899-12-30 (see e.g. the default initializer
    of ImpSvNumberformatScan). This was triggering tdf#167591, where the
    correction added two days of the difference to the date entered into
    the default value box.
    
    I couldn't find how/if this value could get exposed to API; so let's
    try to standardise it a bit.
    
    Change-Id: I9207cbe3a5a91ca63f3f97792da0c5ad2931ffa8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188092
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/connectivity/source/commontools/dbconversion.cxx 
b/connectivity/source/commontools/dbconversion.cxx
index 4dd7d5b8e9f3..4420a63e38d9 100644
--- a/connectivity/source/commontools/dbconversion.cxx
+++ b/connectivity/source/commontools/dbconversion.cxx
@@ -68,7 +68,7 @@ namespace dbtools
 
     css::util::Date const & DBTypeConversion::getStandardDate()
     {
-        static css::util::Date STANDARD_DB_DATE(1,1,1900);
+        static css::util::Date STANDARD_DB_DATE(30,12,1899);
         return STANDARD_DB_DATE;
     }
 
commit 060775489a42d5489417b8a5c29c8f0b4006f796
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Jul 20 23:18:34 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Jul 21 08:18:12 2025 +0200

    tdf#167591: Only apply date correction, when sDefault wasn't date string
    
    The correction is needed to adjust a date in the data source's epoch
    to the epoch used by the control (and its formatter). These epochs
    may differ.
    
    The problem was, that when sDefault has a date string like "20/07/25"
    or "2025-07-20", the conversion from that string to double using the
    control's formatter already created the value in the required epoch;
    and the correction broke the value.
    
    Fix that by checking if the string was really a date string, and so
    the correction should be skipped.
    
    Change-Id: Ia1ba2b1b5dc88d66d524ff03fecc028f7ebf3336
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188091
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/dbaccess/source/ui/control/FieldDescControl.cxx 
b/dbaccess/source/ui/control/FieldDescControl.cxx
index 3c262ddbe9f1..2e9a33a50bfe 100644
--- a/dbaccess/source/ui/control/FieldDescControl.cxx
+++ b/dbaccess/source/ui/control/FieldDescControl.cxx
@@ -1321,7 +1321,17 @@ OUString OFieldDescControl::getControlDefault( const 
OFieldDescription* _pFieldD
                 sal_Int32 nNumberFormat = 
::comphelper::getNumberFormatType(xNumberFormatter,nFormatKey);
                 if (nNumberFormat & css::util::NumberFormat::DATE)
                 {
-                    nValue = 
DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),nValue);
+                    bool bDoCorrect = true;
+                    if (!sDefault.isEmpty())
+                    {
+                        // nValue was converted from that string. If that 
string was a date, nValue
+                        // is already in the required epoch, and we should not 
try to correct it
+                        sal_Int32 nFormatKeyOf_sDefault = 
xNumberFormatter->detectNumberFormat(nFormatKey, sDefault);
+                        sal_Int16 nNumberFormatType = 
comphelper::getNumberFormatType(xNumberFormatter, nFormatKeyOf_sDefault);
+                        bDoCorrect = (nNumberFormatType & 
css::util::NumberFormat::DATE) == 0;
+                    }
+                    if (bDoCorrect)
+                        nValue = 
DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),nValue);
                 }
 
                 Reference< css::util::XNumberFormatPreviewer> 
xPreviewer(xNumberFormatter,UNO_QUERY);
commit 80275c5811449d54ff89054df7fe8e240cd8ee87
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Jul 20 23:16:12 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Jul 21 08:18:06 2025 +0200

    Simplify the condition
    
    css::util::NumberFormat is a bitset; css::util::NumberFormat::DATE is 2,
    and css::util::NumberFormat::DATETIME is 6; so it doesn't make sense to
    check the latter after checking the former.
    
    Change-Id: I1fd968cae2678dc9244594faeb8f9164a714ef7d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188090
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/dbaccess/source/ui/control/FieldDescControl.cxx 
b/dbaccess/source/ui/control/FieldDescControl.cxx
index 08d9211d4fc9..3c262ddbe9f1 100644
--- a/dbaccess/source/ui/control/FieldDescControl.cxx
+++ b/dbaccess/source/ui/control/FieldDescControl.cxx
@@ -1319,8 +1319,7 @@ OUString OFieldDescControl::getControlDefault( const 
OFieldDescription* _pFieldD
                 
::comphelper::getNumberFormatProperty(xNumberFormatter,nFormatKey,u"Locale"_ustr)
 >>= aLocale;
 
                 sal_Int32 nNumberFormat = 
::comphelper::getNumberFormatType(xNumberFormatter,nFormatKey);
-                if(     (nNumberFormat & css::util::NumberFormat::DATE)    == 
css::util::NumberFormat::DATE
-                    || (nNumberFormat & css::util::NumberFormat::DATETIME) == 
css::util::NumberFormat::DATETIME )
+                if (nNumberFormat & css::util::NumberFormat::DATE)
                 {
                     nValue = 
DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),nValue);
                 }

Reply via email to