14const int DateTime::m_daysPerYear = 365;
15const int DateTime::m_daysPer4Years = 1461;
16const int DateTime::m_daysPer100Years = 36524;
17const int DateTime::m_daysPer400Years = 146097;
18const int DateTime::m_daysTo1601 = 584388;
19const int DateTime::m_daysTo1899 = 693593;
20const int DateTime::m_daysTo10000 = 3652059;
21const int DateTime::m_daysToMonth365[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
22const int DateTime::m_daysToMonth366[13] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
23const int DateTime::m_daysInMonth365[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
24const int DateTime::m_daysInMonth366[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
108 return std::make_pair(
expr.value,
expr.delta);
123 stringstream
s(stringstream::in | stringstream::out);
190 stringstream
s(stringstream::in | stringstream::out);
274#if defined(PLATFORM_UNIX) && !defined(PLATFORM_MAC)
284 +
static_cast<std::uint64_t
>(
t.tv_nsec) / 100);
294 throw ConversionException(
"year is out of range");
297 throw ConversionException(
"month is out of range");
302 throw ConversionException(
"day is out of range");
314DateTime::TickType DateTime::timeToTicks(
int hour,
int minute,
int second,
double millisecond)
317 throw ConversionException(
"hour is out of range");
320 throw ConversionException(
"minute is out of range");
323 throw ConversionException(
"second is out of range");
326 throw ConversionException(
"millisecond is out of range");
391 int values[9] = { 0 };
406 if (
c <=
'9' &&
c >=
'0') {
421 }
else if (
c ==
'T') {
426 }
else if (
c ==
'-') {
436 }
else if (
c ==
'.') {
442 }
else if (
c ==
':') {
458 }
else if (
c ==
'\0') {
491 int values[7] = { 0 };
500 if (
c <=
'9' &&
c >=
'0') {
512 }
else if (
c ==
'\0') {
535 auto s = std::stringstream(std::stringstream::in | std::stringstream::out);
584 if (
d.isNegative()) {
591 s <<
setw(2) <<
d.hours();
597 s <<
setw(2) <<
d.minutes();
The ConversionException class is thrown by the various conversion functions of this library when a co...
Represents an instant in time, typically expressed as a date and time of day.
std::string toString(DateTimeOutputFormat format=DateTimeOutputFormat::DateAndTime, bool noMilliseconds=false) const
Returns the string representation of the current instance using the specified format.
int day() const
Returns the day component of the date represented by this instance.
constexpr DayOfWeek dayOfWeek() const
Returns the day of the week represented by this instance.
std::string toIsoStringWithCustomDelimiters(TimeSpan timeZoneDelta=TimeSpan(), char dateDelimiter='-', char timeDelimiter=':', char timeZoneDelimiter=':') const
Returns the string representation of the current instance in the ISO format with custom delimiters,...
bool isLeapYear() const
Returns an indication whether the year represented by this instance is a leap year.
int month() const
Returns the month component of the date represented by this instance.
constexpr DateTime()
Constructs a DateTime.
std::string toIsoString(TimeSpan timeZoneDelta=TimeSpan()) const
Returns the string representation of the current instance in the ISO format, eg.
static constexpr DateTime unixEpochStart()
Returns the DateTime object for the "1970-01-01T00:00:00Z".
constexpr int microsecond() const
Returns the microsecond component of the date represented by this instance.
static std::pair< DateTime, TimeSpan > fromIsoString(const char *str)
Parses the specified ISO date time denotation provided as C-style string.
constexpr int hour() const
Returns the hour component of the date represented by this instance.
static DateTime fromString(const std::string &str)
Parses the given std::string as DateTime.
constexpr int second() const
Returns the second component of the date represented by this instance.
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.
constexpr TickType totalTicks() const
Returns the number of ticks which represent the value of the current instance.
static DateTime fromTimeStamp(std::time_t timeStamp)
Constructs a new DateTime object with the local time from the specified UNIX timeStamp.
constexpr int millisecond() const
Returns the millisecond component of the date represented by this instance.
static const char * printDayOfWeek(DayOfWeek dayOfWeek, bool abbreviation=false)
Returns the string representation as C-style string for the given day of week.
constexpr int nanosecond() const
Returns the nanosecond component of the date represented by this instance.
constexpr int minute() const
Returns the minute component of the date represented by this instance.
int year() const
Returns the year component of the date represented by this instance.
Represents a time interval.
static constexpr TickType nanosecondsPerTick
static constexpr TickType ticksPerMillisecond
static constexpr TickType ticksPerMinute
static constexpr TimeSpan fromMinutes(double minutes)
Constructs a new instance of the TimeSpan class with the specified number of minutes.
static constexpr TickType ticksPerSecond
static constexpr TickType ticksPerDay
static constexpr TickType ticksPerHour
Contains all utilities provides by the c++utilities library.
DatePart
Specifies the date part.
constexpr bool inRangeExclMax(num1 val, num2 min, num3 max)
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.
constexpr bool inRangeInclMax(num1 val, num2 min, num3 max)
StringType argsToString(Args &&...args)
constexpr T max(T first, T second)
Returns the greatest of the given items.
DateTimeParts
The DateTimeParts enum specifies which parts of a timestamp are present.
DateTimeOutputFormat
Specifies the output format.
@ DateTimeAndShortWeekday
@ IsoOmittingDefaultComponents
constexpr T min(T first, T second)
Returns the smallest of the given items.
DayOfWeek
Specifies the day of the week.
The DateTimeExpression struct holds information about a time expression (e.g.
static DateTimeExpression fromString(const char *str)
Parses the given C-style string.
std::string toIsoString(char dateDelimiter='-', char timeDelimiter=':', char timeZoneDelimiter=':') const
Returns the string representation of the current instance in the ISO format.
static DateTimeExpression fromIsoString(const char *str)
Parses the specified ISO date time denotation provided as C-style string.