ADTF  3.18.2
cDateTime

Date and time class. More...

Inheritance diagram for cDateTime:
[legend]

Public Member Functions

 cDateTime ()
 Default constructor.
 
 cDateTime (tInt nYear, tInt nMonth, tInt nDay, tInt nHour, tInt nMinute, tInt nSecond, tInt nMicroseconds=0)
 Constructor for presetting the stored date and time. More...
 
 cDateTime (const tDateTime *psDateTime)
 Constructor for presetting the stored date and time. More...
 
 cDateTime (const cDateTime &oDateTime)
 Constructor for presetting the stored date and time. More...
 
virtual ~cDateTime ()
 Destructor.
 
cDateTimeoperator= (const cDateTime &oDateTime)
 The cDateTime assignment (=) operator reinitializes an existing cDateTime object with new data. More...
 
tVoid Get (tDateTime *psDateTime) const
 Fill a data and time structure with stored values. More...
 
tVoid Set (tInt nYear, tInt nMonth, tInt nDay, tInt nHour, tInt nMinute, tInt nSecond, tInt nMicroseconds=0)
 Set the stored date and time. More...
 
tVoid Set (const tDateTime *psDateTime)
 Set the stored date and time. More...
 
tVoid Set (const cDateTime &oDateTime)
 Set the stored date and time. More...
 
tTimeStamp ToTimeStamp () const
 Convert stored date and time to a timestamp. More...
 
cString Format (const cString &strFormat) const
 Format the date/time string. More...
 
tResult UnFormat (const cString &strFormat, const cString &strDateTime)
 converts a given string into a cDateTime. More...
 
- Public Member Functions inherited from cDate
 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...
 
- Public Member Functions inherited from cTime
 cTime ()
 Default constructor.
 
 cTime (tInt nHour, tInt nMinute, tInt nSecond, tInt nMicroseconds=0)
 Constructor for presetting the stored time. More...
 
 cTime (const tTime *psTime)
 Constructor for presetting the stored time. More...
 
 cTime (const cTime &oTime)
 Copy constructor. More...
 
cTimeoperator= (const cTime &oTime)
 The cTime assignment (=) operator reinitializes an existing cTime object with new data. More...
 
virtual ~cTime ()
 Destructor.
 
tVoid Get (tTime *psTime) const
 Fills a time structure with the stored values. More...
 
tVoid Set (tInt nHour, tInt nMinute, tInt nSecond, tInt nMicroseconds=0)
 Sets the stored time. More...
 
tVoid Set (const tTime *psTime)
 Sets the stored time. More...
 
tVoid Set (const cTime &oTime)
 Sets the stored time. More...
 
tVoid SetHour (tInt nHour)
 Set the hour. More...
 
tInt GetHour () const
 Get the hour. More...
 
tVoid SetMinute (tInt nMinute)
 Set the minute. More...
 
tInt GetMinute () const
 Get the minute. More...
 
tVoid SetSecond (tInt nSecond)
 Set the second. More...
 
tInt GetSecond () const
 Get the second. More...
 
tVoid SetMicroseconds (tInt nMicroseconds)
 Set the microsecond. More...
 
tInt Microseconds () const
 Get the microsecond. More...
 
cString Format (const cString &strFormat) const
 Creates a string representation of the stored time. More...
 
tBool Valid ()
 Check whether or not the stored time is valid. More...
 

Static Public Member Functions

static cDateTime GetCurrentDateTime ()
 Get the current date and time (hardware clock with respect to timezone). More...
 
static cDateTime GetCurrentSystemDateTime ()
 Get the current date and time (in UTC format). More...
 
static cDateTime FromTimeStamp (tTimeStamp tmDateTime)
 Set stored data and time to a timestamp. More...
 
static tTimeStamp GetDiff (const cDateTime &dt1, const cDateTime &dt2)
 Calculates the difference between two dates in microseconds. More...
 
- Static Public Member Functions inherited from cDate
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...
 
- Static Public Member Functions inherited from cTime
static cTime GetCurrentTime ()
 Get the current time (hardware clock with respect to timezone). More...
 
static cTime GetCurrentSystemTime ()
 Get the current time (in UTC format). More...
 
static tResult GetTimeFromString (cTime &oTime, const cString &strTime)
 Converts a given time string into a time and fill the given time. More...
 
static tInt TimeDiff (const cString &str, const cString &strTime1, const cString &strTime2)
 Calculates the difference between two time strings. More...
 
static tInt TimeDiff (const cString &str, const cTime &oTime1, const cTime &oTime2)
 Calculates the difference between two times. More...
 
static cTime FromTimeStamp (tTimeStamp tmTime)
 Converts a given timestamp into a time. More...
 

Additional Inherited Members

- Protected Attributes inherited from cDate
tDate m_sDate
 Internally used date structure.
 
- Protected Attributes inherited from cTime
tTime m_sTime
 Internally used time structure.
 

Detailed Description

Constructor & Destructor Documentation

◆ cDateTime() [1/3]

cDateTime ( tInt  nYear,
tInt  nMonth,
tInt  nDay,
tInt  nHour,
tInt  nMinute,
tInt  nSecond,
tInt  nMicroseconds = 0 
)

Constructor for presetting the stored date and time.

