include/tools/date.hxx | 15 +++------------ include/tools/datetime.hxx | 22 +++++++++++----------- include/tools/time.hxx | 17 +++++------------ tools/source/datetime/datetime.cxx | 27 ++------------------------- 4 files changed, 21 insertions(+), 60 deletions(-)
New commits: commit 6802590b3a850c4c91f4bf16bae770fee6cda577 Author: Mohamed Ali <mohmedali1462...@gmail.com> AuthorDate: Sun Nov 24 17:03:02 2024 +0200 Commit: Hossein <hoss...@libreoffice.org> CommitDate: Sat Feb 1 23:00:54 2025 +0100 tdf#157665 Use <=> operator for date Change-Id: I3527b7fde74f09f6ce4a887ca353ba05a8e14742 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177211 Tested-by: Jenkins Reviewed-by: Hossein <hoss...@libreoffice.org> diff --git a/include/tools/date.hxx b/include/tools/date.hxx index 22429670d805..ddc7b9e7d6d1 100644 --- a/include/tools/date.hxx +++ b/include/tools/date.hxx @@ -25,6 +25,8 @@ #include <com/sun/star/util/Date.hpp> +#include <compare> + namespace com::sun::star::util { struct DateTime; } enum DayOfWeek { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, @@ -207,18 +209,7 @@ public: { return ((mnDate >= rFrom.mnDate) && (mnDate <= rTo.mnDate)); } - bool operator ==( const Date& rDate ) const - { return (mnDate == rDate.mnDate); } - bool operator !=( const Date& rDate ) const - { return (mnDate != rDate.mnDate); } - bool operator >( const Date& rDate ) const - { return (mnDate > rDate.mnDate); } - bool operator <( const Date& rDate ) const - { return (mnDate < rDate.mnDate); } - bool operator >=( const Date& rDate ) const - { return (mnDate >= rDate.mnDate); } - bool operator <=( const Date& rDate ) const - { return (mnDate <= rDate.mnDate); } + auto operator <=> ( const Date& rDate ) const = default; Date& operator =( const Date& rDate ) { mnDate = rDate.mnDate; return *this; } diff --git a/include/tools/datetime.hxx b/include/tools/datetime.hxx index 29dbc80d2ed1..c7ae0c640a52 100644 --- a/include/tools/datetime.hxx +++ b/include/tools/datetime.hxx @@ -64,21 +64,21 @@ public: bool IsEqualIgnoreNanoSec( const DateTime& rDateTime ) const { - if ( Date::operator!=( rDateTime ) ) + if ( GetDate() != rDateTime.GetDate() ) return false; return Time::IsEqualIgnoreNanoSec( rDateTime ); } - bool operator ==( const DateTime& rDateTime ) const - { return (Date::operator==( rDateTime ) && - Time::operator==( rDateTime )); } - bool operator !=( const DateTime& rDateTime ) const - { return (Date::operator!=( rDateTime ) || - Time::operator!=( rDateTime )); } - bool operator >( const DateTime& rDateTime ) const; - bool operator <( const DateTime& rDateTime ) const; - bool operator >=( const DateTime& rDateTime ) const; - bool operator <=( const DateTime& rDateTime ) const; + auto operator <=>( const DateTime& rDateTime ) const + { + if (auto cmp = Date::operator<=>(rDateTime); cmp != 0) + return cmp; + return tools::Time::operator<=>(rDateTime); + } + bool operator==(const DateTime& rDateTime) const + { + return (Date::operator==(rDateTime) && tools::Time::operator==(rDateTime)); + } sal_Int64 GetSecFromDateTime( const Date& rDate ) const; diff --git a/include/tools/time.hxx b/include/tools/time.hxx index 9b3d15f5ec22..b67407f2ebe7 100644 --- a/include/tools/time.hxx +++ b/include/tools/time.hxx @@ -26,6 +26,8 @@ #include <tools/toolsdllapi.h> #include <com/sun/star/util/Time.hpp> +#include <compare> + namespace com::sun::star::util { struct DateTime; } /** @@ -131,18 +133,9 @@ public: bool IsEqualIgnoreNanoSec( const tools::Time& rTime ) const; - bool operator ==( const tools::Time& rTime ) const - { return (nTime == rTime.nTime); } - bool operator !=( const tools::Time& rTime ) const - { return (nTime != rTime.nTime); } - bool operator >( const tools::Time& rTime ) const - { return (nTime > rTime.nTime); } - bool operator <( const tools::Time& rTime ) const - { return (nTime < rTime.nTime); } - bool operator >=( const tools::Time& rTime ) const - { return (nTime >= rTime.nTime); } - bool operator <=( const tools::Time& rTime ) const - { return (nTime <= rTime.nTime); } + bool operator==(const Time& rTime) const = default; + + auto operator <=> ( const Time& rTime ) const = default; static Time GetUTCOffset(); diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index 6f9dea26c6e8..a3c93d82bb65 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -20,6 +20,7 @@ #include <tools/duration.hxx> #include <rtl/math.hxx> #include <sal/log.hxx> +#include <compare> #include <systemdatetime.hxx> @@ -56,33 +57,9 @@ bool DateTime::IsBetween( const DateTime& rFrom, const DateTime& rTo ) const return (*this >= rFrom) && (*this <= rTo); } -bool DateTime::operator >( const DateTime& rDateTime ) const -{ - return (Date::operator>( rDateTime )) || - (Date::operator==( rDateTime ) && tools::Time::operator>( rDateTime )); -} - -bool DateTime::operator <( const DateTime& rDateTime ) const -{ - return (Date::operator<( rDateTime )) || - (Date::operator==( rDateTime ) && tools::Time::operator<( rDateTime )); -} - -bool DateTime::operator >=( const DateTime& rDateTime ) const -{ - return (Date::operator>( rDateTime )) || - (Date::operator==( rDateTime ) && tools::Time::operator>=( rDateTime )); -} - -bool DateTime::operator <=( const DateTime& rDateTime ) const -{ - return (Date::operator<( rDateTime )) || - (Date::operator==( rDateTime ) && tools::Time::operator<=( rDateTime )); -} - sal_Int64 DateTime::GetSecFromDateTime( const Date& rDate ) const { - if ( Date::operator<( rDate ) ) + if (*this < rDate) return 0; else {