ADTF  3.18.3
DateTime

DateTime class representing both Date and Time. More...

Inheritance diagram for DateTime:
[legend]

Public Member Functions

 DateTime ()
 Default constructor - see Date and Time constructors.
 
 DateTime (int year, int month, int day, int hour, int minute, int second, int microsecond=0)
 Constructor for presetting the stored date and time. More...
 
void set (int year, int month, int day, int hour, int minute, int second, int microsecond=0)
 Set the stored date and time. More...
 
void set (timestamp_t timestamp, TimestampReference timestampReference=TimestampReference::MicroSecondsSinceJulianDateOrigin)
 Set stored data and time from a timestamp. More...
 
timestamp_t toTimestamp (TimestampReference timestampReference=TimestampReference::MicroSecondsSinceJulianDateOrigin) const
 Convert stored date and time to a timestamp. More...
 
std::string format (const std::string &format_str) const
 Format the date/time string. More...
 
bool set (const std::string &format_str, const std::string &date_time)
 Sets the date time given a string. More...
 
- Public Member Functions inherited from Date
 Date ()
 Default constructor - initializes the date to 00.00.0000.
 
 Date (int year, int month, int day)
 Constructor for presetting the stored date. More...
 
void set (int year, int month, int day)
 Sets the stored date. More...
 
bool set (const std::string &date)
 Sets the stored date given a date string. More...
 
void setDay (int day)
 Sets the day of the month. More...
 
int getDay () const
 Get the day of the month. More...
 
void setMonth (int month)
 Set the month. More...
 
int getMonth () const
 Get the month. More...
 
void setYear (int year)
 Set the year. More...
 
int getYear () const
 Get the year. More...
 
std::string format (const std::string &format_str) const
 Creates a string representation of the stored date. More...
 
- Public Member Functions inherited from Time
 Time ()
 Default constructor - initializes the time to 00:00:00,0.
 
 Time (int hour, int minute, int second, int microsecond=0)
 Constructor for presetting the stored time. More...
 
void set (int hour, int minute, int second, int microsecond=0)
 Sets the stored time. More...
 
bool set (const std::string &time)
 Sets the time a given time string. More...
 
void setHour (int hour)
 Set the hour. More...
 
int getHour () const
 Get the hour. More...
 
void setMinute (int minute)
 Set the minute. More...
 
int getMinute () const
 Get the minute. More...
 
void setSecond (int second)
 Set the second. More...
 
int getSecond () const
 Get the second. More...
 
void setMicrosecond (int microsecond)
 Set the microsecond. More...
 
int getMicrosecond () const
 Get the microsecond. More...
 
std::string format (const std::string &format_str) const
 Creates a string representation of the stored time. More...
 

Detailed Description

Constructor & Destructor Documentation

◆ DateTime()

DateTime ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second,
int  microsecond = 0 
)

Constructor for presetting the stored date and time.

Parameters
[in]yearThe year.
[in]monthThe month.
[in]dayThe day of the month.
[in]hourThe hour.
[in]minuteThe minute.
[in]secondThe second.
[in]microsecondThe microsecond.

Member Function Documentation

◆ format()

std::string format ( const std::string &  format_str) 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]format_strFormat-control string.
Returns
The formatted string.
Exceptions
std::invalid_argumentIf the format string is invalid

◆ set() [1/3]

bool set ( const std::string &  format_str,
const std::string &  date_time 
)

Sets the date time given a string.

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]format_strformat string (see list)
[in]date_timestring containing the date / time string
Return values
trueif the conversion is OK, in this case the local data structures are updated with the new values
falseOtherwise
Remarks
the counterpart is DateTime::format

◆ set() [2/3]

void set ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second,
int  microsecond = 0 
)

Set the stored date and time.

Parameters
[in]yearThe year.
[in]monthThe month.
[in]dayThe day of the month.
[in]hourThe hour.
[in]minuteThe minute.
[in]secondThe second.
[in]microsecondThe microsecond.

◆ set() [3/3]

void set ( timestamp_t  timestamp,
TimestampReference  timestampReference = TimestampReference::MicroSecondsSinceJulianDateOrigin 
)

Set stored data and time from a timestamp.

Since the internal data structure uses julian day as the reference point, you have to set the timestampReference parameter to the reference point in time that the timestamp parameter uses.

Remarks
To convert the number of microseconds that have elapsed since midnight on Thursday, 1 January 1970 AC (Unix time) to the number of microseconds that have elapsed since noon on Monday, January 1, 4713 BC (Julian day), you have to add the number 210866803200000000 to the timestamp
Parameters
[in]timestampThe timestamp in number of microseconds that have elapsed since the reference point defined in the timestampReference parameter.
[in]timestampReferenceThe reference point in time when the count in microseconds was started. Default is julian day.

◆ toTimestamp()

timestamp_t toTimestamp ( TimestampReference  timestampReference = TimestampReference::MicroSecondsSinceJulianDateOrigin) const

Convert stored date and time to a timestamp.

Since the internal data structure uses julian day as the reference point, this is the default reference point of the timestamp returned by its member function. You can change the reference point in time by the timestampReference parameter.

Remarks
To get the number of microseconds that have elapsed since midnight on Thursday, 1 January 1970 AC (Unix time), you have to subtract the number 210866803200000000 from the result. This is the number of microseconds that have elapsed since the Julian day up to the reference point in time in Unix time.
Parameters
[in]timestampReferenceThe reference point in time the returned timestamp should refer to.
Returns
The timestamp in number of microseconds that have elapsed since the point in time defined by the timestampReference parameter. The default reference point int time is julian day.