sc/source/ui/view/tabvwsha.cxx | 12 ++++++++++++ 1 file changed, 12 insertions(+)
New commits: commit 23689e492feb41a391738586cef04ab82cc21f80 Author: Eike Rathke <er...@redhat.com> AuthorDate: Tue May 10 18:39:27 2022 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Wed May 11 00:26:01 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 diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx index 393a59cc4d42..7d57d26534fe 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;