sc/source/ui/view/tabvwsha.cxx |   12 ++++++++++++
 1 file changed, 12 insertions(+)

New commits:
commit 8b6ce0459302580a616c657f6aff19e41660dcdf
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Tue May 10 18:39:27 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed May 11 09:58:10 2022 +0200

    Resolves: tdf#132582 Display duration for calculated time values selection
    
    Change-Id: I634cd0fb059ed9c35849b435bcbd178cd84ac2ae
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134132
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit 23689e492feb41a391738586cef04ab82cc21f80)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134069
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx
index 209f935a729f..39910e32cc39 100644
--- a/sc/source/ui/view/tabvwsha.cxx
+++ b/sc/source/ui/view/tabvwsha.cxx
@@ -29,6 +29,7 @@
 #include <sfx2/viewfrm.hxx>
 #include <svl/ilstitem.hxx>
 #include <svl/numformat.hxx>
+#include <svl/zformat.hxx>
 #include <svl/int64item.hxx>
 #include <svl/srchitem.hxx>
 #include <svl/srchdefs.hxx>
@@ -127,6 +128,17 @@ bool ScTabViewShell::GetFunction( OUString& rFuncStr, 
FormulaError nErrCode )
                     {
                         // number format from attributes or formula
                         nNumFmt = rDoc.GetNumberFormat( nPosX, nPosY, nTab );
+                        // If the number format is time (without date) and the
+                        // result is not within 24 hours, use a duration
+                        // format. Summing date+time doesn't make much sense
+                        // otherwise but we also don't want to display duration
+                        // for a single date+time value.
+                        if (nVal < 0.0 || nVal >= 1.0)
+                        {
+                            const SvNumberformat* pFormat = 
pFormatter->GetEntry(nNumFmt);
+                            if (pFormat && (pFormat->GetType() == 
SvNumFormatType::TIME))
+                                nNumFmt = pFormatter->GetTimeFormat( nVal, 
pFormat->GetLanguage(), true);
+                        }
                     }
 
                     OUString aValStr;

Reply via email to