ADTF
Loading...
Searching...
No Matches
a_util::datetime::DateTime Class Reference

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

#include <datetime.h>

Inherits a_util::datetime::Date, and a_util::datetime::Time.

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)
 
void set (int year, int month, int day, int hour, int minute, int second, int microsecond=0)
 
void set (timestamp_t timestamp, TimestampReference timestampReference=TimestampReference::MicroSecondsSinceJulianDateOrigin)
 
timestamp_t toTimestamp (TimestampReference timestampReference=TimestampReference::MicroSecondsSinceJulianDateOrigin) const
 
std::string format (const std::string &format_str) const
 
bool set (const std::string &format_str, const std::string &date_time)
 
- Public Member Functions inherited from a_util::datetime::Date
 Date ()
 Default constructor - initializes the date to 00.00.0000.
 
 Date (int year, int month, int day)
 
void set (int year, int month, int day)
 
bool set (const std::string &date)
 
void setDay (int day)
 
int getDay () const
 
void setMonth (int month)
 
int getMonth () const
 
void setYear (int year)
 
int getYear () const
 
std::string format (const std::string &format_str) const
 
- Public Member Functions inherited from a_util::datetime::Time
 Time ()
 Default constructor - initializes the time to 00:00:00,0.
 
 Time (int hour, int minute, int second, int microsecond=0)
 
void set (int hour, int minute, int second, int microsecond=0)
 
bool set (const std::string &time)
 
void setHour (int hour)
 
int getHour () const
 
void setMinute (int minute)
 
int getMinute () const
 
void setSecond (int second)
 
int getSecond () const
 
void setMicrosecond (int microsecond)
 
int getMicrosecond () const
 
std::string format (const std::string &format_str) const
 

Detailed Description

DateTime class representing both Date and Time.

Constructor & Destructor Documentation

◆ DateTime()

a_util::datetime::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 a_util::datetime::DateTime::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 a_util::datetime::DateTime::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 a_util::datetime::DateTime::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 a_util::datetime::DateTime::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 a_util::datetime::DateTime::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.

The documentation for this class was generated from the following file: