From 7e5f69aa33509a359b547b9a4a6569a55cd5d5c9 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 20 Oct 2024 22:51:02 +0500 Subject: Make tools::Time ctor taking sal_Int64 private This ctor is meant to set the value of nTime directly; and that value is not nanoseconds, but an encoded value, using SEC_/MIN_/HOUR_MASK. But in some places, this ctor was misused for setting of nanoseconds, which would only accidentally work for values less than one second. All places that initialized tools::Time with 0, now use EMPTY. This makes the ctor private; and for the very few cases where really the encoded value of nTime is stored / restored, fromEncodedTime is introduced. Change-Id: I1f1994bd9aab1b51a41b1de637619049fe820da4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175283 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- forms/source/component/DatabaseForm.cxx | 4 +++- forms/source/component/EditBase.cxx | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'forms/source') diff --git a/forms/source/component/DatabaseForm.cxx b/forms/source/component/DatabaseForm.cxx index f32b95a4c482..ce12e1c4f184 100644 --- a/forms/source/component/DatabaseForm.cxx +++ b/forms/source/component/DatabaseForm.cxx @@ -721,7 +721,9 @@ void ODatabaseForm::AppendComponent(HtmlSuccessfulObjList& rList, const Referenc sal_Int32 nInt32Val = 0; if (aVal >>= nInt32Val) { - ::tools::Time aTime(nInt32Val); + // Is this 32-bit number actually encoded time? Or should rather + // Time::MakeTimeFromNS be used here? + ::tools::Time aTime(tools::Time::fromEncodedTime(nInt32Val)); OUStringBuffer aBuffer; appendDigits( aTime.GetHour(), 2, aBuffer ); aBuffer.append( '-' ); diff --git a/forms/source/component/EditBase.cxx b/forms/source/component/EditBase.cxx index faf27cf3f0f7..251c54b147c3 100644 --- a/forms/source/component/EditBase.cxx +++ b/forms/source/component/EditBase.cxx @@ -185,7 +185,7 @@ void OEditBaseModel::read(const Reference& _rxInStream) } else if ((nAnyMask & DEFAULT_TIME) == DEFAULT_TIME) { - m_aDefault <<= ::tools::Time(_rxInStream->readHyper()).GetUNOTime(); + m_aDefault <<= ::tools::Time::fromEncodedTime(_rxInStream->readHyper()).GetUNOTime(); } else if ((nAnyMask & DEFAULT_DATE) == DEFAULT_DATE) { -- cgit