LibreOffice Module tools (master) 1
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Friends | List of all members
DateTime Class Reference

#include <datetime.hxx>

Inheritance diagram for DateTime:
[legend]
Collaboration diagram for DateTime:
[legend]

Public Types

enum  DateTimeInitSystem { SYSTEM }
 
enum  DateTimeInitEmpty { EMPTY }
 
- Public Types inherited from Date
enum  DateInitSystem { SYSTEM }
 
enum  DateInitEmpty { EMPTY }
 
- Public Types inherited from tools::Time
enum  TimeInitSystem { SYSTEM }
 
enum  TimeInitEmpty { EMPTY }
 

Public Member Functions

 DateTime (DateTimeInitEmpty)
 
 DateTime (DateTimeInitSystem)
 
 DateTime (const DateTime &rDateTime)
 
 DateTime (const Date &rDate)
 
 DateTime (const tools::Time &rTime)
 
 DateTime (const Date &rDate, const tools::Time &rTime)
 
 DateTime (const css::util::DateTime &rDateTime)
 
css::util::DateTime GetUNODateTime () const
 
bool IsBetween (const DateTime &rFrom, const DateTime &rTo) const
 
bool IsEqualIgnoreNanoSec (const DateTime &rDateTime) const
 
bool operator== (const DateTime &rDateTime) const
 
bool operator!= (const DateTime &rDateTime) const
 
bool operator> (const DateTime &rDateTime) const
 
bool operator< (const DateTime &rDateTime) const
 
bool operator>= (const DateTime &rDateTime) const
 
bool operator<= (const DateTime &rDateTime) const
 
sal_Int64 GetSecFromDateTime (const Date &rDate) const
 
void ConvertToUTC ()
 
void ConvertToLocalTime ()
 
void AddTime (double fTimeInDays)
 
DateTimeoperator+= (const tools::Time &rTime)
 
DateTimeoperator-= (const tools::Time &rTime)
 
DateTimeoperator+= (const tools::Duration &rDuration)
 Duration can be negative, so adding it will subtract its value. More...
 
DateTimeoperator= (const DateTime &rDateTime)
 
DateTimeoperator= (const css::util::DateTime &rUDateTime)
 
void GetWin32FileDateTime (sal_uInt32 &rLower, sal_uInt32 &rUpper) const
 
