LibreOffice Module comphelper (master) 1
Functions | Variables
comphelper::date Namespace Reference

Functions

sal_Int32 convertDateToDaysNormalizing (sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
 Obtain days from zero for a given date, with normalizing. More...
 
bool isValidDate (sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
 Whether date is a valid date. More...
 
void convertDaysToDate (sal_Int32 nDays, sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_Int16 &rYear)
 Obtain date for a days from zero value. More...
 
bool normalize (sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_Int16 &rYear)
 Normalize date, i.e. More...
 
constexpr sal_Int32 YearToDays (sal_Int16 nYear)
 Days until start of year from zero, so month and day of month can be added. More...
 
constexpr bool isLeapYear (sal_Int16 nYear)
 Whether year is a leap year. More...
 
constexpr sal_uInt16 getDaysInMonth (sal_uInt16 nMonth, sal_Int16 nYear)
 Get number of days in month of year. More...
 
constexpr sal_Int32 convertDateToDays (sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
 Obtain days from zero for a given date, without normalizing. More...
 

Variables

constexpr sal_Int32 MIN_DAYS = -11968265
 
constexpr sal_Int32 MAX_DAYS = 11967900
 
constexpr sal_Int16 kYearMax = SAL_MAX_INT16
 
constexpr sal_Int16 kYearMin = SAL_MIN_INT16
 
constexpr sal_Int32 nNullDateDays = convertDateToDays(30, 12, 1899)
 

Function Documentation

◆ convertDateToDays()

constexpr sal_Int32 comphelper::date::convertDateToDays ( sal_uInt16  nDay,
sal_uInt16  nMonth,
sal_Int16  nYear 
)
inlineconstexpr

Obtain days from zero for a given date, without normalizing.

nDay, nMonth, nYear MUST form a valid proleptic Gregorian calendar date.

Definition at line 82 of file date.hxx.

References getDaysInMonth(), i, and YearToDays().

Referenced by convertDateToDaysNormalizing().

◆ convertDateToDaysNormalizing()

COMPHELPER_DLLPUBLIC sal_Int32 comphelper::date::convertDateToDaysNormalizing ( sal_uInt16  nDay,
sal_uInt16  nMonth,
sal_Int16  nYear 
)

Obtain days from zero for a given date, with normalizing.

nDay, nMonth, nYear may be out-of-bounds and are adjusted/normalized.

Parameters
nYearMust be != 0, unless nMonth > 12.

Definition at line 48 of file date.cxx.

References convertDateToDays(), nNullDateDays, and normalize().

◆ convertDaysToDate()

COMPHELPER_DLLPUBLIC void comphelper::date::convertDaysToDate ( sal_Int32  nDays,
sal_uInt16 &  rDay,
sal_uInt16 &  rMonth,
sal_Int16 &  rYear 
)

Obtain date for a days from zero value.

Definition at line 69 of file date.cxx.

References getDaysInMonth(), i, isLeapYear(), kYearMax, kYearMin, MAX_DAYS, MIN_DAYS, and YearToDays().

◆ getDaysInMonth()

constexpr sal_uInt16 comphelper::date::getDaysInMonth ( sal_uInt16  nMonth,
sal_Int16  nYear 
)
inlineconstexpr

Get number of days in month of year.

Parameters
nYearMUST be != 0.

Definition at line 67 of file date.hxx.

References isLeapYear(), and n.

Referenced by convertDateToDays(), convertDaysToDate(), isValidDate(), and normalize().

◆ isLeapYear()

constexpr bool comphelper::date::isLeapYear ( sal_Int16  nYear)
inlineconstexpr

Whether year is a leap year.

Leap years BCE are -1, -5, -9, ... See https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar#Usage https://en.wikipedia.org/wiki/0_(year)#History_of_astronomical_usage

Parameters
nYearMUST be != 0.

Definition at line 54 of file date.hxx.

Referenced by convertDaysToDate(), and getDaysInMonth().

◆ isValidDate()

COMPHELPER_DLLPUBLIC bool comphelper::date::isValidDate ( sal_uInt16  nDay,
sal_uInt16  nMonth,
sal_Int16  nYear 
)

Whether date is a valid date.

Definition at line 58 of file date.cxx.

References getDaysInMonth().

Referenced by normalize().

◆ normalize()

COMPHELPER_DLLPUBLIC bool comphelper::date::normalize ( sal_uInt16 &  rDay,
sal_uInt16 &  rMonth,
sal_Int16 &  rYear 
)

Normalize date, i.e.

add days or months to form a proper proleptic Gregorian calendar date, unless all values are 0.

Parameters
rYearMust be != 0, unless rMonth > 12.
Returns
<TRUE> if date was normalized, <FALSE> if it was valid already or empty (all values 0).

Definition at line 127 of file date.cxx.

References getDaysInMonth(), isValidDate(), kYearMax, and kYearMin.

Referenced by convertDateToDaysNormalizing().

◆ YearToDays()

constexpr sal_Int32 comphelper::date::YearToDays ( sal_Int16  nYear)
inlineconstexpr

Days until start of year from zero, so month and day of month can be added.

year 1 => 0 days, year 2 => 365 days, ... year -1 => -366 days, year -2 => -731 days, ...

Parameters
nYearMUST be != 0.

Definition at line 37 of file date.hxx.

References y.

Referenced by convertDateToDays(), and convertDaysToDate().

Variable Documentation

◆ kYearMax

constexpr sal_Int16 comphelper::date::kYearMax = SAL_MAX_INT16
constexpr

Definition at line 42 of file date.cxx.

Referenced by convertDaysToDate(), and normalize().

◆ kYearMin

constexpr sal_Int16 comphelper::date::kYearMin = SAL_MIN_INT16
constexpr

Definition at line 43 of file date.cxx.

Referenced by convertDaysToDate(), and normalize().

◆ MAX_DAYS

constexpr sal_Int32 comphelper::date::MAX_DAYS = 11967900
constexpr

Definition at line 40 of file date.cxx.

Referenced by convertDaysToDate().

◆ MIN_DAYS

constexpr sal_Int32 comphelper::date::MIN_DAYS = -11968265
constexpr

Definition at line 39 of file date.cxx.

Referenced by convertDaysToDate().

◆ nNullDateDays

constexpr sal_Int32 comphelper::date::nNullDateDays = convertDateToDays(30, 12, 1899)
constexpr

Definition at line 45 of file date.cxx.

Referenced by convertDateToDaysNormalizing().