Wall-clock date and time based on std::chrono::system_clock. More...
#include <datetime.h>
Public Types | |
| using | Value = std::chrono::system_clock::time_point |
| Underlying time point type from the system clock. | |
Public Member Functions | |
| DateTime () | |
| Default constructor. The resulting time point is epoch (uninitialized). | |
| DateTime (const Value &val) | |
| Constructs a DateTime from a system_clock time point. | |
| DateTime (std::tm val) | |
| Constructs a DateTime from a broken-down std::tm value. | |
| DateTime (time_t val) | |
| Constructs a DateTime from a time_t value. | |
| DateTime | operator+ (const DateTime &other) const |
| Returns the sum of two DateTime time points. | |
| DateTime | operator- (const DateTime &other) const |
| Returns the difference of two DateTime time points. | |
| DateTime & | operator+= (const DateTime &other) |
| Adds another DateTime's duration to this one. | |
| DateTime & | operator-= (const DateTime &other) |
| Subtracts another DateTime's duration from this one. | |
| DateTime | operator+ (double seconds) const |
| Returns a DateTime offset forward by the given number of seconds. | |
| DateTime | operator- (double seconds) const |
| Returns a DateTime offset backward by the given number of seconds. | |
| DateTime & | operator+= (double seconds) |
| Advances this DateTime forward by the given number of seconds. | |
| DateTime & | operator-= (double seconds) |
| Moves this DateTime backward by the given number of seconds. | |
| bool | operator== (const DateTime &other) const |
| Returns true if both DateTimes represent the same time point. | |
| bool | operator!= (const DateTime &other) const |
| Returns true if the DateTimes represent different time points. | |
| bool | operator< (const DateTime &other) const |
Returns true if this DateTime is earlier than other. | |
| bool | operator<= (const DateTime &other) const |
Returns true if this DateTime is earlier than or equal to other. | |
| bool | operator> (const DateTime &other) const |
Returns true if this DateTime is later than other. | |
| bool | operator>= (const DateTime &other) const |
Returns true if this DateTime is later than or equal to other. | |
| String | toString (const char *format=DefaultFormat) const |
| Formats the DateTime as a string. | |
| operator String () const | |
| Implicit conversion to String via toString(). | |
| time_t | toTimeT () const |
| Converts the DateTime to a POSIX time_t value. | |
| double | toDouble () const |
| Converts the DateTime to a floating-point seconds value. | |
| Value | value () const |
| Returns the underlying system_clock time point. | |
Static Public Member Functions | |
| static DateTime | now () |
| Returns a DateTime representing the current wall-clock time. | |
| static DateTime | fromString (const String &str, const char *fmt=DefaultFormat, Error *err=nullptr) |
| Parses a DateTime from a formatted string. | |
| static DateTime | fromNow (const String &description) |
| Creates a DateTime relative to the current time from a natural-language description. | |
| static String | strftime (const std::tm &tm, const char *format=DefaultFormat) |
| Formats a std::tm value using a strftime-style format string. | |
Static Public Attributes | |
| static constexpr const char * | DefaultFormat = "%F %T" |
| Default strftime format string ("%F %T" = "YYYY-MM-DD HH:MM:SS"). | |
Wall-clock date and time based on std::chrono::system_clock.
Wraps a system_clock time_point and provides construction from strings, time_t, and std::tm values. Supports arithmetic with other DateTime instances and with floating-point second offsets. Output formatting
Constructs a DateTime from a system_clock time point.
| val | The time point value. |
|
inline |
Constructs a DateTime from a broken-down std::tm value.
| val | The calendar time to convert. |
|
inline |
Constructs a DateTime from a time_t value.
| val | The POSIX time value. |
|
inlinestatic |
Parses a DateTime from a formatted string.
| str | The date/time string to parse. |
| fmt | The strftime-style format string (default: DefaultFormat). |
| err | Optional error output; set to Error::Invalid on parse failure. |
Formats a std::tm value using a strftime-style format string.
| tm | The broken-down time to format. |
| format | The strftime-style format string (default: DefaultFormat). |
|
inline |
Converts the DateTime to a floating-point seconds value.
| String DateTime::toString | ( | const char * | format = DefaultFormat | ) | const |
Formats the DateTime as a string.
| format | The strftime-style format string (default: DefaultFormat). |
|
inline |
Converts the DateTime to a POSIX time_t value.
|
inline |
Returns the underlying system_clock time point.