C++ Utilities
4.6.1
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
|
Represents an instant in time, typically expressed as a date and time of day. More...
#include <datetime.h>
Public Member Functions | |
constexpr | DateTime () |
Constructs a DateTime. More... | |
constexpr | DateTime (uint64 ticks) |
Constructs a DateTime with the specified number of ticks. More... | |
constexpr uint64 | totalTicks () const |
Gets the number of ticks which represent the value of the current instance. More... | |
int | year () const |
Gets the year component of the date represented by this instance. More... | |
int | month () const |
Gets the month component of the date represented by this instance. More... | |
int | day () const |
Gets the day component of the date represented by this instance. More... | |
int | dayOfYear () const |
Gets the day of the year represented by this instance. More... | |
constexpr DayOfWeek | dayOfWeek () const |
Gets the day of the week represented by this instance. More... | |
constexpr int | hour () const |
Gets the hour component of the date represented by this instance. More... | |
constexpr int | minute () const |
Gets the minute component of the date represented by this instance. More... | |
constexpr int | second () const |
Gets the second component of the date represented by this instance. More... | |
constexpr int | millisecond () const |
Gets the millisecond component of the date represented by this instance. More... | |
constexpr bool | isNull () const |
Returns ture if the date represented by the current DateTime class is null. More... | |
constexpr TimeSpan | timeOfDay () const |
Gets the time of day as TimeSpan for this instance. More... | |
bool | isLeapYear () const |
Returns an indication whether the year of the dae represented by this instance is a leap year. More... | |
constexpr bool | isEternity () const |
Returns whether the instance has the maximal number of ticks. More... | |
constexpr bool | isSameDay (const DateTime &other) const |
Returns and indication whether two DateTime instances represent the same day. More... | |
std::string | toString (DateTimeOutputFormat format=DateTimeOutputFormat::DateAndTime, bool noMilliseconds=false) const |
Returns the string representation of the current instance using the specified format. More... | |
void | toString (std::string &result, DateTimeOutputFormat format=DateTimeOutputFormat::DateAndTime, bool noMilliseconds=false) const |
Returns the string representation of the current instance using the specified format. More... | |
std::string | toIsoString (TimeSpan timeZoneDelta=TimeSpan()) const |
Returns the string representation of the current instance in the ISO format, eg. More... | |
constexpr bool | operator== (const DateTime &other) const |
Indicates whether two DateTime instances are equal. More... | |
constexpr bool | operator!= (const DateTime &other) const |
Indicates whether two DateTime instances are not equal. More... | |
constexpr bool | operator< (const DateTime &other) const |
Indicates whether a specified DateTime is less than another specified DateTime. More... | |
constexpr bool | operator> (const DateTime &other) const |
Indicates whether a specified DateTime is greater than another specified DateTime. More... | |
constexpr bool | operator<= (const DateTime &other) const |
Indicates whether a specified DateTime is less or equal than another specified DateTime. More... | |
constexpr bool | operator>= (const DateTime &other) const |
Indicates whether a specified DateTime is greater or equal than another specified DateTime. More... | |
constexpr DateTime | operator+ (const TimeSpan &timeSpan) const |
Adds another instance. More... | |
constexpr DateTime | operator- (const TimeSpan &timeSpan) const |
Substracts another instance. More... | |
constexpr TimeSpan | operator+ (const DateTime &other) const |
Adds two instances. More... | |
constexpr TimeSpan | operator- (const DateTime &other) const |
Substracts two DateTime instances. More... | |
DateTime & | operator+= (const TimeSpan &timeSpan) |
Adds a TimeSpan to the current instance. More... | |
DateTime & | operator-= (const TimeSpan &timeSpan) |
Substracts a TimeSpan from the current instance. More... | |
Static Public Member Functions | |
static DateTime | fromDate (int year=1, int month=1, int day=1) |
Constructs a DateTime to the specified year, month, and day. More... | |
static DateTime | fromTime (int hour=0, int minute=0, int second=0, double millisecond=0.0) |
Constructs a DateTime to the specified hour, minute, second and millisecond. More... | |
static DateTime | fromDateAndTime (int year=1, int month=1, int day=1, int hour=0, int minute=0, int second=0, double millisecond=0.0) |
Constructs a DateTime to the specified year, month, day, hour, minute, second and millisecond. More... | |
static DateTime | fromString (const std::string &str) |
Parses the given std::string as DateTime. More... | |
static DateTime | fromString (const char *str) |
Parses the given C-style string as DateTime. More... | |
static std::pair< DateTime, TimeSpan > | fromIsoString (const char *str) |
Parses the specified ISO date time denotation provided as C-style string. More... | |
static DateTime | fromIsoStringGmt (const char *str) |
Parses the specified ISO date time denotation provided as C-style string. More... | |
static DateTime | fromIsoStringLocal (const char *str) |
Parses the specified ISO date time denotation provided as C-style string. More... | |
static DateTime | fromTimeStamp (time_t timeStamp) |
Constructs a new DateTime object with the local time from the specified timeStamp. More... | |
static DateTime | fromTimeStampGmt (time_t timeStamp) |
Constructs a new DateTime object with the GMT time from the specified timeStamp. More... | |
static const char * | printDayOfWeek (DayOfWeek dayOfWeek, bool abbreviation=false) |
Returns the string representation as C-style string for the given day of week. More... | |
static constexpr DateTime | eternity () |
Constructs a new instance of the DateTime class with the maximal number of ticks. More... | |
static DateTime | now () |
Returns a DateTime object that is set to the current date and time on this computer, expressed as the local time. More... | |
static DateTime | gmtNow () |
Returns a DateTime object that is set to the current date and time on this computer, expressed as the GMT time. More... | |
static constexpr bool | isLeapYear (int year) |
Returns an indication whether the specified year is a leap year. More... | |
static int | daysInMonth (int year, int month) |
Returns the number of days in the specified month and year. More... | |
Represents an instant in time, typically expressed as a date and time of day.
Definition at line 55 of file datetime.h.
|
inlineexplicit |
Constructs a DateTime.
Definition at line 134 of file datetime.h.
|
inlineexplicit |
Constructs a DateTime with the specified number of ticks.
Definition at line 141 of file datetime.h.
|
inline |
Gets the day component of the date represented by this instance.
Definition at line 228 of file datetime.h.
|
inline |
Gets the day of the week represented by this instance.
Definition at line 245 of file datetime.h.
|
inline |
Gets the day of the year represented by this instance.
Definition at line 236 of file datetime.h.
|
inlinestatic |
Returns the number of days in the specified month and year.
Definition at line 330 of file datetime.h.
|
inlinestatic |
Constructs a new instance of the DateTime class with the maximal number of ticks.
Definition at line 350 of file datetime.h.
|
inlinestatic |
Constructs a DateTime to the specified year, month, and day.
Definition at line 148 of file datetime.h.
|
inlinestatic |
Constructs a DateTime to the specified year, month, day, hour, minute, second and millisecond.
Definition at line 164 of file datetime.h.
Parses the specified ISO date time denotation provided as C-style string.
Definition at line 120 of file datetime.cpp.
|
inlinestatic |
Parses the specified ISO date time denotation provided as C-style string.
Definition at line 185 of file datetime.h.
|
inlinestatic |
Parses the specified ISO date time denotation provided as C-style string.
Definition at line 196 of file datetime.h.
|
inlinestatic |
Parses the given std::string as DateTime.
Definition at line 175 of file datetime.h.
|
static |
Parses the given C-style string as DateTime.
Definition at line 82 of file datetime.cpp.
|
inlinestatic |
Constructs a DateTime to the specified hour, minute, second and millisecond.
Definition at line 156 of file datetime.h.
|
static |
Constructs a new DateTime object with the local time from the specified timeStamp.
Definition at line 54 of file datetime.cpp.
|
static |
Constructs a new DateTime object with the GMT time from the specified timeStamp.
Definition at line 68 of file datetime.cpp.
|
inlinestatic |
Returns a DateTime object that is set to the current date and time on this computer, expressed as the GMT time.
Definition at line 366 of file datetime.h.
|
inline |
Gets the hour component of the date represented by this instance.
Definition at line 253 of file datetime.h.
|
inline |
Returns whether the instance has the maximal number of ticks.
Definition at line 310 of file datetime.h.
|
inline |
Returns an indication whether the year of the dae represented by this instance is a leap year.
Definition at line 302 of file datetime.h.
|
inlinestatic |
Returns an indication whether the specified year is a leap year.
Definition at line 318 of file datetime.h.
|
inline |
Returns ture if the date represented by the current DateTime class is null.
Definition at line 286 of file datetime.h.
|
inline |
Returns and indication whether two DateTime instances represent the same day.
Definition at line 342 of file datetime.h.
|
inline |
Gets the millisecond component of the date represented by this instance.
Definition at line 277 of file datetime.h.
|
inline |
Gets the minute component of the date represented by this instance.
Definition at line 261 of file datetime.h.
|
inline |
Gets the month component of the date represented by this instance.
Definition at line 220 of file datetime.h.
|
inlinestatic |
Returns a DateTime object that is set to the current date and time on this computer, expressed as the local time.
Definition at line 358 of file datetime.h.
|
inline |
Indicates whether two DateTime instances are not equal.
Definition at line 382 of file datetime.h.
Adds another instance.
Definition at line 423 of file datetime.h.
Adds a TimeSpan to the current instance.
Definition at line 458 of file datetime.h.
Substracts another instance.
Definition at line 432 of file datetime.h.
Substracts two DateTime instances.
Definition at line 450 of file datetime.h.
Substracts a TimeSpan from the current instance.
Definition at line 467 of file datetime.h.
|
inline |
Indicates whether a specified DateTime is less than another specified DateTime.
Definition at line 390 of file datetime.h.
|
inline |
Indicates whether a specified DateTime is less or equal than another specified DateTime.
Definition at line 406 of file datetime.h.
|
inline |
Indicates whether two DateTime instances are equal.
Definition at line 374 of file datetime.h.
|
inline |
Indicates whether a specified DateTime is greater than another specified DateTime.
Definition at line 398 of file datetime.h.
|
inline |
Indicates whether a specified DateTime is greater or equal than another specified DateTime.
Definition at line 414 of file datetime.h.
|
static |
Returns the string representation as C-style string for the given day of week.
If abbreviation is true, only the first three letters of the string will be returned.
Definition at line 249 of file datetime.cpp.
|
inline |
Gets the second component of the date represented by this instance.
Definition at line 269 of file datetime.h.
|
inline |
Gets the time of day as TimeSpan for this instance.
Definition at line 294 of file datetime.h.
Returns the string representation of the current instance in the ISO format, eg.
2016-08-29T21:32:31.588539814+02:00.
Definition at line 229 of file datetime.cpp.
string DateTime::toString | ( | DateTimeOutputFormat | format = DateTimeOutputFormat::DateAndTime , |
bool | noMilliseconds = false |
||
) | const |
Returns the string representation of the current instance using the specified format.
Definition at line 184 of file datetime.cpp.
void DateTime::toString | ( | std::string & | result, |
DateTimeOutputFormat | format = DateTimeOutputFormat::DateAndTime , |
||
bool | noMilliseconds = false |
||
) | const |
Returns the string representation of the current instance using the specified format.
Definition at line 196 of file datetime.cpp.
|
inline |
Gets the number of ticks which represent the value of the current instance.
Definition at line 204 of file datetime.h.
|
inline |
Gets the year component of the date represented by this instance.
Definition at line 212 of file datetime.h.