[Libreoffice-commits] core.git: chart2/source include/svl svl/source

Eike Rathke erack at redhat.com
Wed Aug 12 05:35:23 PDT 2015


 chart2/source/tools/DiagramHelper.cxx |   33 -------------
 include/svl/zforlist.hxx              |    9 +++
 svl/source/numbers/zforlist.cxx       |   86 ++++++++++++++++++++++++----------
 3 files changed, 72 insertions(+), 56 deletions(-)

New commits:
commit 9d370f2bb9f2af1b3acc1531f1e71b0ded36e40f
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Aug 12 14:29:25 2015 +0200

    move date/time guess work to SvNumberFormatter::GuessDateTimeFormat()
    
    Change-Id: I26f7c47f5b3cf4a3c4274832448d9c8076981af0

diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx
index 3dcbf4b..162bdf6 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -1202,38 +1202,9 @@ sal_Int32 DiagramHelper::getDateTimeInputNumberFormat( const Reference< util::XN
         SAL_WARN("chart2", "DiagramHelper::getDateTimeInputNumberFormat - no SvNumberFormatter");
     else
     {
-        // Categorize the format according to the implementation of
-        // SvNumberFormatter::GetEditFormat(), making assumptions about what
-        // would be time only.
-        /* TODO: implement a method at SvNumberFormatter that does this and
-         * call instead, if Chart isn't able transport the proper format of the
-         * Axis, which of course would be much better.. */
         short nType;
-        if (0.0 <= fNumber && fNumber < 1.0)
-        {
-            // Clearly a time.
-            nType = util::NumberFormat::TIME;
-            nRet = pNumFormatter->GetFormatIndex( NF_TIME_HHMM, LANGUAGE_SYSTEM);
-        }
-        else if (fabs( fNumber) * 24 < 0x7fff)
-        {
-            // Assuming time within 32k hours or 3.7 years.
-            nType = util::NumberFormat::TIME;
-            nRet = pNumFormatter->GetFormatIndex( NF_TIME_HH_MMSS, LANGUAGE_SYSTEM);
-        }
-        else if (rtl::math::approxFloor( fNumber) != fNumber)
-        {
-            // Date+Time.
-            nType = util::NumberFormat::DATETIME;
-            nRet = pNumFormatter->GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, LANGUAGE_SYSTEM);
-        }
-        else
-        {
-            // Date only.
-            nType = util::NumberFormat::DATE;
-            nRet = pNumFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM);
-        }
-
+        // Obtain best matching date, time or datetime format.
+        nRet = pNumFormatter->GuessDateTimeFormat( nType, fNumber, LANGUAGE_SYSTEM);
         // Obtain the corresponding edit format.
         nRet = pNumFormatter->GetEditFormat( fNumber, nRet, nType, LANGUAGE_SYSTEM, NULL);
     }
diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx
index b22aeef..a6e8732 100644
--- a/include/svl/zforlist.hxx
+++ b/include/svl/zforlist.hxx
@@ -572,6 +572,15 @@ public:
     /// Whether nFIndex is a special builtin format
     bool IsSpecialStandardFormat( sal_uInt32 nFIndex, LanguageType eLnge );
 
+    /** Return a time format that best matches fNumber. */
+    sal_uInt32 GetTimeFormat( double fNumber, LanguageType eLnge );
+
+    /** Return a format and type that best matches the value of fNumber if
+        fNumber is assumed to be a date, time or datetime value, but unknown
+        which. Originally introduced for Chart databrowser editor, probably
+        should not be used otherwise. */
+    sal_uInt32 GuessDateTimeFormat( short& rType, double fNumber, LanguageType eLnge );
+
     /** Return the corresponding edit format of a format. */
     sal_uInt32 GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType,
                               LanguageType eLnge, SvNumberformat* pFormat );
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 69ec74d..4f18a09 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -1208,6 +1208,33 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( sal_uInt32 nFIndex, short eType
         return GetStandardFormat( eType, eLnge );
 }
 
+sal_uInt32 SvNumberFormatter::GetTimeFormat( double fNumber, LanguageType eLnge )
+{
+    bool bSign;
+    if ( fNumber < 0.0 )
+    {
+        bSign = true;
+        fNumber = -fNumber;
+    }
+    else
+        bSign = false;
+    double fSeconds = fNumber * 86400;
+    if ( floor( fSeconds + 0.5 ) * 100 != floor( fSeconds * 100 + 0.5 ) )
+    {   // with 100th seconds
+        if ( bSign || fSeconds >= 3600 )
+            return GetFormatIndex( NF_TIME_HH_MMSS00, eLnge );
+        else
+            return GetFormatIndex( NF_TIME_MMSS00, eLnge );
+    }
+    else
+    {
+        if ( bSign || fNumber >= 1.0 )
+            return GetFormatIndex( NF_TIME_HH_MMSS, eLnge );
+        else
+            return GetStandardFormat( css::util::NumberFormat::TIME, eLnge );
+    }
+}
+
 sal_uInt32 SvNumberFormatter::GetStandardFormat( double fNumber, sal_uInt32 nFIndex,
                                                  short eType, LanguageType eLnge )
 {
@@ -1217,36 +1244,45 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( double fNumber, sal_uInt32 nFIn
     switch( eType )
     {
         case css::util::NumberFormat::TIME :
-        {
-            bool bSign;
-            if ( fNumber < 0.0 )
-            {
-                bSign = true;
-                fNumber = -fNumber;
-            }
-            else
-                bSign = false;
-            double fSeconds = fNumber * 86400;
-            if ( floor( fSeconds + 0.5 ) * 100 != floor( fSeconds * 100 + 0.5 ) )
-            {   // with 100th seconds
-                if ( bSign || fSeconds >= 3600 )
-                    return GetFormatIndex( NF_TIME_HH_MMSS00, eLnge );
-                else
-                    return GetFormatIndex( NF_TIME_MMSS00, eLnge );
-            }
-            else
-            {
-                if ( bSign || fNumber >= 1.0 )
-                    return GetFormatIndex( NF_TIME_HH_MMSS, eLnge );
-                else
-                    return GetStandardFormat( eType, eLnge );
-            }
-        }
+            return GetTimeFormat( fNumber, eLnge);
         default:
             return GetStandardFormat( eType, eLnge );
     }
 }
 
+sal_uInt32 SvNumberFormatter::GuessDateTimeFormat( short& rType, double fNumber, LanguageType eLnge )
+{
+    // Categorize the format according to the implementation of
+    // SvNumberFormatter::GetEditFormat(), making assumptions about what
+    // would be time only.
+    sal_uInt32 nRet;
+    if (0.0 <= fNumber && fNumber < 1.0)
+    {
+        // Clearly a time.
+        rType = util::NumberFormat::TIME;
+        nRet = GetTimeFormat( fNumber, eLnge);
+    }
+    else if (fabs( fNumber) * 24 < 0x7fff)
+    {
+        // Assuming time within 32k hours or 3.7 years.
+        rType = util::NumberFormat::TIME;
+        nRet = GetTimeFormat( fNumber, eLnge);
+    }
+    else if (rtl::math::approxFloor( fNumber) != fNumber)
+    {
+        // Date+Time.
+        rType = util::NumberFormat::DATETIME;
+        nRet = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eLnge);
+    }
+    else
+    {
+        // Date only.
+        rType = util::NumberFormat::DATE;
+        nRet = GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLnge);
+    }
+    return nRet;
+}
+
 sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex,
                                              short eType, LanguageType eLang,
                                              SvNumberformat* pFormat )


More information about the Libreoffice-commits mailing list