ADTF  3.18.2
cDate

Date class. More...

Inheritance diagram for cDate:
[legend]

Public Member Functions

 cDate ()
 Default constructor.
 
 cDate (tInt nYear, tInt nMonth, tInt nDay)
 Constructor for presetting the stored date. More...
 
 cDate (const tDate *psDate)
 Constructor that presets the stored date from a given data structure. More...
 
 cDate (const cDate &oDate)
 Copy constructor. More...
 
virtual ~cDate ()
 Destructor.
 
cDateoperator= (const cDate &oDate)
 The cDate assignment (=) operator reinitializes an existing cDate object with new data. More...
 
tVoid Get (tDate *psDate) const
 Fills a date structure with the stored values. More...
 
tVoid Set (tInt nYear, tInt nMonth, tInt nDay)
 Sets the stored date. More...
 
tVoid Set (const tDate *psDate)
 Sets the stored date. More...
 
tVoid Set (const cDate &oDate)
 Sets the stored date. More...
 
tVoid SetDay (tInt nDay)
 Sets the day of the month. More...
 
tInt GetDay () const
 Get the day of the month. More...
 
tVoid SetMonth (tInt nMonth)
 Set the month. More...
 
tInt GetMonth () const
 Get the month. More...
 
tVoid SetYear (tInt nYear)
 Set the year. More...
 
tInt GetYear () const
 Get the year. More...
 
tBool IsLeapYear () const
 Check whether or not the stored year is a leap year. More...
 
cString Format (const cString &strFormat) const
 Creates a string representation of the stored date. More...
 
tBool Valid ()
 Check whether or not the stored date is valid. More...
 

Static Public Member Functions

static cDate GetCurrentDate ()
 Retrieves the current date (hardware clock with respect to timezone). More...
 
static cDate GetCurrentSystemDate ()
 Retrieves the current system date (in UTC format). More...
 
static tBool IsLeapYear (tInt nYear)
 Check whether or not the specified year is a leap year. More...
 
static tResult GetDateFromString (cDate &oDate, const cString &strDate)
 Converts a given date string into a date and fill the given date. More...
 
static tInt GetNumOfDaysInMonth (const tInt nMonth, const tInt nYear)
 Get the number of days of the given month and year (also consider the leap years). More...
 
static tInt64 DateDiff (const cString &str, const cString &strDate1, const cString &strDate2)
 Calculates the difference between two date strings. More...
 
static tInt64 DateDiff (const cString &str, const cDate &oDate1, const cDate &oDate2)
 Calculates the difference between two dates. More...
 

Protected Attributes

tDate m_sDate
 Internally used date structure.
 

Detailed Description

Constructor & Destructor Documentation

◆ cDate() [1/3]

cDate ( tInt  nYear,
tInt  nMonth,
tInt  nDay 
)

Constructor for presetting the stored date.

Parameters
nYearThe year.
nMonthThe month.
nDayThe day of the month.

◆ cDate() [2/3]

cDate ( const tDate psDate)

Constructor that presets the stored date from a given data structure.

Parameters
psDateThe date structure.

◆ cDate() [3/3]

cDate ( const cDate oDate)

Copy constructor.

Parameters
oDate

Member Function Documentation

◆ DateDiff() [1/2]

static tInt64 DateDiff ( const cString str,
const cDate oDate1,
const cDate oDate2 
)
static

Calculates the difference between two dates.

Note
The second date has to be later on first date. Daylight-saving time within the two dates is not supported.
Parameters
[in]strThe format string of the output.

The formatting codes are listed below:

  • d Difference between two dates in days
  • m Difference between two dates in months
  • y Difference between two dates in years
  • w Difference between two dates in weeks
Parameters
[in]oDate1The first date.
[in]oDate2The second date.
Return values
ERR_INVALID_ARGThe output format string length is 0 or any unsupported character was found.
ERR_OUT_OF_RANGEThe first or second date is invalid (see cDate::Valid).
ERR_NOT_SUPPORTEDFirst date is later on second date.
Returns
The difference between two dates according to the output format string.

◆ DateDiff() [2/2]

static tInt64 DateDiff ( const cString str,
const cString strDate1,
const cString strDate2 
)
static

Calculates the difference between two date strings.

Note
The second date has to be later on first date. Daylight-saving time within the two dates is not supported.
Parameters
[in]strThe format string of the output.

The formatting codes are listed below:

  • d Difference between two dates in days
  • m Difference between two dates in months
  • y Difference between two dates in years
  • w Difference between two dates in weeks