Parameters
nYearThe year.
nMonthThe month.
nDayThe day of the month.
nHourThe hour.
nMinuteThe minute.
nSecondThe second.
nMicrosecondsThe microsecond.

◆ cDateTime() [2/3]

cDateTime ( const tDateTime psDateTime)

Constructor for presetting the stored date and time.

Parameters
psDateTimeThe date and time.

◆ cDateTime() [3/3]

cDateTime ( const cDateTime oDateTime)

Constructor for presetting the stored date and time.

Parameters
oDateTimeThe date and time.

Member Function Documentation

◆ Format()

cString Format ( const cString strFormat) const

Format the date/time string.

Returns a formated string containing date/time information. The format argument consists of one or more codes; as in printf, the formatting codes are preceded by a percent sign ('%'). Characters that do not begin with % are copied unchanged.

The formatting codes are listed below:

  • %a Abbreviated weekday name
  • %A Full weekday name
  • %b Abbreviated month name
  • %B Full month name
  • %c Date and time representation appropriate for locale
  • %d Day of month as decimal number (01 31)
  • %H Hour in 24-hour format (00 23)
  • %I Hour in 12-hour format (01 12)
  • %j Day of year as decimal number (001 366)
  • %m Month as decimal number (01 12)
  • %M Minute as decimal number (00 59)
  • %p Current locale's A.M./P.M. indicator for 12-hour clock
  • %S Second as decimal number (00 59)
  • %U Week of year as decimal number, with Sunday as first day of week (00 53)
  • %w Weekday as decimal number (0 6; Sunday is 0)
  • %W Week of year as decimal number, with Monday as first day of week (00 53)
  • %x Date representation for current locale
  • %X Time representation for current locale
  • %y Year without century, as decimal number (00 99)
  • %Y Year with century, as decimal number
  • %z,Z Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
  • %% Percent sign

As in the printf() function, the # flag may prefix any formatting code. In that case, the meaning of the format code is changed as follows.
%#a, %#A, %#b, %#B
Characters are converted to uppercase.
For example: "TUESDAY", "MARCH".

Parameters
[in]strFormatFormat-control string.
Returns
the formatted string.
Remarks
The counterpart is cDateTime::UnFormat

◆ FromTimeStamp()

static cDateTime FromTimeStamp ( tTimeStamp  tmDateTime)
static

Set stored data and time to a timestamp.

Parameters
tmDateTimeThe timestamp.
Returns
An object corresponding to tmDateTime.

◆ Get()

tVoid Get ( tDateTime psDateTime) const

Fill a data and time structure with stored values.

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

◆ GetCurrentDateTime()

static cDateTime GetCurrentDateTime ( )
static

Get the current date and time (hardware clock with respect to timezone).

Returns
The current date and time.

Referenced by A_UTILS_NS::log::add_entry().

◆ GetCurrentSystemDateTime()

static cDateTime GetCurrentSystemDateTime ( )
static

Get the current date and time (in UTC format).

Returns
The current date and time.

◆ GetDiff()

static tTimeStamp GetDiff ( const cDateTime dt1,
const cDateTime dt2 
)
static

Calculates the difference between two dates in microseconds.

Parameters
dt1The first date.
dt2The second date.
Returns
The difference in microseconds.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ operator=()

cDateTime& operator= ( const cDateTime oDateTime)

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

Parameters
oDateTime[in] cDateTime object to be assigned.
Returns
Reference to accessed cDateTime object.

◆ Set() [1/3]

tVoid Set ( const cDateTime oDateTime)

Set the stored date and time.

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

◆ Set() [2/3]

tVoid Set ( const tDateTime psDateTime)

Set the stored date and time.

Parameters
psDateTimeThe date and time.
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,
tInt  nHour,
tInt  nMinute,
tInt  nSecond,
tInt  nMicroseconds = 0 
)

Set the stored date and time.

Parameters
nYearThe year.
nMonthThe month.
nDayThe day of the month.
nHourThe hour.
nMinuteThe minute.
nSecondThe second.
nMicrosecondsThe microsecond.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ ToTimeStamp()

tTimeStamp ToTimeStamp ( ) const

Convert stored date and time to a timestamp.

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

Referenced by A_UTILS_NS::log::add_entry().

◆ UnFormat()

tResult UnFormat ( const cString strFormat,
const cString strDateTime 
)

converts a given string into a cDateTime.

The formatting codes are listed below:

  • %b Abbreviated month name
  • %B Full month name
  • %m Month as decimal number (space-padded _1..12, zero-padded 01..12, normal 1 -12)
  • %d Day of month as decimal number (space-padded _1..31, zero-padded 01..31, normal 1-31)
  • %y Year without century, as decimal number (00 99)
  • %Y Year with century, as decimal number
  • %H Hour in 24-hour format (00 23)
  • %I Hour in 12-hour format (01 12)
  • %p AM / PM and am / pm detection
  • %M Minute as decimal number (00 59)
  • %S Second as decimal number (00 59)
Parameters
[in]strFormatformat string (see list)
[in]strDateTimestring containing the date / time string
Return values
ERROR_NOERRORconversion is OK, in this case the local data structures ares updated with the new values
Remarks
the counterpart is cDateTime::Format