include/tools/datetime.hxx | 3 +++ tools/source/datetime/datetime.cxx | 6 ++++++ 2 files changed, 9 insertions(+)
New commits: commit 66da786bdd4588b31755058acf46034c2056215c Author: Eike Rathke <er...@redhat.com> AuthorDate: Tue Jun 20 16:05:58 2023 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Wed Jun 21 02:17:19 2023 +0200 Introduce double DateTime::Sub() as a substitute for friend double operator-() Change-Id: Idb93b3e9b4dcbd09ad7f4253a523fe5be24d0776 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153354 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins diff --git a/include/tools/datetime.hxx b/include/tools/datetime.hxx index 2194711dc208..21cb65921d27 100644 --- a/include/tools/datetime.hxx +++ b/include/tools/datetime.hxx @@ -102,6 +102,9 @@ public: TOOLS_DLLPUBLIC friend DateTime operator +( const DateTime& rDateTime, const tools::Time& rTime ); TOOLS_DLLPUBLIC friend DateTime operator -( const DateTime& rDateTime, const tools::Time& rTime ); TOOLS_DLLPUBLIC friend double operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 ); + /** Same as friend operator-() to be able to disable operator-() to find + places where tools::Duration could be used instead. */ + static double Sub( const DateTime& rDateTime1, const DateTime& rDateTime2 ); TOOLS_DLLPUBLIC friend sal_Int64 operator -( const DateTime& rDateTime, const Date& rDate ) { return static_cast<const Date&>(rDateTime) - rDate; } /** Duration can be negative, so adding it will subtract its value. */ diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index bb4c1ff173a5..f2e5a0e69c57 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -195,6 +195,12 @@ DateTime operator +( const DateTime& rDateTime, double fTimeInDays ) } double operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 ) +{ + return DateTime::Sub( rDateTime1, rDateTime2); +} + +// static +double DateTime::Sub( const DateTime& rDateTime1, const DateTime& rDateTime2 ) { if (static_cast<const tools::Time&>(rDateTime1) != static_cast<const tools::Time&>(rDateTime2)) {