tdf#157665 Use <=> operator for date

Change-Id: I3527b7fde74f09f6ce4a887ca353ba05a8e14742
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177211
Tested-by: Jenkins
Reviewed-by: Hossein   <hossein@libreoffice.org>
This commit is contained in:
Mohamed Ali
2024-11-24 17:03:02 +02:00
committed by Hossein
parent df6fe96163
commit 6802590b3a
4 changed files with 21 additions and 60 deletions

View File

@@ -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; }

View File

@@ -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;

View File

@@ -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();

View File

@@ -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
{