Parameters
[in]strDate1The string contains the first date as string.
[in]strDate2The string contains the second date as string.
Return values
ERR_INVALID_ARGThe output format string length is 0 or any unsupported character was found.
ERR_OUT_OF_RANGEThe first or second date is invalid (see cDate::Valid).
ERR_NOT_SUPPORTEDFirst date is later on second date.
Returns
The difference between two dates according to the output format string.

◆ Format()

cString Format ( const cString strFormat) const

Creates a string representation of the stored date.

This format identifiers are supported: a A b B c d H I j m M p S U w W x X y Y Percent signs are escaped by %% %#<character> is not supported because it only makes sense with Z which is also not supported

Parameters
strFormatThe format of the string representation (see cDateTime::Format, can be empty).
Returns
A string representation of the stored date.

◆ Get()

tVoid Get ( tDate psDate) const

Fills a date structure with the stored values.

Parameters
psDateThe structure to fill.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetCurrentDate()

static cDate GetCurrentDate ( )
static

Retrieves the current date (hardware clock with respect to timezone).

Returns
The current date.

◆ GetCurrentSystemDate()

static cDate GetCurrentSystemDate ( )
static

Retrieves the current system date (in UTC format).

Returns
The current date.

◆ GetDateFromString()

static tResult GetDateFromString ( cDate oDate,
const cString strDate 
)
static

Converts a given date string into a date and fill the given date.

This string formats are supported: yyyy.mm.dd or dd.mm.yyyy

  • yyyy Year as decimal number (zero-padded 0000..9999)
  • mm Month as decimal number (zero-padded 01..12)
  • dd Day of month as decimal number (zero-padded 01..31)
  • . Separator for year.month.day or day.month.year
Parameters
[out]oDateThe date to fill according to the given date string.
[in]strDateThe string contains the given date as string.
Return values
ERR_INVALID_ARGThe date string length is 0 or any unsupported character was found.
ERR_UNKNOWN_FORMATThe date string format is invalid (e.g. yy.mm.dd).
ERR_OUT_OF_RANGEThe date is invalid (see cDate::Valid).
ERR_NOERROR

◆ GetDay()

tInt GetDay ( ) const

Get the day of the month.

Returns
The day of the month.
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetMonth()

tInt GetMonth ( ) const

Get the month.

Returns
The month.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetNumOfDaysInMonth()

static tInt GetNumOfDaysInMonth ( const tInt  nMonth,
const tInt  nYear 
)
static

Get the number of days of the given month and year (also consider the leap years).

Parameters
[in]nMonthThe Month.
[in]nYearThe Year.
Return values
ERR_OUT_OF_RANGEThe month or year is invalid (see cDate::Valid).
Returns
The number of days of the given month and year.

◆ GetYear()

tInt GetYear ( ) const

Get the year.

Returns
The year.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ IsLeapYear() [1/2]

tBool IsLeapYear ( ) const

Check whether or not the stored year is a leap year.

Returns
Whether or not the stored year is a leap year.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ IsLeapYear() [2/2]

static tBool IsLeapYear ( tInt  nYear)
static

Check whether or not the specified year is a leap year.

Parameters
nYearThe Year.
Returns
Whether or not the specified year is a leap year.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ operator=()

cDate& operator= ( const cDate oDate)

The cDate assignment (=) operator reinitializes an existing cDate object with new data.

Parameters
oDate[in] cDate object to be assigned.
Returns
Reference to accessed cDate object.

◆ Set() [1/3]

tVoid Set ( const cDate oDate)

Sets the stored date.

Parameters
oDateThe new date.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ Set() [2/3]

tVoid Set ( const tDate psDate)

Sets the stored date.

Parameters
psDateThe new date.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ Set() [3/3]

tVoid Set ( tInt  nYear,
tInt  nMonth,
tInt  nDay 
)

Sets the stored date.

Parameters
nYearThe year.
nMonthThe month.
nDayThe day of the month.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ SetDay()

tVoid SetDay ( tInt  nDay)

Sets the day of the month.

Parameters
nDayThe day of the month.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ SetMonth()

tVoid SetMonth ( tInt  nMonth)

Set the month.

Parameters
nMonthThe month.
Returns
Standard Result Code.
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ SetYear()

tVoid SetYear ( tInt  nYear)

Set the year.

Parameters
nYearThe year.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ Valid()

tBool Valid ( )

Check whether or not the stored date is valid.

Range table:

  • Year (0000..9999)
  • Month (01..12)
  • Day Jan, Mar, May, Jul, Aug, Oct, Dec (01..31)
  • Day Apr, Jun, Sep, Nov (01..30)
  • Day Feb (01..28)
  • Day Feb leap year (01..29)
Returns
Whether or not the specified date is valid.