19#include <tools/datetime.hxx>
21#include <rtl/math.hxx>
42 :
Date( rDateTime.
Day, rDateTime.Month, rDateTime.
Year ),
50 Time::operator=(
Time( rUDateTime));
56 return (*
this >= rFrom) && (*
this <= rTo);
61 return (Date::operator>( rDateTime )) ||
67 return (Date::operator<( rDateTime )) ||
73 return (Date::operator>( rDateTime )) ||
79 return (Date::operator<( rDateTime )) ||
85 if ( Date::operator<( rDate ) )
89 sal_Int64 nSec =
Date( *
this ) - rDate;
93 nSec += (nHour*3600)+(nMin*60)+
GetSec();
100 sal_uInt16 nHours = rTime.
GetHour();
110 else if ( rTime.
GetTime() != 0 )
114 AddDays( -
static_cast<sal_Int32
>(nHours) / 24 );
119 rTime =
Time( 24, 0, 0 ) + rTime;
179 aDateTime += rDuration.
GetTime();
193 aDateTime.
AddTime( fTimeInDays );
211 return static_cast<const Date&
>(rDateTime1) -
static_cast<const Date&
>(rDateTime2);
216 const sal_Int64 a100nPerSecond = SAL_CONST_INT64( 10000000 );
217 const sal_Int64 a100nPerDay = a100nPerSecond * sal_Int64( 60 * 60 * 24 );
230 SAL_WARN_IF( nYear < 1601,
"tools.datetime",
"DateTime::GetWin32FileDateTime - year < 1601: " << nYear);
232 sal_Int64 aTime = (nYear < 1601 ? 0 : (
233 a100nPerDay * (*
this -
Date(1,1,1601)) +
236 rLower = sal_uInt32( aTime % SAL_CONST_UINT64( 0x100000000 ) );
237 rUpper = sal_uInt32( aTime / SAL_CONST_UINT64( 0x100000000 ) );
243 const sal_uInt64 a100nPerSecond = SAL_CONST_UINT64( 10000000 );
244 const sal_uInt64 a100nPerDay = a100nPerSecond * sal_uInt64( 60 * 60 * 24 );
247 sal_uInt64( rUpper ) * SAL_CONST_UINT64( 0x100000000 ) +
248 sal_uInt64( rLower );
250 SAL_WARN_IF(
static_cast<sal_Int64
>(aTime) < 0,
"tools.datetime",
251 "DateTime::CreateFromWin32FileDateTime - absurdly high value expected?");
253 sal_uInt64 nDays = aTime / a100nPerDay;
255 Date aDate(1,1,1601);
260 SAL_WARN_IF( aDate -
Date(1,1,1601) !=
static_cast<sal_Int32
>(nDays),
"tools.datetime",
261 "DateTime::CreateFromWin32FileDateTime - date truncated to max");
263 sal_uInt64 nNanos = (aTime - (nDays * a100nPerDay)) * 100;
273 double fValue = fSecondsSinceEpoch / Time::secondPerDay;
274 const sal_Int32 nDays =
static_cast <sal_Int32
>(::rtl::math::approxFloor(fValue));
276 Date aDate (1, 1, 1970);
279 "DateTime::CreateFromUnixTime - date truncated to max");
bool operator>=(const DateTime &rDateTime) const
DateTime & operator+=(const tools::Time &rTime)
bool operator<(const DateTime &rDateTime) const
static DateTime CreateFromUnixTime(const double fSecondsSinceEpoch)
Creates DateTime given a unix time, which is the number of seconds elapsed since Jan 1st,...
bool operator>(const DateTime &rDateTime) const
void AddTime(double fTimeInDays)
sal_Int64 GetSecFromDateTime(const Date &rDate) const
DateTime & operator-=(const tools::Time &rTime)
DateTime(DateTimeInitEmpty)
void NormalizeTimeRemainderAndApply(tools::Time &rTime)
bool IsBetween(const DateTime &rFrom, const DateTime &rTo) const
void GetWin32FileDateTime(sal_uInt32 &rLower, sal_uInt32 &rUpper) const
DateTime & operator=(const DateTime &rDateTime)
static double Sub(const DateTime &rDateTime1, const DateTime &rDateTime2)
Use Sub() if the floating point "time in days" value is to be processed.
bool operator<=(const DateTime &rDateTime) const
static DateTime CreateFromWin32FileDateTime(sal_uInt32 rLower, sal_uInt32 rUpper)
Represents a date in the proleptic Gregorian calendar.
Date & operator=(const Date &rDate)
void AddDays(sal_Int32 nAddDays)
Add days skipping year 0 and truncating at limits.
sal_Int16 GetYear() const
bool operator==(const Date &rDate) const
DateTime operator-(const DateTime &rDateTime, sal_Int32 nDays)
DateTime operator+(const DateTime &rDateTime, sal_Int32 nDays)
#define SAL_WARN_IF(condition, area, stream)
constexpr OUStringLiteral EMPTY
bool GetSystemDateTime(sal_Int32 *pDate, sal_Int64 *pTime)
Get current local timestamp.