- Public Member Functions inherited from Date
 Date (DateInitEmpty)
 
 Date (DateInitSystem)
 
 Date (sal_Int32 nDate)
 
 Date (const Date &rDate)
 
 Date (sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
 nDay and nMonth both must be <100, nYear must be != 0 More...
 
 Date (const css::util::Date &rUDate)
 
 Date (const css::util::DateTime &_rDateTime)
 
bool IsEmpty () const
 
void SetDate (sal_Int32 nNewDate)
 
sal_Int32 GetDate () const
 
sal_uInt32 GetDateUnsigned () const
 Type safe access for values that are guaranteed to be unsigned, like Date::SYSTEM. More...
 
css::util::Date GetUNODate () const
 
void SetDay (sal_uInt16 nNewDay)
 nNewDay must be <100 More...
 
void SetMonth (sal_uInt16 nNewMonth)
 nNewMonth must be <100 More...
 
void SetYear (sal_Int16 nNewYear)
 nNewYear must be != 0 More...
 
sal_uInt16 GetDay () const
 
sal_uInt16 GetMonth () const
 
sal_Int16 GetYear () const
 
sal_uInt16 GetYearUnsigned () const
 Type safe access for values that are guaranteed to be unsigned, like Date::SYSTEM. More...
 
sal_Int16 GetNextYear () const
 
sal_Int16 GetPrevYear () const
 
void AddYears (sal_Int16 nAddYears)
 Add years skipping year 0 and truncating at limits. More...
 
void AddMonths (sal_Int32 nAddMonths)
 Add months skipping year 0 and truncating at limits. More...
 
void AddDays (sal_Int32 nAddDays)
 Add days skipping year 0 and truncating at limits. More...
 
DayOfWeek GetDayOfWeek () const
 Obtain the day of the week for the date. More...
 
sal_uInt16 GetDayOfYear () const
 Obtain the day of the year for the date. More...
 
sal_uInt16 GetWeekOfYear (DayOfWeek eStartDay=MONDAY, sal_Int16 nMinimumNumberOfDaysInWeek=4) const
 Obtain the week of the year for a date. More...
 
sal_uInt16 GetDaysInMonth () const
 Obtain the number of days in the month of the year of the date. More...
 
sal_uInt16 GetDaysInYear () const
 
bool IsLeapYear () const
 
bool IsValidAndGregorian () const
 If the represented date is valid (1<=month<=12, 1<=day<=(28,29,30,31) depending on month/year) AND is of the Gregorian calendar (1582-10-15 <= date) More...
 
bool IsValidDate () const
 If the represented date is valid (1<=month<=12, 1<=day<=(28,29,30,31) depending on month/year) More...
 
bool IsEndOfMonth () const
 
void Normalize ()
 Normalize date, invalid day or month values are adapted such that they carry over to the next month or/and year, for example 1999-02-32 becomes 1999-03-04, 1999-13-01 becomes 2000-01-01, 1999-13-42 becomes 2000-02-11. More...
 
bool IsBetween (const Date &rFrom, const Date &rTo) const
 
bool operator== (const Date &rDate) const
 
bool operator!= (const Date &rDate) const
 
bool operator> (const Date &rDate) const
 
bool operator< (const Date &rDate) const
 
bool operator>= (const Date &rDate) const
 
bool operator<= (const Date &rDate) const
 
Dateoperator= (const Date &rDate)
 
Dateoperator= (const css::util::Date &rUDate)
 
Dateoperator++ ()
 
Dateoperator-- ()
 
- Public Member Functions inherited from tools::Time
 Time (TimeInitEmpty)
 
 Time (TimeInitSystem)
 
 Time (sal_Int64 _nTime)
 
 Time (const tools::Time &rTime)
 
 Time (const css::util::Time &rTime)
 
 Time (const css::util::DateTime &rDateTime)
 
 Time (sal_uInt32 nHour, sal_uInt32 nMin, sal_uInt32 nSec=0, sal_uInt64 nNanoSec=0)
 
void SetTime (sal_Int64 nNewTime)
 
sal_Int64 GetTime () const
 
css::util::Time GetUNOTime () const
 
void SetHour (sal_uInt16 nNewHour)
 
void SetMin (sal_uInt16 nNewMin)
 
void SetSec (sal_uInt16 nNewSec)
 
void SetNanoSec (sal_uInt32 nNewNanoSec)
 
sal_uInt16 GetHour () const
 
sal_uInt16 GetMin () const
 
sal_uInt16 GetSec () const
 
sal_uInt32 GetNanoSec () const
 
sal_Int32 GetMSFromTime () const
 
void MakeTimeFromMS (sal_Int32 nMS)
 
sal_Int64 GetNSFromTime () const
 
void MakeTimeFromNS (sal_Int64 nNS)
 
double GetTimeInDays () const
 12 hours == 0.5 days More...
 
bool IsEqualIgnoreNanoSec (const tools::Time &rTime) const
 
bool operator== (const tools::Time &rTime) const
 
bool operator!= (const tools::Time &rTime) const
 
bool operator> (const tools::Time &rTime) const
 
bool operator< (const tools::Time &rTime) const
 
bool operator>= (const tools::Time &rTime) const
 
bool operator<= (const tools::Time &rTime) const
 
tools::Timeoperator= (const tools::Time &rTime)
 
Time operator- () const
 
tools::Timeoperator+= (const tools::Time &rTime)
 
tools::Timeoperator-= (const tools::Time &rTime)
 

Static Public Member Functions

static double Sub (const DateTime &rDateTime1, const DateTime &rDateTime2)
 Use Sub() if the floating point "time in days" value is to be processed. More...
 
static DateTime CreateFromWin32FileDateTime (sal_uInt32 rLower, sal_uInt32 rUpper)
 
static DateTime CreateFromUnixTime (const double fSecondsSinceEpoch)
 Creates DateTime given a unix time, which is the number of seconds elapsed since Jan 1st, 1970. More...
 
- Static Public Member Functions inherited from Date
static sal_uInt16 GetDaysInMonth (sal_uInt16 nMonth, sal_Int16 nYear)
 Obtain number of days in a month of a year. More...
 
static sal_Int32 DateToDays (sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
 Internally normalizes values. More...
 
static bool IsValidDate (sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
 Semantically identical to IsValidDate() member method. More...
 
static bool IsEndOfMonth (sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
 Semantically identical to IsEndOfMonth() member method. More...
 
static bool Normalize (sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_Int16 &rYear)
 Semantically identical to Normalize() member method. More...
 
- Static Public Member Functions inherited from tools::Time
static void GetClock (double fTimeInDays, sal_uInt16 &nHour, sal_uInt16 &nMinute, sal_uInt16 &nSecond, double &fFractionOfSecond, int nFractionDecimals)
 Get the wall clock time particles for a (date+)time value. More...
 
static Time GetUTCOffset ()
 
static sal_uInt64 GetSystemTicks ()
 Elapsed time in milliseconds (1e-3) since some unspecified starting point. More...
 
static sal_uInt64 GetMonotonicTicks ()
 Elapsed time in microseconds (1e-6) since some unspecified starting point. More...
 

Private Member Functions

void NormalizeTimeRemainderAndApply (tools::Time &rTime)
 

Friends

TOOLS_DLLPUBLIC friend DateTime operator+ (const DateTime &rDateTime, sal_Int32 nDays)
 
TOOLS_DLLPUBLIC friend DateTime operator- (const DateTime &rDateTime, sal_Int32 nDays)
 
TOOLS_DLLPUBLIC friend DateTime operator+ (const DateTime &rDateTime, double fTimeInDays)
 
TOOLS_DLLPUBLIC friend DateTime operator- (const DateTime &rDateTime, double fTimeInDays)
 
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 tools::Duration operator- (const DateTime &rDateTime1, const DateTime &rDateTime2)
 Use operator-() if a duration is to be remembered or processed. More...
 
TOOLS_DLLPUBLIC friend sal_Int64 operator- (const DateTime &rDateTime, const Date &rDate)
 
TOOLS_DLLPUBLIC friend DateTime operator+ (const DateTime &rDateTime, const tools::Duration &rDuration)
 Duration can be negative, so adding it will subtract its value. More...
 

Additional Inherited Members

- Static Public Attributes inherited from tools::Time
static const sal_Int64 hourPerDay = 24
 
static const sal_Int64 minutePerHour = 60
 
static const sal_Int64 secondPerMinute = 60
 
static const sal_Int64 nanoSecPerSec = 1000000000
 
static const sal_Int64 nanoSecPerMinute = nanoSecPerSec * secondPerMinute
 
static const sal_Int64 nanoSecPerHour = nanoSecPerSec * secondPerMinute * minutePerHour
 
static const sal_Int64 nanoSecPerDay = nanoSecPerSec * secondPerMinute * minutePerHour * hourPerDay
 
static const sal_Int64 secondPerHour = secondPerMinute * minutePerHour
 
static const sal_Int64 secondPerDay = secondPerMinute * minutePerHour * hourPerDay
 
static const sal_Int64 minutePerDay = minutePerHour * hourPerDay
 
static const sal_Int64 nanoPerMicro = 1000
 
static const sal_Int64 nanoPerMilli = 1000000
 
static const sal_Int64 nanoPerCenti = 10000000
 

Detailed Description

Definition at line 34 of file datetime.hxx.

Member Enumeration Documentation

◆ DateTimeInitEmpty

Enumerator
EMPTY 

Definition at line 42 of file datetime.hxx.

◆ DateTimeInitSystem

Enumerator
SYSTEM 

Definition at line 37 of file datetime.hxx.

Constructor & Destructor Documentation

◆ DateTime() [1/7]

DateTime::DateTime ( DateTimeInitEmpty  )
inlineexplicit

Definition at line 47 of file datetime.hxx.

References EMPTY, and Time.

Referenced by CreateFromUnixTime(), and CreateFromWin32FileDateTime().

◆ DateTime() [2/7]

DateTime::DateTime ( DateTimeInitSystem  )
explicit

◆ DateTime() [3/7]

DateTime::DateTime ( const DateTime rDateTime)
inline

Definition at line 49 of file datetime.hxx.

References Time.

◆ DateTime() [4/7]

DateTime::DateTime ( const Date rDate)
inline

Definition at line 51 of file datetime.hxx.

References Time.

◆ DateTime() [5/7]

DateTime::DateTime ( const tools::Time rTime)
inline

Definition at line 52 of file datetime.hxx.

References Time.

◆ DateTime() [6/7]

DateTime::DateTime ( const Date rDate,
const tools::Time rTime 
)
inline

Definition at line 53 of file datetime.hxx.

References Time.

◆ DateTime() [7/7]

DateTime::DateTime ( const css::util::DateTime &  rDateTime)

Definition at line 41 of file datetime.cxx.

References Day, Hours, Minutes, Seconds, Time, and Year.

Member Function Documentation

◆ AddTime()

void DateTime::AddTime ( double  fTimeInDays)

Definition at line 183 of file datetime.cxx.

References operator+=().

◆ ConvertToLocalTime()

void DateTime::ConvertToLocalTime ( )
inline

Definition at line 86 of file datetime.hxx.

References tools::Time::GetUTCOffset().

◆ ConvertToUTC()

void DateTime::ConvertToUTC ( )
inline

Definition at line 85 of file datetime.hxx.

References tools::Time::GetUTCOffset().

◆ CreateFromUnixTime()

DateTime DateTime::CreateFromUnixTime ( const double  fSecondsSinceEpoch)
static

Creates DateTime given a unix time, which is the number of seconds elapsed since Jan 1st, 1970.

Definition at line 271 of file datetime.cxx.

References Date::AddDays(), Date::Date(), DateTime(), tools::Time::nanoSecPerDay, tools::Time::nanoSecPerHour, tools::Time::nanoSecPerMinute, tools::Time::nanoSecPerSec, and SAL_WARN_IF.

◆ CreateFromWin32FileDateTime()

DateTime DateTime::CreateFromWin32FileDateTime ( sal_uInt32  rLower,
sal_uInt32  rUpper 
)
static

◆ GetSecFromDateTime()

sal_Int64 DateTime::GetSecFromDateTime ( const Date rDate) const

◆ GetUNODateTime()

css::util::DateTime DateTime::GetUNODateTime ( ) const
inline

◆ GetWin32FileDateTime()

void DateTime::GetWin32FileDateTime ( sal_uInt32 &  rLower,
sal_uInt32 &  rUpper 
) const

Definition at line 214 of file datetime.cxx.

References Date::Date(), tools::Time::GetNSFromTime(), Date::GetYear(), and SAL_WARN_IF.

◆ IsBetween()

bool DateTime::IsBetween ( const DateTime rFrom,
const DateTime rTo 
) const

Definition at line 54 of file datetime.cxx.

◆ IsEqualIgnoreNanoSec()

bool DateTime::IsEqualIgnoreNanoSec ( const DateTime rDateTime) const
inline

Definition at line 65 of file datetime.hxx.

References tools::Time::IsEqualIgnoreNanoSec().

◆ NormalizeTimeRemainderAndApply()

void DateTime::NormalizeTimeRemainderAndApply ( tools::Time rTime)
private

◆ operator!=()

bool DateTime::operator!= ( const DateTime rDateTime) const
inline

Definition at line 75 of file datetime.hxx.

◆ operator+=() [1/2]

DateTime & DateTime::operator+= ( const tools::Duration rDuration)

Duration can be negative, so adding it will subtract its value.

Definition at line 140 of file datetime.cxx.

References Date::AddDays(), tools::Duration::GetDays(), tools::Duration::GetTime(), and operator+=().

◆ operator+=() [2/2]

DateTime & DateTime::operator+= ( const tools::Time rTime)

Definition at line 124 of file datetime.cxx.

References NormalizeTimeRemainderAndApply().

Referenced by AddTime(), and operator+=().

◆ operator-=()

DateTime & DateTime::operator-= ( const tools::Time rTime)

Definition at line 132 of file datetime.cxx.

References NormalizeTimeRemainderAndApply().

◆ operator<()

bool DateTime::operator< ( const DateTime rDateTime) const

Definition at line 65 of file datetime.cxx.

References tools::Time::operator<(), and Date::operator==().

◆ operator<=()

bool DateTime::operator<= ( const DateTime rDateTime) const

Definition at line 77 of file datetime.cxx.

References tools::Time::operator<=(), and Date::operator==().

◆ operator=() [1/2]

DateTime & DateTime::operator= ( const css::util::DateTime &  rUDateTime)

Definition at line 47 of file datetime.cxx.

References Date::Date(), Date::operator=(), and tools::Time::Time().

◆ operator=() [2/2]

DateTime & DateTime::operator= ( const DateTime rDateTime)
inline

Definition at line 129 of file datetime.hxx.

References Date::operator=().

◆ operator==()

bool DateTime::operator== ( const DateTime rDateTime) const
inline

Definition at line 72 of file datetime.hxx.

◆ operator>()

bool DateTime::operator> ( const DateTime rDateTime) const

Definition at line 59 of file datetime.cxx.

References Date::operator==(), and tools::Time::operator>().

◆ operator>=()

bool DateTime::operator>= ( const DateTime rDateTime) const

Definition at line 71 of file datetime.cxx.

References Date::operator==(), and tools::Time::operator>=().

◆ Sub()

double DateTime::Sub ( const DateTime rDateTime1,
const DateTime rDateTime2 
)
static

Use Sub() if the floating point "time in days" value is to be processed.

This also takes a shortcut for whole days values (equal times), and only for times inflicted values uses an intermediary tools::Duration for conversion. Note that the resulting floating point value nevertheless in many cases is not an exact representation down to nanoseconds.

Definition at line 203 of file datetime.cxx.

References tools::Duration::GetInDays().

Friends And Related Function Documentation

◆ operator+ [1/4]

TOOLS_DLLPUBLIC friend DateTime operator+ ( const DateTime rDateTime,
const tools::Duration rDuration 
)
friend

Duration can be negative, so adding it will subtract its value.

Definition at line 175 of file datetime.cxx.

◆ operator+ [2/4]

TOOLS_DLLPUBLIC friend DateTime operator+ ( const DateTime rDateTime,
const tools::Time rTime 
)
friend

Definition at line 161 of file datetime.cxx.

◆ operator+ [3/4]

TOOLS_DLLPUBLIC friend DateTime operator+ ( const DateTime rDateTime,
double  fTimeInDays 
)
friend

Definition at line 190 of file datetime.cxx.

◆ operator+ [4/4]

TOOLS_DLLPUBLIC friend DateTime operator+ ( const DateTime rDateTime,
sal_Int32  nDays 
)
friend

Definition at line 147 of file datetime.cxx.

◆ operator- [1/5]

TOOLS_DLLPUBLIC friend sal_Int64 operator- ( const DateTime rDateTime,
const Date rDate 
)
friend

Definition at line 113 of file datetime.hxx.

◆ operator- [2/5]

TOOLS_DLLPUBLIC friend DateTime operator- ( const DateTime rDateTime,
const tools::Time rTime 
)
friend

Definition at line 168 of file datetime.cxx.

◆ operator- [3/5]

TOOLS_DLLPUBLIC friend DateTime operator- ( const DateTime rDateTime,
double  fTimeInDays 
)
friend

Definition at line 100 of file datetime.hxx.

◆ operator- [4/5]

TOOLS_DLLPUBLIC friend DateTime operator- ( const DateTime rDateTime,
sal_Int32  nDays 
)
friend

Definition at line 154 of file datetime.cxx.

◆ operator- [5/5]

TOOLS_DLLPUBLIC friend tools::Duration operator- ( const DateTime rDateTime1,
const DateTime rDateTime2 
)
friend

Use operator-() if a duration is to be remembered or processed.

Definition at line 197 of file datetime.cxx.


The documentation for this class was generated from the following files: