C++ Utilities: chrono/datetime.h Source File

C++ Utilities 5.34.1 Useful C++ classes and routines such as argument parser, IO and conversion utilities

Loading...
Searching...
No Matches
datetime.h
Go to the documentation of this file.
1#ifndef CHRONO_UTILITIES_DATETIME_H
2#define CHRONO_UTILITIES_DATETIME_H
3
4#include "./timespan.h"
5
6#include "../misc/flagenumclass.h"
7
8#include <cstdint>
9#include <ctime>
10#include <limits>
11#include <string>
12
13namespace CppUtilities {
14
19 enum class DateTimeOutputFormat {
20 DateAndTime,
21 DateOnly,
22 TimeOnly,
23 DateTimeAndWeekday,
24 DateTimeAndShortWeekday,
25 Iso,
26 IsoOmittingDefaultComponents,
27};
28
33 enum class DayOfWeek {
34 Monday,
35 Tuesday,
36 Wednesday,
37 Thursday,
38 Friday,
39 Saturday,
40 Sunday
41};
42
48 enum class DatePart {
49 Year,
50 Month,
51 DayOfYear,
52 Day
53};
54
55 class CPP_UTILITIES_EXPORT DateTime {
56public:
57 using TickType = std::uint64_t;
58
59 explicit constexpr DateTime();
60 explicit constexpr DateTime(TickType ticks);
61 static DateTime fromDate(int year = 1, int month = 1, int day = 1);
62 static DateTime fromTime(int hour = 0, int minute = 0, int second = 0, double millisecond = 0.0);
63 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);
64 static DateTime fromString(const std::string &str);
65 static DateTime fromString(const char *str);
66 static std::pair<DateTime, TimeSpan> fromIsoString(const char *str);
67 static DateTime fromIsoStringGmt(const char *str);
68 static DateTime fromIsoStringLocal(const char *str);
69 static DateTime fromTimeStamp(std::time_t timeStamp);
70 constexpr static DateTime fromTimeStampGmt(std::time_t timeStamp);
71 template <typename TimePoint> static DateTime fromChronoTimePoint(TimePoint timePoint);
72 template <typename TimePoint> constexpr static DateTime fromChronoTimePointGmt(TimePoint timePoint);
73
74 constexpr TickType &ticks();
75 constexpr TickType totalTicks() const;
76 int year() const;
77 int month() const;
78 int day() const;
79 int dayOfYear() const;
80 constexpr DayOfWeek dayOfWeek() const;
81 constexpr int hour() const;
82 constexpr int minute() const;
83 constexpr int second() const;
84 constexpr int millisecond() const;
85 constexpr int microsecond() const;
86 constexpr int nanosecond() const;
87 constexpr bool isNull() const;
88 constexpr TimeSpan timeOfDay() const;
89 bool isLeapYear() const;
90 constexpr bool isEternity() const;
91 constexpr bool isSameDay(const DateTime &other) const;
92 std::string toString(DateTimeOutputFormat format = DateTimeOutputFormat::DateAndTime, bool noMilliseconds = false) const;
93 void toString(std::string &result, DateTimeOutputFormat format = DateTimeOutputFormat::DateAndTime, bool noMilliseconds = false) const;
94 std::string toIsoStringWithCustomDelimiters(
95 TimeSpan timeZoneDelta = TimeSpan(), char dateDelimiter = '-', char timeDelimiter = ':', char timeZoneDelimiter = ':') const;
96 std::string toIsoString(TimeSpan timeZoneDelta = TimeSpan()) const;
97 constexpr std::time_t toTimeStamp() const;
98 static const char *printDayOfWeek(DayOfWeek dayOfWeek, bool abbreviation = false);
99
100 static constexpr DateTime eternity();
101 static constexpr DateTime unixEpochStart();
102 static DateTime now();
103 static DateTime gmtNow();
104 static DateTime exactGmtNow();
105 constexpr static bool isLeapYear(int year);
106 static int daysInMonth(int year, int month);
107
108 constexpr bool operator==(const DateTime &other) const;
109 constexpr bool operator!=(const DateTime &other) const;
110 constexpr bool operator<(const DateTime &other) const;
111 constexpr bool operator>(const DateTime &other) const;
112 constexpr bool operator<=(const DateTime &other) const;
113 constexpr bool operator>=(const DateTime &other) const;
114 constexpr DateTime operator+(const TimeSpan &timeSpan) const;
115 constexpr DateTime operator-(const TimeSpan &timeSpan) const;
116 constexpr TimeSpan operator+(const DateTime &other) const;
117 constexpr TimeSpan operator-(const DateTime &other) const;
118 DateTime &operator+=(const TimeSpan &timeSpan);
119 DateTime &operator-=(const TimeSpan &timeSpan);
120
121private:
122 static TickType dateToTicks(int year, int month, int day);
123 static TickType timeToTicks(int hour, int minute, int second, double millisecond);
124 int getDatePart(DatePart part) const;
125
126 TickType m_ticks;
127 static const int m_daysPerYear;
128 static const int m_daysPer4Years;
129 static const int m_daysPer100Years;
130 static const int m_daysPer400Years;
131 static const int m_daysTo1601;
132 static const int m_daysTo1899;
133 static const int m_daysTo10000;
134 static const int m_daysToMonth365[13];
135 static const int m_daysToMonth366[13];
136 static const int m_daysInMonth365[12];
137 static const int m_daysInMonth366[12];
138};
139
143 enum class DateTimeParts : std::uint64_t {
144 None = 0,
145 Year = (1 << 0),
146 Month = (1 << 1),
147 Day = (1 << 2),
148 Hour = (1 << 3),
149 Minute = (1 << 4),
150 Second = (1 << 5),
151 SubSecond = (1 << 6),
152 DeltaHour = (1 << 7),
153 DeltaMinute = (1 << 8),
154 Date = Year | Month | Day,
155 Time = Hour | Minute | Second | SubSecond,
156 DateTime = Date | Time,
157 TimeZoneDelta = DeltaHour | DeltaMinute,
158 All = DateTime | TimeZoneDelta,
159};
160
161 struct CPP_UTILITIES_EXPORT DateTimeExpression {
162 DateTime value;
163 TimeSpan delta;
164 DateTimeParts parts = DateTimeParts::None;
165
166 constexpr DateTime gmt() const;
167 constexpr bool operator==(const DateTimeExpression &other) const;
168 std::string toIsoString(char dateDelimiter = '-', char timeDelimiter = ':', char timeZoneDelimiter = ':') const;
169 static DateTimeExpression fromIsoString(const char *str);
170 static DateTimeExpression fromString(const char *str);
171};
172
176 constexpr DateTime DateTimeExpression::gmt() const
177{
178 return value - delta;
179}
180
184 constexpr bool DateTimeExpression::operator==(const DateTimeExpression &other) const
185{
186 return value == other.value && delta == other.delta && parts == other.parts;
187}
188
192 constexpr inline DateTime::DateTime()
193 : m_ticks(0)
194{
195}
196
200 constexpr inline DateTime::DateTime(TickType ticks)
201 : m_ticks(ticks)
202{
203}
204
209 inline DateTime DateTime::fromDate(int year, int month, int day)
210{
211 return DateTime(dateToTicks(year, month, day));
212}
213
218 inline DateTime DateTime::fromTime(int hour, int minute, int second, double millisecond)
219{
220 return DateTime(timeToTicks(hour, minute, second, millisecond));
221}
222
228 inline DateTime DateTime::fromDateAndTime(int year, int month, int day, int hour, int minute, int second, double millisecond)
229{
230 return DateTime(dateToTicks(year, month, day) + timeToTicks(hour, minute, second, millisecond));
231}
232
242 inline DateTime DateTime::fromString(const std::string &str)
243{
244 return fromString(str.data());
245}
246
253 inline DateTime DateTime::fromIsoStringGmt(const char *str)
254{
255 return DateTimeExpression::fromIsoString(str).gmt();
256}
257
264 inline DateTime DateTime::fromIsoStringLocal(const char *str)
265{
266 return DateTimeExpression::fromIsoString(str).value;
267}
268
272 constexpr inline DateTime DateTime::fromTimeStampGmt(std::time_t timeStamp)
273{
274 return DateTime(DateTime::unixEpochStart().totalTicks() + static_cast<std::uint64_t>(timeStamp) * TimeSpan::ticksPerSecond);
275}
276
282 template <typename TimePoint> inline DateTime DateTime::fromChronoTimePoint(TimePoint timePoint)
283{
284 return DateTime::fromTimeStamp(decltype(timePoint)::clock::to_time_t(timePoint));
285}
286
292 template <typename TimePoint> constexpr DateTime DateTime::fromChronoTimePointGmt(TimePoint timePoint)
293{
294 return DateTime::fromTimeStampGmt(decltype(timePoint)::clock::to_time_t(timePoint));
295}
296
300 constexpr inline DateTime::TickType &DateTime::ticks()
301{
302 return m_ticks;
303}
304
308 constexpr inline DateTime::TickType DateTime::totalTicks() const
309{
310 return m_ticks;
311}
312
316 inline int DateTime::year() const
317{
318 return getDatePart(DatePart::Year);
319}
320
324 inline int DateTime::month() const
325{
326 return getDatePart(DatePart::Month);
327}
328
332 inline int DateTime::day() const
333{
334 return getDatePart(DatePart::Day);
335}
336
340 inline int DateTime::dayOfYear() const
341{
342 return getDatePart(DatePart::DayOfYear);
343}
344
349 constexpr inline DayOfWeek DateTime::dayOfWeek() const
350{
351 return static_cast<DayOfWeek>((m_ticks / TimeSpan::ticksPerDay) % 7l);
352}
353
357 constexpr inline int DateTime::hour() const
358{
359 return static_cast<int>(m_ticks / TimeSpan::ticksPerHour % 24ul);
360}
361
365 constexpr inline int DateTime::minute() const
366{
367 return static_cast<int>(m_ticks / TimeSpan::ticksPerMinute % 60ul);
368}
369
373 constexpr inline int DateTime::second() const
374{
375 return static_cast<int>(m_ticks / TimeSpan::ticksPerSecond % 60ul);
376}
377
381 constexpr inline int DateTime::millisecond() const
382{
383 return static_cast<int>(m_ticks / TimeSpan::ticksPerMillisecond % 1000ul);
384}
385
389 constexpr inline int DateTime::microsecond() const
390{
391 return static_cast<int>(m_ticks / TimeSpan::ticksPerMicrosecond % 1000ul);
392}
393
399 constexpr inline int DateTime::nanosecond() const
400{
401 return static_cast<int>(m_ticks % 10ul * TimeSpan::nanosecondsPerTick);
402}
403
408 constexpr inline bool DateTime::isNull() const
409{
410 return m_ticks == 0;
411}
412
416 constexpr inline TimeSpan DateTime::timeOfDay() const
417{
418 return TimeSpan(static_cast<TimeSpan::TickType>(m_ticks % TimeSpan::ticksPerDay));
419}
420
424 inline bool DateTime::isLeapYear() const
425{
426 return isLeapYear(year());
427}
428
432 constexpr inline bool DateTime::isEternity() const
433{
434 return m_ticks == std::numeric_limits<TickType>::max();
435}
436
440 constexpr inline bool DateTime::isLeapYear(int year)
441{
442 return (year % 4 != 0) ? false : ((year % 100 == 0) ? (year % 400 == 0) : true);
443}
444
448 inline int DateTime::daysInMonth(int year, int month)
449{
450 return (month >= 1 && month <= 12) ? (isLeapYear(year) ? m_daysInMonth366[month - 1] : m_daysInMonth365[month - 1]) : (0);
451}
452
456 constexpr inline bool DateTime::isSameDay(const DateTime &other) const
457{
458 return (m_ticks / TimeSpan::ticksPerDay) == (other.m_ticks / TimeSpan::ticksPerDay);
459}
460
466 inline std::string DateTime::toString(DateTimeOutputFormat format, bool noMilliseconds) const
467{
468 std::string result;
469 toString(result, format, noMilliseconds);
470 return result;
471}
472
476 constexpr std::time_t DateTime::toTimeStamp() const
477{
478 return static_cast<std::time_t>((totalTicks() - DateTime::unixEpochStart().totalTicks()) / TimeSpan::ticksPerSecond);
479}
480
484 constexpr inline DateTime DateTime::eternity()
485{
486 return DateTime(std::numeric_limits<TickType>::max());
487}
488
492 constexpr inline DateTime DateTime::unixEpochStart()
493{
494 return DateTime(621355968000000000);
495}
496
501 inline DateTime DateTime::now()
502{
503 return DateTime::fromTimeStamp(std::time(nullptr));
504}
505
510 inline DateTime DateTime::gmtNow()
511{
512 return DateTime::fromTimeStampGmt(std::time(nullptr));
513}
514
518 constexpr inline bool DateTime::operator==(const DateTime &other) const
519{
520 return m_ticks == other.m_ticks;
521}
522
526 constexpr inline bool DateTime::operator!=(const DateTime &other) const
527{
528 return m_ticks != other.m_ticks;
529}
530
534 constexpr inline bool DateTime::operator<(const DateTime &other) const
535{
536 return m_ticks < other.m_ticks;
537}
538
542 constexpr inline bool DateTime::operator>(const DateTime &other) const
543{
544 return m_ticks > other.m_ticks;
545}
546
550 constexpr inline bool DateTime::operator<=(const DateTime &other) const
551{
552 return m_ticks <= other.m_ticks;
553}
554
558 constexpr inline bool DateTime::operator>=(const DateTime &other) const
559{
560 return m_ticks >= other.m_ticks;
561}
562
567 constexpr inline DateTime DateTime::operator+(const TimeSpan &timeSpan) const
568{
569 return DateTime(m_ticks + static_cast<TickType>(timeSpan.m_ticks));
570}
571
576 constexpr inline DateTime DateTime::operator-(const TimeSpan &timeSpan) const
577{
578 return DateTime(m_ticks - static_cast<TickType>(timeSpan.m_ticks));
579}
580
585 constexpr inline TimeSpan DateTime::operator+(const DateTime &other) const
586{
587 return TimeSpan(static_cast<TimeSpan::TickType>(m_ticks + other.m_ticks));
588}
589
596 constexpr inline TimeSpan DateTime::operator-(const DateTime &other) const
597{
598 return TimeSpan(static_cast<TimeSpan::TickType>(m_ticks - other.m_ticks));
599}
600
604 inline DateTime &DateTime::operator+=(const TimeSpan &timeSpan)
605{
606 m_ticks += static_cast<TickType>(timeSpan.m_ticks);
607 return *this;
608}
609
613 inline DateTime &DateTime::operator-=(const TimeSpan &timeSpan)
614{
615 m_ticks += static_cast<TickType>(timeSpan.m_ticks);
616 return *this;
617}
618} // namespace CppUtilities
619
620namespace std {
622 template <> struct hash<CppUtilities::DateTime> {
623 inline size_t operator()(const CppUtilities::DateTime &dateTime) const
624 {
625 return hash<CppUtilities::DateTime::TickType>()(dateTime.totalTicks());
626 }
627};
628} // namespace std
629
630 CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(CppUtilities, CppUtilities::DateTimeParts);
631
632#endif // CHRONO_UTILITIES_DATETIME_H
CppUtilities::DateTime
Represents an instant in time, typically expressed as a date and time of day.
Definition datetime.h:55
CppUtilities::DateTime::toString
std::string toString(DateTimeOutputFormat format=DateTimeOutputFormat::DateAndTime, bool noMilliseconds=false) const
Returns the string representation of the current instance using the specified format.
Definition datetime.h:466
CppUtilities::DateTime::day
int day() const
Returns the day component of the date represented by this instance.
Definition datetime.h:332
CppUtilities::DateTime::dayOfWeek
constexpr DayOfWeek dayOfWeek() const
Returns the day of the week represented by this instance.
Definition datetime.h:349
CppUtilities::DateTime::toIsoStringWithCustomDelimiters
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,...
Definition datetime.cpp:195
CppUtilities::DateTime::isLeapYear
bool isLeapYear() const
Returns an indication whether the year represented by this instance is a leap year.
Definition datetime.h:424
CppUtilities::DateTime::fromTimeStampGmt
static constexpr DateTime fromTimeStampGmt(std::time_t timeStamp)
Constructs a new DateTime object with the GMT time from the specified UNIX timeStamp.
Definition datetime.h:272
CppUtilities::DateTime::now
static DateTime now()
Returns a DateTime object that is set to the current date and time on this computer,...
Definition datetime.h:501
CppUtilities::DateTime::operator>
constexpr bool operator>(const DateTime &other) const
Indicates whether a specified DateTime is greater than another specified DateTime.
Definition datetime.h:542
CppUtilities::DateTime::fromIsoStringLocal
static DateTime fromIsoStringLocal(const char *str)
Parses the specified ISO date time denotation provided as C-style string.
Definition datetime.h:264
CppUtilities::DateTime::isNull
constexpr bool isNull() const
Returns true if the date represented by the current DateTime class is null.
Definition datetime.h:408
CppUtilities::DateTime::month
int month() const
Returns the month component of the date represented by this instance.
Definition datetime.h:324
CppUtilities::DateTime::DateTime
constexpr DateTime()
Constructs a DateTime.
Definition datetime.h:192
CppUtilities::DateTime::operator-=
DateTime & operator-=(const TimeSpan &timeSpan)
Subtracts a TimeSpan from the current instance.
Definition datetime.h:613
CppUtilities::DateTime::operator+=
DateTime & operator+=(const TimeSpan &timeSpan)
Adds a TimeSpan to the current instance.
Definition datetime.h:604
CppUtilities::DateTime::toIsoString
std::string toIsoString(TimeSpan timeZoneDelta=TimeSpan()) const
Returns the string representation of the current instance in the ISO format, eg.
Definition datetime.cpp:229
CppUtilities::DateTime::unixEpochStart
static constexpr DateTime unixEpochStart()
Returns the DateTime object for the "1970-01-01T00:00:00Z".
Definition datetime.h:492
CppUtilities::DateTime::fromChronoTimePointGmt
static constexpr DateTime fromChronoTimePointGmt(TimePoint timePoint)
Constructs a new DateTime object with the GMT time from the specified std::chrono::time_point.
Definition datetime.h:292
CppUtilities::DateTime::TickType
std::uint64_t TickType
Definition datetime.h:57
CppUtilities::DateTime::microsecond
constexpr int microsecond() const
Returns the microsecond component of the date represented by this instance.
Definition datetime.h:389
CppUtilities::DateTime::operator>=
constexpr bool operator>=(const DateTime &other) const
Indicates whether a specified DateTime is greater or equal than another specified DateTime.
Definition datetime.h:558
CppUtilities::DateTime::operator!=
constexpr bool operator!=(const DateTime &other) const
Indicates whether two DateTime instances are not equal.
Definition datetime.h:526
CppUtilities::DateTime::operator==
constexpr bool operator==(const DateTime &other) const
Indicates whether two DateTime instances are equal.
Definition datetime.h:518
CppUtilities::DateTime::fromIsoString
static std::pair< DateTime, TimeSpan > fromIsoString(const char *str)
Parses the specified ISO date time denotation provided as C-style string.
Definition datetime.cpp:112
CppUtilities::DateTime::operator+
constexpr DateTime operator+(const TimeSpan &timeSpan) const
Adds another instance.
Definition datetime.h:567
CppUtilities::DateTime::dayOfYear
int dayOfYear() const
Returns the day of the year represented by this instance.
Definition datetime.h:340
CppUtilities::DateTime::exactGmtNow
static DateTime exactGmtNow()
Returns a DateTime object that is set to the current date and time on this computer,...
Definition datetime.cpp:284
CppUtilities::DateTime::operator<=
constexpr bool operator<=(const DateTime &other) const
Indicates whether a specified DateTime is less or equal than another specified DateTime.
Definition datetime.h:550
CppUtilities::DateTime::isSameDay
constexpr bool isSameDay(const DateTime &other) const
Returns and indication whether two DateTime instances represent the same day.
Definition datetime.h:456
CppUtilities::DateTime::hour
constexpr int hour() const
Returns the hour component of the date represented by this instance.
Definition datetime.h:357
CppUtilities::DateTime::fromString
static DateTime fromString(const std::string &str)
Parses the given std::string as DateTime.
Definition datetime.h:242
CppUtilities::DateTime::second
constexpr int second() const
Returns the second component of the date represented by this instance.
Definition datetime.h:373
CppUtilities::DateTime::fromDateAndTime
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.
Definition datetime.h:228
CppUtilities::DateTime::fromDate
static DateTime fromDate(int year=1, int month=1, int day=1)
Constructs a DateTime to the specified year, month, and day.
Definition datetime.h:209
CppUtilities::DateTime::timeOfDay
constexpr TimeSpan timeOfDay() const
Returns the time of day as TimeSpan for this instance.
Definition datetime.h:416
CppUtilities::DateTime::fromChronoTimePoint
static DateTime fromChronoTimePoint(TimePoint timePoint)
Constructs a new DateTime object with the local time from the specified std::chrono::time_point.
Definition datetime.h:282
CppUtilities::DateTime::ticks
constexpr TickType & ticks()
Returns a mutable reference to the total ticks.
Definition datetime.h:300
CppUtilities::DateTime::totalTicks
constexpr TickType totalTicks() const
Returns the number of ticks which represent the value of the current instance.
Definition datetime.h:308
CppUtilities::DateTime::gmtNow
static DateTime gmtNow()
Returns a DateTime object that is set to the current date and time on this computer,...
Definition datetime.h:510
CppUtilities::DateTime::fromTimeStamp
static DateTime fromTimeStamp(std::time_t timeStamp)
Constructs a new DateTime object with the local time from the specified UNIX timeStamp.
Definition datetime.cpp:76
CppUtilities::DateTime::operator-
constexpr DateTime operator-(const TimeSpan &timeSpan) const
Subtracts another instance.
Definition datetime.h:576
CppUtilities::DateTime::isEternity
constexpr bool isEternity() const
Returns whether the instance has the maximal number of ticks.
Definition datetime.h:432
CppUtilities::DateTime::millisecond
constexpr int millisecond() const
Returns the millisecond component of the date represented by this instance.
Definition datetime.h:381
CppUtilities::DateTime::fromTime
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.
Definition datetime.h:218
CppUtilities::DateTime::printDayOfWeek
static const char * printDayOfWeek(DayOfWeek dayOfWeek, bool abbreviation=false)
Returns the string representation as C-style string for the given day of week.
Definition datetime.cpp:241
CppUtilities::DateTime::nanosecond
constexpr int nanosecond() const
Returns the nanosecond component of the date represented by this instance.
Definition datetime.h:399
CppUtilities::DateTime::fromIsoStringGmt
static DateTime fromIsoStringGmt(const char *str)
Parses the specified ISO date time denotation provided as C-style string.
Definition datetime.h:253
CppUtilities::DateTime::operator<
constexpr bool operator<(const DateTime &other) const
Indicates whether a specified DateTime is less than another specified DateTime.
Definition datetime.h:534
CppUtilities::DateTime::daysInMonth
static int daysInMonth(int year, int month)
Returns the number of days in the specified month and year.
Definition datetime.h:448
CppUtilities::DateTime::toTimeStamp
constexpr std::time_t toTimeStamp() const
Returns the UNIX timestamp for the current instance.
Definition datetime.h:476
CppUtilities::DateTime::eternity
static constexpr DateTime eternity()
Constructs a new instance of the DateTime class with the maximal number of ticks.
Definition datetime.h:484
CppUtilities::DateTime::minute
constexpr int minute() const
Returns the minute component of the date represented by this instance.
Definition datetime.h:365
CppUtilities::DateTime::year
int year() const
Returns the year component of the date represented by this instance.
Definition datetime.h:316
CppUtilities::TimeSpan
Represents a time interval.
Definition timespan.h:25
CppUtilities::TimeSpan::nanosecondsPerTick
static constexpr TickType nanosecondsPerTick
Definition timespan.h:99
CppUtilities::TimeSpan::ticksPerMillisecond
static constexpr TickType ticksPerMillisecond
Definition timespan.h:101
CppUtilities::TimeSpan::ticksPerMinute
static constexpr TickType ticksPerMinute
Definition timespan.h:103
CppUtilities::TimeSpan::ticksPerMicrosecond
static constexpr TickType ticksPerMicrosecond
Definition timespan.h:100
CppUtilities::TimeSpan::TickType
std::int64_t TickType
Definition timespan.h:29
CppUtilities::TimeSpan::ticksPerSecond
static constexpr TickType ticksPerSecond
Definition timespan.h:102
CppUtilities::TimeSpan::ticksPerDay
static constexpr TickType ticksPerDay
Definition timespan.h:105
CppUtilities::TimeSpan::ticksPerHour
static constexpr TickType ticksPerHour
Definition timespan.h:104
flagenumclass.h
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS
#define CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(Namespace, EnumClassType)
Definition flagenumclass.h:18
CPP_UTILITIES_EXPORT
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Definition global.h:14
CppUtilities
Contains all utilities provided by the c++utilities library.
Definition argumentparser.h:18
CppUtilities::DatePart
DatePart
Specifies the date part.
Definition datetime.h:48
CppUtilities::DatePart::Day
@ Day
Definition datetime.h:52
CppUtilities::DatePart::DayOfYear
@ DayOfYear
Definition datetime.h:51
CppUtilities::DatePart::Year
@ Year
Definition datetime.h:49
CppUtilities::DatePart::Month
@ Month
Definition datetime.h:50
CppUtilities::ValueCompletionBehavior::None
@ None
Definition argumentparser.h:118
CppUtilities::DateTimeParts
DateTimeParts
The DateTimeParts enum specifies which parts of a timestamp are present.
Definition datetime.h:143
CppUtilities::DateTimeParts::SubSecond
@ SubSecond
Definition datetime.h:151
CppUtilities::DateTimeParts::TimeZoneDelta
@ TimeZoneDelta
Definition datetime.h:157
CppUtilities::DateTimeParts::Date
@ Date
Definition datetime.h:154
CppUtilities::DateTimeParts::Minute
@ Minute
Definition datetime.h:149
CppUtilities::DateTimeParts::None
@ None
Definition datetime.h:144
CppUtilities::DateTimeParts::DeltaMinute
@ DeltaMinute
Definition datetime.h:153
CppUtilities::DateTimeParts::Time
@ Time
Definition datetime.h:155
CppUtilities::DateTimeParts::All
@ All
Definition datetime.h:158
CppUtilities::DateTimeParts::Hour
@ Hour
Definition datetime.h:148
CppUtilities::DateTimeParts::Second
@ Second
Definition datetime.h:150
CppUtilities::DateTimeParts::DeltaHour
@ DeltaHour
Definition datetime.h:152
CppUtilities::DateTimeOutputFormat
DateTimeOutputFormat
Specifies the output format.
Definition datetime.h:19
CppUtilities::DateTimeOutputFormat::DateTimeAndShortWeekday
@ DateTimeAndShortWeekday
Definition datetime.h:24
CppUtilities::DateTimeOutputFormat::TimeOnly
@ TimeOnly
Definition datetime.h:22
CppUtilities::DateTimeOutputFormat::Iso
@ Iso
Definition datetime.h:25
CppUtilities::DateTimeOutputFormat::DateAndTime
@ DateAndTime
Definition datetime.h:20
CppUtilities::DateTimeOutputFormat::IsoOmittingDefaultComponents
@ IsoOmittingDefaultComponents
Definition datetime.h:26
CppUtilities::DateTimeOutputFormat::DateTimeAndWeekday
@ DateTimeAndWeekday
Definition datetime.h:23
CppUtilities::DateTimeOutputFormat::DateOnly
@ DateOnly
Definition datetime.h:21
CppUtilities::DayOfWeek
DayOfWeek
Specifies the day of the week.
Definition datetime.h:33
CppUtilities::DayOfWeek::Tuesday
@ Tuesday
Definition datetime.h:35
CppUtilities::DayOfWeek::Monday
@ Monday
Definition datetime.h:34
CppUtilities::DayOfWeek::Thursday
@ Thursday
Definition datetime.h:37
CppUtilities::DayOfWeek::Wednesday
@ Wednesday
Definition datetime.h:36
CppUtilities::DayOfWeek::Saturday
@ Saturday
Definition datetime.h:39
CppUtilities::DayOfWeek::Sunday
@ Sunday
Definition datetime.h:40
CppUtilities::DayOfWeek::Friday
@ Friday
Definition datetime.h:38
std
STL namespace.
CppUtilities::DateTimeExpression
The DateTimeExpression struct holds information about a time expression (e.g.
Definition datetime.h:161
CppUtilities::DateTimeExpression::delta
TimeSpan delta
Definition datetime.h:163
CppUtilities::DateTimeExpression::gmt
constexpr DateTime gmt() const
Returns the value in UTC time.
Definition datetime.h:176
CppUtilities::DateTimeExpression::value
DateTime value
Definition datetime.h:162
CppUtilities::DateTimeExpression::operator==
constexpr bool operator==(const DateTimeExpression &other) const
Returns whether the expressions are equivalent.
Definition datetime.h:184
CppUtilities::DateTimeExpression::fromString
static DateTimeExpression fromString(const char *str)
Parses the given C-style string.
Definition datetime.cpp:499
CppUtilities::DateTimeExpression::parts
DateTimeParts parts
Definition datetime.h:164
CppUtilities::DateTimeExpression::toIsoString
std::string toIsoString(char dateDelimiter='-', char timeDelimiter=':', char timeZoneDelimiter=':') const
Returns the string representation of the current instance in the ISO format.
Definition datetime.cpp:544
CppUtilities::DateTimeExpression::fromIsoString
static DateTimeExpression fromIsoString(const char *str)
Parses the specified ISO date time denotation provided as C-style string.
Definition datetime.cpp:399
std::hash< CppUtilities::DateTime >::operator()
size_t operator()(const CppUtilities::DateTime &dateTime) const
Definition datetime.h:623
timespan.h