ADTF  3.18.3
workspace/conan/dev_essential/1.3.4/dw/stable/package/aef85909f792a5a628750d25016a24323084963f/include/a_util/datetime/datetime.h
Go to the documentation of this file.
1 
16 #ifndef _A_UTILS_UTIL_DATETIME_DATETIME_HEADER_INCLUDED_
17 #define _A_UTILS_UTIL_DATETIME_DATETIME_HEADER_INCLUDED_
18 
19 #include <a_util/base/types.h> //timestamp_t
20 
21 #include <string> //std::string
22 
23 namespace a_util {
24 namespace datetime {
29 class Date {
30 public:
32  Date();
33 
40  Date(int year, int month, int day);
41 
48  void set(int year, int month, int day);
49 
62  bool set(const std::string& date);
63 
68  void setDay(int day);
69 
74  int getDay() const;
75 
80  void setMonth(int month);
81 
86  int getMonth() const;
87 
92  void setYear(int year);
93 
98  int getYear() const;
99 
112  std::string format(const std::string& format_str) const;
113 
114 private:
115  int _day;
116  int _month;
117  int _year;
118 };
119 
126 bool operator==(const Date& lhs, const Date& rhs);
127 
134 bool operator!=(const Date& lhs, const Date& rhs);
135 
141 
147 
152 class Time {
153 public:
155  Time();
156 
164  Time(int hour, int minute, int second, int microsecond = 0);
165 
173  void set(int hour, int minute, int second, int microsecond = 0);
174 
187  bool set(const std::string& time);
188 
193  void setHour(int hour);
194 
199  int getHour() const;
200 
205  void setMinute(int minute);
206 
211  int getMinute() const;
212 
217  void setSecond(int second);
218 
223  int getSecond() const;
224 
229  void setMicrosecond(int microsecond);
230 
235  int getMicrosecond() const;
236 
244  std::string format(const std::string& format_str) const;
245 
246 private:
247  int _hour;
248  int _minute;
249  int _second;
250  int _microsecond;
251 };
252 
259 bool operator==(const Time& lhs, const Time& rhs);
260 
267 bool operator!=(const Time& lhs, const Time& rhs);
268 
274 
280 
303 };
304 
306 class DateTime : public Date, public Time {
307 public:
310 
321  DateTime(int year, int month, int day, int hour, int minute, int second, int microsecond = 0);
322 
333  void set(int year, int month, int day, int hour, int minute, int second, int microsecond = 0);
334 
359  void set(timestamp_t timestamp,
360  TimestampReference timestampReference =
362 
387 
425 #ifdef _WIN32
439 #else
445 #endif // _WIN32
452  std::string format(const std::string& format_str) const;
453 
475  bool set(const std::string& format_str, const std::string& date_time);
476 };
477 
484 bool operator==(const DateTime& lhs, const DateTime& rhs);
485 
492 bool operator!=(const DateTime& lhs, const DateTime& rhs);
493 
499 
505 
506 } // namespace datetime
507 } // namespace a_util
508 
509 #endif // _A_UTILS_UTIL_DATETIME_DATETIME_HEADER_INCLUDED_
void setMonth(int month)
Set the month.
int getMonth() const
Get the month.
void setYear(int year)
Set the year.
bool set(const std::string &date)
Sets the stored date given a date string.
std::string format(const std::string &format_str) const
Creates a string representation of the stored date.
Date(int year, int month, int day)
Constructor for presetting the stored date.
void set(int year, int month, int day)
Sets the stored date.
int getDay() const
Get the day of the month.
void setDay(int day)
Sets the day of the month.
int getYear() const
Get the year.
Date()
Default constructor - initializes the date to 00.00.0000.
bool set(const std::string &format_str, const std::string &date_time)
Sets the date time given a string.
DateTime(int year, int month, int day, int hour, int minute, int second, int microsecond=0)
Constructor for presetting the stored date and time.
DateTime()
Default constructor - see Date and Time constructors.
void set(timestamp_t timestamp, TimestampReference timestampReference=TimestampReference::MicroSecondsSinceJulianDateOrigin)
Set stored data and time from a timestamp.
void set(int year, int month, int day, int hour, int minute, int second, int microsecond=0)
Set the stored date and time.
timestamp_t toTimestamp(TimestampReference timestampReference=TimestampReference::MicroSecondsSinceJulianDateOrigin) const
Convert stored date and time to a timestamp.
void setMinute(int minute)
Set the minute.
void setSecond(int second)
Set the second.
int getSecond() const
Get the second.
int getHour() const
Get the hour.
bool set(const std::string &time)
Sets the time a given time string.
Time()
Default constructor - initializes the time to 00:00:00,0.
int getMicrosecond() const
Get the microsecond.
std::string format(const std::string &format_str) const
Creates a string representation of the stored time.
int getMinute() const
Get the minute.
void setMicrosecond(int microsecond)
Set the microsecond.
void setHour(int hour)
Set the hour.
Time(int hour, int minute, int second, int microsecond=0)
Constructor for presetting the stored time.
void set(int hour, int minute, int second, int microsecond=0)
Sets the stored time.
std::int64_t timestamp_t
Type of a timestamp value. If not otherwise stated, always in microseconds.
DateTime getCurrentSystemDateTime()
Get the current date and time (in UTC format).
bool operator==(const Date &lhs, const Date &rhs)
Compare two dates for equality.
Time getCurrentSystemTime()
Get the current time (in UTC format).
Date getCurrentLocalDate()
Retrieves the current date (hardware clock with respect to timezone).
DateTime getCurrentLocalDateTime()
Get the current date and time (hardware clock with respect to timezone).
Time getCurrentLocalTime()
Get the current time (hardware clock with respect to timezone).
@ MicroSecondsSinceUnixTimeOrigin
Reference point in time is midnight on Thursday, 1 January 1970 AC (Unix time)
Date getCurrentSystemDate()
Retrieves the current system date (in UTC format).
bool operator!=(const Date &lhs, const Date &rhs)
Compare two dates for inequality.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24
Public types and functions defining a_util core functionality.