summaryrefslogtreecommitdiff
path: root/include/tools
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-10-20 22:51:02 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-10-21 10:30:58 +0200
commit7e5f69aa33509a359b547b9a4a6569a55cd5d5c9 (patch)
treed5956d0364044238979ef22319259d8c4a97b46f /include/tools
parent04921e20b4d3d08a4b78dbafe26c983075fe5630 (diff)
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 <mike.kaganski@collabora.com>
Diffstat (limited to 'include/tools')
-rw-r--r--include/tools/datetime.hxx2
-rw-r--r--include/tools/duration.hxx2
-rw-r--r--include/tools/time.hxx5
3 files changed, 6 insertions, 3 deletions
diff --git a/include/tools/datetime.hxx b/include/tools/datetime.hxx
index f50db1049a77..29dbc80d2ed1 100644
--- a/include/tools/datetime.hxx
+++ b/include/tools/datetime.hxx
@@ -48,7 +48,7 @@ public:
explicit DateTime( DateTimeInitSystem );
DateTime( const DateTime& rDateTime ) :
Date( rDateTime ), Time( rDateTime ) {}
- explicit DateTime( const Date& rDate ) : Date( rDate ), Time(0) {}
+ explicit DateTime( const Date& rDate ) : Date( rDate ), Time(Time::EMPTY) {}
explicit DateTime( const tools::Time& rTime ) : Date(0), Time( rTime ) {}
DateTime( const Date& rDate, const tools::Time& rTime ) :
Date( rDate ), Time( rTime ) {}
diff --git a/include/tools/duration.hxx b/include/tools/duration.hxx
index 9f032539e142..ca0d7088b7e1 100644
--- a/include/tools/duration.hxx
+++ b/include/tools/duration.hxx
@@ -96,7 +96,7 @@ private:
void SetTimeDiff(const Time& rStart, const Time& rEnd);
private:
- Time maTime = Time(0);
+ Time maTime = Time(Time::EMPTY);
sal_Int32 mnDays = 0;
};
}
diff --git a/include/tools/time.hxx b/include/tools/time.hxx
index c92bdd9aee05..9b3d15f5ec22 100644
--- a/include/tools/time.hxx
+++ b/include/tools/time.hxx
@@ -40,6 +40,7 @@ class SAL_WARN_UNUSED TOOLS_DLLPUBLIC Time
{
private:
sal_Int64 nTime;
+ explicit Time(sal_Int64 _nTime) { nTime = _nTime; }
static sal_Int64 assemble(sal_uInt32 h, sal_uInt32 m, sal_uInt32 s, sal_uInt64 ns);
short GetSign() const { return (nTime >= 0) ? +1 : -1; }
@@ -78,13 +79,15 @@ public:
explicit Time( TimeInitEmpty )
{ nTime = 0; }
explicit Time( TimeInitSystem );
- explicit Time( sal_Int64 _nTime ) { Time::nTime = _nTime; }
Time( const tools::Time& rTime ) = default;
explicit Time( const css::util::Time& rTime );
explicit Time( const css::util::DateTime& rDateTime );
Time( sal_uInt32 nHour, sal_uInt32 nMin,
sal_uInt32 nSec = 0, sal_uInt64 nNanoSec = 0 );
+ // The argument is not nanoseconds, it's what nTime must contain!
+ static Time fromEncodedTime(sal_Int64 _nTime) { return Time(_nTime); }
+
void SetTime( sal_Int64 nNewTime ) { nTime = nNewTime; }
sal_Int64 GetTime() const { return nTime; }
css::util::Time GetUNOTime() const { return css::util::Time(GetNanoSec(),GetSec(),GetMin(),GetHour(),false); }