LibreOffice Module tools (master) 1
|
Represents a date in the proleptic Gregorian calendar. More...
#include <date.hxx>
Public Types | |
enum | DateInitSystem { SYSTEM } |
enum | DateInitEmpty { EMPTY } |
Public Member Functions | |
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 |
Date & | operator= (const Date &rDate) |
Date & | operator= (const css::util::Date &rUDate) |
Date & | operator++ () |
Date & | operator-- () |
Static Public Member Functions | |
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... | |
Private Member Functions | |
void | setDateFromDMY (sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear) |
sal_Int32 | GetAsNormalizedDays () const |
An accelerated form of DateToDays on this date. More... | |
Private Attributes | |
sal_Int32 | mnDate |
Friends | |
TOOLS_DLLPUBLIC friend Date | operator+ (const Date &rDate, sal_Int32 nDays) |
TOOLS_DLLPUBLIC friend Date | operator- (const Date &rDate, sal_Int32 nDays) |
TOOLS_DLLPUBLIC friend sal_Int32 | operator- (const Date &rDate1, const Date &rDate2) |
Represents a date in the proleptic Gregorian calendar.
Largest representable date is 32767-12-31 = 327671231
Smallest representable date is -32768-01-01 = -327680101
Due to possible conversions to css::util::Date, which has a short Year member variable, these limits are fix.
Year value 0 is unused. The year before year 1 CE is year 1 BCE, which is the traditional proleptic Gregorian calendar.
This is not how ISO 8601:2000 defines things (but ISO 8601:1998 Draft Revision did), but it enables class Date to be used for writing XML files as XML Schema Part 2 in D.3.2 No Year Zero says "The year "0000" is an illegal year value.", see https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#noYearZero and furthermore the note for 3.2.7 dateTime https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dateTime
enum Date::DateInitEmpty |
enum Date::DateInitSystem |
|
inlineexplicit |
Definition at line 71 of file date.hxx.
Referenced by DateTime::CreateFromUnixTime(), DateTime::CreateFromWin32FileDateTime(), DateTime::DateTime(), DateTime::GetSecFromDateTime(), GetWeekOfYear(), DateTime::GetWin32FileDateTime(), and DateTime::operator=().
|
explicit |
Definition at line 104 of file tdate.cxx.
References GetSystemDateTime(), mnDate, and setDateFromDMY().
|
inline |
Date::Date | ( | const css::util::DateTime & | _rDateTime | ) |
Definition at line 110 of file tdate.cxx.
References setDateFromDMY().
void Date::AddDays | ( | sal_Int32 | nAddDays | ) |
Add days skipping year 0 and truncating at limits.
Definition at line 375 of file tdate.cxx.
References GetAsNormalizedDays(), and lcl_DaysToDate().
Referenced by DateTime::CreateFromUnixTime(), DateTime::CreateFromWin32FileDateTime(), DateTime::NormalizeTimeRemainderAndApply(), and DateTime::operator+=().
void Date::AddMonths | ( | sal_Int32 | nAddMonths | ) |
Add months skipping year 0 and truncating at limits.
If the original date was on Feb-29 or day 31 and the resulting date is not a leap year or a month with fewer days, the result is adjusted to Feb-28 or day 30.
Definition at line 172 of file tdate.cxx.
References GetMonth(), GetYear(), kYearMax, kYearMin, Normalize(), SetMonth(), and SetYear().
void Date::AddYears | ( | sal_Int16 | nAddYears | ) |
Add years skipping year 0 and truncating at limits.
If the original date was on Feb-29 and the resulting date is not a leap year, the result is adjusted to Feb-28.
Definition at line 131 of file tdate.cxx.
References GetDay(), GetMonth(), GetYear(), comphelper::date::isLeapYear(), kYearMax, kYearMin, SetDay(), and SetYear().
|
static |
Internally normalizes values.
Definition at line 90 of file tdate.cxx.
References comphelper::date::convertDateToDaysNormalizing().
Referenced by GetAsNormalizedDays().
|
private |
An accelerated form of DateToDays on this date.
Definition at line 70 of file tdate.cxx.
References comphelper::date::convertDateToDays(), DateToDays(), GetDay(), GetMonth(), GetYear(), mnDate, and comphelper::date::normalize().
Referenced by AddDays(), GetDayOfWeek(), GetWeekOfYear(), operator++(), and operator--().
|
inline |
Type safe access for values that are guaranteed to be unsigned, like Date::SYSTEM.
|
inline |
Definition at line 101 of file date.hxx.
Referenced by AddYears(), DateTimeToOString(), DateToDDMMYYYYOString(), GetAsNormalizedDays(), GetDayOfYear(), GetDaysInMonth(), DateTime::GetUNODateTime(), IsEndOfMonth(), IsValidAndGregorian(), IsValidDate(), Normalize(), operator<<(), SetMonth(), and SetYear().
DayOfWeek Date::GetDayOfWeek | ( | ) | const |
Obtain the day of the week for the date.
Internally normalizes a copy of values. The result may be unexpected for a non-normalized invalid date like Date(31,11,2000) or a sequence of aDate.SetDay(31); aDate.SetMonth(11);
Definition at line 192 of file tdate.cxx.
References GetAsNormalizedDays().
Referenced by GetWeekOfYear().
sal_uInt16 Date::GetDayOfYear | ( | ) | const |
Obtain the day of the year for the date.
Internally normalizes a copy of values. The result may be unexpected for a non-normalized invalid date like Date(31,11,2000) or a sequence of aDate.SetDay(31); aDate.SetMonth(11);
Definition at line 197 of file tdate.cxx.
References GetDay(), comphelper::date::getDaysInMonth(), GetMonth(), GetYear(), i, and Normalize().
Referenced by GetWeekOfYear().
sal_uInt16 Date::GetDaysInMonth | ( | ) | const |
Obtain the number of days in the month of the year of the date.
Internally normalizes a copy of values.
The result may be unexpected for a non-normalized invalid date like Date(31,11,2000) or a sequence of aDate.SetDay(31); aDate.SetMonth(11);
These would result in 31 as –11-31 rolls over to –12-01 and the number of days in December is returned.
Instead, to obtain the value for the actual set use the static method Date::GetDaysInMonth( aDate.GetMonth(), aDate.GetYear()) in such cases.
Definition at line 295 of file tdate.cxx.
References GetDay(), comphelper::date::getDaysInMonth(), GetMonth(), GetYear(), and Normalize().
|
static |
Obtain number of days in a month of a year.
Internally sanitizes nMonth to values 1 <= nMonth <= 12, does not normalize values.
Definition at line 60 of file tdate.cxx.
References comphelper::date::getDaysInMonth(), and SAL_WARN_IF.
|
inline |
|
inline |
Definition at line 107 of file date.hxx.
Referenced by AddMonths(), AddYears(), DateTimeToOString(), DateToDDMMYYYYOString(), GetAsNormalizedDays(), GetDayOfYear(), GetDaysInMonth(), DateTime::GetUNODateTime(), IsEndOfMonth(), IsValidAndGregorian(), IsValidDate(), Normalize(), operator<<(), SetDay(), and SetYear().
|
inline |
Definition at line 116 of file date.hxx.
Referenced by GetWeekOfYear().
|
inline |
Definition at line 117 of file date.hxx.
Referenced by GetWeekOfYear().
sal_uInt16 Date::GetWeekOfYear | ( | DayOfWeek | eStartDay = MONDAY , |
sal_Int16 | nMinimumNumberOfDaysInWeek = 4 |
||
) | const |
Obtain the week of the year for a date.
nMinimumNumberOfDaysInWeek | How many days of a week must reside in the first week of a year. |
Internally normalizes a copy of values. The result may be unexpected for a non-normalized invalid date like Date(31,11,2000) or a sequence of aDate.SetDay(31); aDate.SetMonth(11);
Definition at line 209 of file tdate.cxx.
References Date(), GetAsNormalizedDays(), GetDayOfWeek(), GetDayOfYear(), GetDaysInYear(), GetNextYear(), GetPrevYear(), GetWeekOfYear(), GetYear(), IsLeapYear(), lcl_DaysToDate(), and SAL_WARN.
Referenced by GetWeekOfYear().
|
inline |
Definition at line 113 of file date.hxx.
Referenced by AddMonths(), AddYears(), DateTimeToOString(), DateToDDMMYYYYOString(), GetAsNormalizedDays(), GetDayOfYear(), GetDaysInMonth(), DateTime::GetUNODateTime(), GetWeekOfYear(), DateTime::GetWin32FileDateTime(), IsEndOfMonth(), IsLeapYear(), IsValidAndGregorian(), IsValidDate(), Normalize(), operator<<(), SetDay(), and SetMonth().
|
inline |
Type safe access for values that are guaranteed to be unsigned, like Date::SYSTEM.
bool Date::IsEndOfMonth | ( | ) | const |
Definition at line 345 of file tdate.cxx.
References GetDay(), GetMonth(), GetYear(), and IsEndOfMonth().
Referenced by IsEndOfMonth().
|
static |
Semantically identical to IsEndOfMonth() member method.
Definition at line 351 of file tdate.cxx.
References comphelper::date::getDaysInMonth(), and comphelper::date::isValidDate().
bool Date::IsLeapYear | ( | ) | const |
Definition at line 305 of file tdate.cxx.
References GetYear(), and comphelper::date::isLeapYear().
Referenced by GetWeekOfYear().
bool Date::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)
Definition at line 311 of file tdate.cxx.
References GetDay(), comphelper::date::getDaysInMonth(), GetMonth(), and GetYear().
bool Date::IsValidDate | ( | ) | const |
If the represented date is valid (1<=month<=12, 1<=day<=(28,29,30,31) depending on month/year)
Definition at line 334 of file tdate.cxx.
References GetDay(), GetMonth(), GetYear(), and comphelper::date::isValidDate().
|
static |
Semantically identical to IsValidDate() member method.
Definition at line 340 of file tdate.cxx.
References comphelper::date::isValidDate().
void Date::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.
Truncates at -32768-01-01 or 32767-12-31, 0001-00-x will yield the normalized value of -0001-12-x
This may be necessary after Date ctors or if the SetDate(), SetDay(), SetMonth(), SetYear() methods set individual non-matching values. Adding/subtracting to/from dates never produces invalid dates.
Definition at line 357 of file tdate.cxx.
References GetDay(), GetMonth(), GetYear(), Normalize(), and setDateFromDMY().
Referenced by AddMonths(), GetDayOfYear(), GetDaysInMonth(), and Normalize().
|
static |
Semantically identical to Normalize() member method.
Definition at line 370 of file tdate.cxx.
References comphelper::date::normalize().
|
inline |
Date & Date::operator++ | ( | void | ) |
Definition at line 381 of file tdate.cxx.
References GetAsNormalizedDays(), and lcl_DaysToDate().
Date & Date::operator-- | ( | ) |
Definition at line 387 of file tdate.cxx.
References GetAsNormalizedDays(), and lcl_DaysToDate().
Referenced by DateTime::NormalizeTimeRemainderAndApply().
|
inline |
|
inline |
|
inline |
Definition at line 223 of file date.hxx.
References mnDate.
Referenced by DateTime::DateTime(), and DateTime::operator=().
|
inline |
Definition at line 210 of file date.hxx.
References mnDate.
Referenced by DateTime::operator<(), DateTime::operator<=(), DateTime::operator>(), and DateTime::operator>=().
|
inline |
|
inline |
void Date::SetDate | ( | sal_Int32 | nNewDate | ) |
|
private |
Definition at line 34 of file tdate.cxx.
References mnDate, and SAL_WARN_IF.
Referenced by Date(), Normalize(), SetDay(), SetMonth(), and SetYear().
void Date::SetDay | ( | sal_uInt16 | nNewDay | ) |
nNewDay must be <100
Definition at line 115 of file tdate.cxx.
References GetMonth(), GetYear(), and setDateFromDMY().
Referenced by AddYears().
void Date::SetMonth | ( | sal_uInt16 | nNewMonth | ) |
nNewMonth must be <100
Definition at line 120 of file tdate.cxx.
References GetDay(), GetYear(), and setDateFromDMY().
Referenced by AddMonths().
void Date::SetYear | ( | sal_Int16 | nNewYear | ) |
nNewYear must be != 0
Definition at line 125 of file tdate.cxx.
References GetDay(), GetMonth(), and setDateFromDMY().
Referenced by AddMonths(), and AddYears().
|
friend |
|
friend |
|
friend |
|
private |
Definition at line 57 of file date.hxx.
Referenced by Date(), GetAsNormalizedDays(), IsBetween(), operator!=(), operator<(), operator<=(), operator=(), operator==(), operator>(), operator>=(), SetDate(), and setDateFromDMY().