| 1 | #cxx . . $ `<file>/chrono/datetime.cpp`/include "./datetime.h"cxx . . $ `<file>/chrono/datetime.h`/ |
| 2 | |
| 3 | #include "../conversion/stringbuilder.h"cxx . . $ `<file>/conversion/stringbuilder.h`/ |
| 4 | #include "../conversion/stringconversion.h"cxx . . $ `<file>/conversion/stringconversion.h`/ |
| 5 | |
| 6 | #include <iomanip> |
| 7 | #include <sstream> |
| 8 | |
| 9 | #if !defined(CPP_UTILITIES_CHRONO_BASED_EXACT_TIME) && (defined(PLATFORM_MAC) || !defined(PLATFORM_UNIXcxx . . $ `application/global.h:56:9`!)) |
| 10 | #define CPP_UTILITIES_CHRONO_BASED_EXACT_TIME |
| 11 | #endif |
| 12 | #ifdef CPP_UTILITIES_CHRONO_BASED_EXACT_TIME |
| 13 | #include <chrono> |
| 14 | #endif |
| 15 | |
| 16 | using namespace std; |
| 17 | |
| 18 | namespace CppUtilitiescxx . . $ CppUtilities/ { |
| 19 | |
| 20 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysPerYearcxx . . $ CppUtilities/DateTime#m_daysPerYear. = 365; |
| 21 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysPer4Yearscxx . . $ CppUtilities/DateTime#m_daysPer4Years. = 1461; |
| 22 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysPer100Yearscxx . . $ CppUtilities/DateTime#m_daysPer100Years. = 36524; |
| 23 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysPer400Yearscxx . . $ CppUtilities/DateTime#m_daysPer400Years. = 146097; |
| 24 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysTo1601cxx . . $ CppUtilities/DateTime#m_daysTo1601. = 584388; |
| 25 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysTo1899cxx . . $ CppUtilities/DateTime#m_daysTo1899. = 693593; |
| 26 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysTo10000cxx . . $ CppUtilities/DateTime#m_daysTo10000. = 3652059; |
| 27 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysToMonth365cxx . . $ CppUtilities/DateTime#m_daysToMonth365.[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; |
| 28 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysToMonth366cxx . . $ CppUtilities/DateTime#m_daysToMonth366.[13] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }; |
| 29 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysInMonth365cxx . . $ CppUtilities/DateTime#m_daysInMonth365.[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
| 30 | const int DateTimecxx . . $ CppUtilities/DateTime#::m_daysInMonth366cxx . . $ CppUtilities/DateTime#m_daysInMonth366.[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
| 31 | |
| 32 | template <typename num1, typename num2, typename num3> constexpr bool inRangeInclMaxcxx . . $ CppUtilities/inRangeInclMax(e174ffa2ff62cfae).(num1 val, num2 min, num3 max) |
| 33 | { |
| 34 | return (val) >=cxx . . $ std/`operator>=`(39b98f4fe21ae589). (min) &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). (val) <=cxx . . $ std/`operator<=`(39b98f4fe21ae589). (max); |
| 35 | } |
| 36 | |
| 37 | template <typename num1, typename num2, typename num3> constexpr bool inRangeExclMaxcxx . . $ CppUtilities/inRangeExclMax(e174ffa2ff62cfae).(num1 val, num2 min, num3 max) |
| 38 | { |
| 39 | return (val) >=cxx . . $ std/`operator>=`(39b98f4fe21ae589). (min) &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). (val) <cxx . . $ std/`operator<`(39b98f4fe21ae589). (max); |
| 40 | } |
| 41 | |
| 42 | /*! |
| 43 | * \class DateTime |
| 44 | * \brief Represents an instant in time, typically expressed as a date and time of day. |
| 45 | * \remarks |
| 46 | * - Time values are measured in 100-nanosecond units called ticks, |
| 47 | * and a particular date is the number of ticks since 12:00 midnight, January 1, |
| 48 | * 0001 A.D. (C.E.) in the Gregorian Calendar (excluding ticks that would be added by leap seconds). |
| 49 | * - There is no time zone information associated. You need to keep track of the used time zone separately. That can be done by |
| 50 | * keeping an additional TimeSpan around which represents the delta to UTC. For this one can also use DateTimeExpression. |
| 51 | * Alternatively, one can simply use UTC everywhere in the program. |
| 52 | * - Many functions/descriptions refer to GMT instead of UTC. Both terms are used interchangeably here as the difference is not |
| 53 | * relevant here. Note that GMT does *not* mean "time in Greenwich". |
| 54 | * - When constructing an instance via DateTime::fromTimeStamp(), DateTime::fromChronoTimePoint() or DateTime::fromIsoStringLocal() |
| 55 | * the time zone deltas are "baked into" the DateTime instance. For instance, the expression (DateTime::now() - DateTime::gmtNow()) |
| 56 | * returns one hour in Germany during winter time (and *not* zero although both instances represent the current time). |
| 57 | * \todo |
| 58 | * - Allow to determine the date part for each component at once to prevent multiple invocations of getDatePart(). |
| 59 | */ |
| 60 | |
| 61 | /*! |
| 62 | * \struct DateTimeExpression |
| 63 | * \brief The DateTimeExpression struct holds information about a time expression (e.g. an ISO-8601 timestamp). |
| 64 | * |
| 65 | * This struct holds the date and time specification (DateTimeExpression::value), the time-zone delta |
| 66 | * (DateTimeExpression::delta) and what parts are actually specified (DateTimeExpression::parts). |
| 67 | * |
| 68 | * The idea is to be able to preserve a time-zone delta and present parts when deserializing and then |
| 69 | * serializing again. Note that it still does not allow to preserve the format of the original timestamp |
| 70 | * exactly. |
| 71 | */ |
| 72 | |
| 73 | /*! |
| 74 | * \brief Constructs a new DateTime object with the local time from the specified UNIX \a timeStamp. |
| 75 | */ |
| 76 | DateTimecxx . . $ CppUtilities/DateTime# DateTimecxx . . $ CppUtilities/DateTime#::fromTimeStampcxx . . $ CppUtilities/DateTime#fromTimeStamp(481e32044e5fdc05).(time_t timeStamp) |
| 77 | { |
| 78 | if (timeStamp) { |
| 79 | struct tmcxx . . $ tm# *const timeinfo = localtime(&timeStamp); |
| 80 | return DateTimecxx . . $ CppUtilities/DateTime#::fromDateAndTimecxx . . $ CppUtilities/DateTime#fromDateAndTime(aa79afcea2b9ba5).(timeinfo->tm_yearcxx . . $ tm#tm_year. + 1900, timeinfo->tm_moncxx . . $ tm#tm_mon. + 1, timeinfo->tm_mdaycxx . . $ tm#tm_mday., timeinfo->tm_hourcxx . . $ tm#tm_hour., timeinfo->tm_mincxx . . $ tm#tm_min., |
| 81 | timeinfo->tm_seccxx . . $ tm#tm_sec. < 60 ? timeinfo->tm_seccxx . . $ tm#tm_sec. : 59, 0); |
| 82 | } else { |
| 83 | return DateTimecxx . . $ CppUtilities/DateTime#DateTime(49f6e7a06ebc5aa8).(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /*! |
| 88 | * \brief Parses the given C-style string as DateTime. |
| 89 | * \throws Throws a ConversionException if the specified \a str does not match the expected time format. |
| 90 | * |
| 91 | * The expected format is something like "2012-02-29 15:34:20.033" or "2012/02/29 15:34:20.033". The |
| 92 | * delimiters '-', ':' and '/' are exchangeable. |
| 93 | * |
| 94 | * \sa DateTime::fromIsoString() |
| 95 | */ |
| 96 | DateTimecxx . . $ CppUtilities/DateTime# DateTimecxx . . $ CppUtilities/DateTime#::fromStringcxx . . $ CppUtilities/DateTime#fromString(935e9a342e01659a).(const char *str) |
| 97 | { |
| 98 | return DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression#::fromStringcxx . . $ CppUtilities/DateTimeExpression#fromString(61528dc78229123e).(str).valuecxx . . $ CppUtilities/DateTimeExpression#value.; |
| 99 | } |
| 100 | |
| 101 | /*! |
| 102 | * \brief Parses the specified ISO date time denotation provided as C-style string. |
| 103 | * \returns Returns a pair where the first value is the parsed date time and the second value |
| 104 | * the time zone designator (a time span which can be subtracted from the first value to get the UTC time). |
| 105 | * \throws Throws a ConversionException if the specified \a str does not match the expected time format. |
| 106 | * \remarks |
| 107 | * - Parsing durations and time intervals is *not* supported. |
| 108 | * - Truncated representations are *not* supported. |
| 109 | * - Standardised extensions (ISO 8601-2:2019) are *not* supported. |
| 110 | * \sa https://en.wikipedia.org/wiki/ISO_8601 |
| 111 | */ |
| 112 | stdcxx . . $ std/::paircxx . . $ std/pair#<DateTimecxx . . $ CppUtilities/DateTime#, TimeSpancxx . . $ CppUtilities/TimeSpan#> DateTimecxx . . $ CppUtilities/DateTime#::fromIsoStringcxx . . $ CppUtilities/DateTime#fromIsoString(e51b6f1fbe1aec73).(const char *str) |
| 113 | { |
| 114 | const auto expr = DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression#::fromIsoStringcxx . . $ CppUtilities/DateTimeExpression#fromIsoString(61528dc78229123e).(str); |
| 115 | return stdcxx . . $ std/::make_paircxx . . $ std/make_pair(1d30b6e115203116).(expr.valuecxx . . $ CppUtilities/DateTimeExpression#value., expr.deltacxx . . $ CppUtilities/DateTimeExpression#delta.); |
| 116 | } |
| 117 | |
| 118 | /*! |
| 119 | * \brief Returns the string representation of the current instance using the specified \a format. |
| 120 | * \remarks If \a noMilliseconds is true the date will be rounded to full seconds. |
| 121 | * \sa toIsoString() for ISO format |
| 122 | */ |
| 123 | void DateTimecxx . . $ CppUtilities/DateTime#::toStringcxx . . $ CppUtilities/DateTime#toString(dc9785426bdd7430).(stringcxx . . $ std/string# &result, DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat# format, bool noMilliseconds) const |
| 124 | { |
| 125 | if (format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::Isocxx . . $ CppUtilities/DateTimeOutputFormat#Iso.) { |
| 126 | result =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). toIsoStringcxx . . $ CppUtilities/DateTime#toIsoString(e6f522c1ca4180f0).(); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | stringstreamcxx . . $ std/stringstream# scxx . . $ std/__cxx11/basic_stringstream#basic_stringstream(322f8929844464d3).(stringstreamcxx . . $ std/stringstream#::incxx . . $ std/ios_base#in. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). stringstreamcxx . . $ std/stringstream#::outcxx . . $ std/ios_base#out.); |
| 131 | s <<cxx . . $ std/`operator<<`(47f1cf32aeb3f1a2). setfillcxx . . $ std/setfill(ade351e831a1374a).('0'); |
| 132 | |
| 133 | if (format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::IsoOmittingDefaultComponentscxx . . $ CppUtilities/DateTimeOutputFormat#IsoOmittingDefaultComponents.) { |
| 134 | constexpr auto dateDelimiter = '-', timeDelimiter = ':'; |
| 135 | const int components[] = { yearcxx . . $ CppUtilities/DateTime#year(455f465bc33b4cdf).(), monthcxx . . $ CppUtilities/DateTime#month(455f465bc33b4cdf).(), daycxx . . $ CppUtilities/DateTime#day(455f465bc33b4cdf).(), hourcxx . . $ CppUtilities/DateTime#hour(455f465bc33b4cdf).(), minutecxx . . $ CppUtilities/DateTime#minute(455f465bc33b4cdf).(), secondcxx . . $ CppUtilities/DateTime#second(455f465bc33b4cdf).(), millisecondcxx . . $ CppUtilities/DateTime#millisecond(455f465bc33b4cdf).(), microsecondcxx . . $ CppUtilities/DateTime#microsecond(455f465bc33b4cdf).(), nanosecondcxx . . $ CppUtilities/DateTime#nanosecond(455f465bc33b4cdf).() }; |
| 136 | const int *const firstTimeComponent = components + 3; |
| 137 | const int *const firstFractionalComponent = components + 6; |
| 138 | const int *const lastComponent = components + 8; |
| 139 | const int *componentsEnd = noMilliseconds ? firstFractionalComponent : lastComponent + 1; |
| 140 | for (const int *i = componentsEnd - 1; i > components; --i) { |
| 141 | if (i >= firstTimeComponent && *i == 0) { |
| 142 | componentsEnd = i; |
| 143 | } else if (i < firstTimeComponent && *i == 1) { |
| 144 | componentsEnd = i; |
| 145 | } |
| 146 | } |
| 147 | for (const int *i = components; i != componentsEnd; ++i) { |
| 148 | if (i == firstTimeComponent) { |
| 149 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). 'T'; |
| 150 | } else if (i == firstFractionalComponent) { |
| 151 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '.'; |
| 152 | } |
| 153 | if (i == components) { |
| 154 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(4) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). *i; |
| 155 | } else if (i < firstFractionalComponent) { |
| 156 | if (i < firstTimeComponent) { |
| 157 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). dateDelimiter; |
| 158 | } else if (i > firstTimeComponent) { |
| 159 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). timeDelimiter; |
| 160 | } |
| 161 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). *i; |
| 162 | } else if (i < lastComponent) { |
| 163 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(3) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). *i; |
| 164 | } else { |
| 165 | s <<cxx . . $ std/basic_ostream#`operator<<`(761e6a6e6922c86). *i / TimeSpancxx . . $ CppUtilities/TimeSpan#::nanosecondsPerTickcxx . . $ CppUtilities/TimeSpan#nanosecondsPerTick.; |
| 166 | } |
| 167 | } |
| 168 | result =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). s.strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).(); |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | if (format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndWeekday. || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndShortWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndShortWeekday.) |
| 173 | s <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). printDayOfWeekcxx . . $ CppUtilities/DateTime#printDayOfWeek(6bdfb5cd057db062).(dayOfWeekcxx . . $ CppUtilities/DateTime#dayOfWeek(d50da9aa82afe8a1).(), format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndShortWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndShortWeekday.) <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 174 | if (format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateOnlycxx . . $ CppUtilities/DateTimeOutputFormat#DateOnly. || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateAndTimecxx . . $ CppUtilities/DateTimeOutputFormat#DateAndTime. || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndWeekday. |
| 175 | || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndShortWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndShortWeekday.) |
| 176 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(4) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). yearcxx . . $ CppUtilities/DateTime#year(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-' <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). monthcxx . . $ CppUtilities/DateTime#month(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-' <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). daycxx . . $ CppUtilities/DateTime#day(455f465bc33b4cdf).(); |
| 177 | if (format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateAndTimecxx . . $ CppUtilities/DateTimeOutputFormat#DateAndTime. || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndWeekday. |
| 178 | || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndShortWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndShortWeekday.) |
| 179 | s <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " "; |
| 180 | if (format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::TimeOnlycxx . . $ CppUtilities/DateTimeOutputFormat#TimeOnly. || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateAndTimecxx . . $ CppUtilities/DateTimeOutputFormat#DateAndTime. || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndWeekday. |
| 181 | || format == DateTimeOutputFormatcxx . . $ CppUtilities/DateTimeOutputFormat#::DateTimeAndShortWeekdaycxx . . $ CppUtilities/DateTimeOutputFormat#DateTimeAndShortWeekday.) { |
| 182 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). hourcxx . . $ CppUtilities/DateTime#hour(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ':' <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). minutecxx . . $ CppUtilities/DateTime#minute(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ':' <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). secondcxx . . $ CppUtilities/DateTime#second(455f465bc33b4cdf).(); |
| 183 | int ms = millisecondcxx . . $ CppUtilities/DateTime#millisecond(455f465bc33b4cdf).(); |
| 184 | if (!noMilliseconds && ms > 0) { |
| 185 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '.' <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(3) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). ms; |
| 186 | } |
| 187 | } |
| 188 | result =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). s.strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).(); |
| 189 | } |
| 190 | |
| 191 | /*! |
| 192 | * \brief Returns the string representation of the current instance in the ISO format with custom delimiters, |
| 193 | * eg. 2016/08/29T21-32-31.588539814+02:00 with '/' as \a dateDelimiter and '-' as \a timeDelimiter. |
| 194 | */ |
| 195 | stringcxx . . $ std/string# DateTimecxx . . $ CppUtilities/DateTime#::toIsoStringWithCustomDelimiterscxx . . $ CppUtilities/DateTime#toIsoStringWithCustomDelimiters(44f5e9ca7d10a61f).(TimeSpancxx . . $ CppUtilities/TimeSpan# timeZoneDelta, char dateDelimiter, char timeDelimiter, char timeZoneDelimiter) const |
| 196 | { |
| 197 | stringstreamcxx . . $ std/stringstream# scxx . . $ std/__cxx11/basic_stringstream#basic_stringstream(322f8929844464d3).(stringstreamcxx . . $ std/stringstream#::incxx . . $ std/ios_base#in. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). stringstreamcxx . . $ std/stringstream#::outcxx . . $ std/ios_base#out.); |
| 198 | s <<cxx . . $ std/`operator<<`(47f1cf32aeb3f1a2). setfillcxx . . $ std/setfill(ade351e831a1374a).('0'); |
| 199 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(4) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). yearcxx . . $ CppUtilities/DateTime#year(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). dateDelimiter <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). monthcxx . . $ CppUtilities/DateTime#month(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). dateDelimiter <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). daycxx . . $ CppUtilities/DateTime#day(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). 'T' <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). hourcxx . . $ CppUtilities/DateTime#hour(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). timeDelimiter |
| 200 | <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). minutecxx . . $ CppUtilities/DateTime#minute(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). timeDelimiter <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). secondcxx . . $ CppUtilities/DateTime#second(455f465bc33b4cdf).(); |
| 201 | const int milli(millisecondcxx . . $ CppUtilities/DateTime#millisecond(455f465bc33b4cdf).()); |
| 202 | const int micro(microsecondcxx . . $ CppUtilities/DateTime#microsecond(455f465bc33b4cdf).()); |
| 203 | const int nano(nanosecondcxx . . $ CppUtilities/DateTime#nanosecond(455f465bc33b4cdf).()); |
| 204 | if (milli || micro || nano) { |
| 205 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '.' <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(3) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). milli; |
| 206 | if (micro || nano) { |
| 207 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(3) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). micro; |
| 208 | if (nano) { |
| 209 | s <<cxx . . $ std/basic_ostream#`operator<<`(761e6a6e6922c86). nano / TimeSpancxx . . $ CppUtilities/TimeSpan#::nanosecondsPerTickcxx . . $ CppUtilities/TimeSpan#nanosecondsPerTick.; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | if (!timeZoneDelta.isNullcxx . . $ CppUtilities/TimeSpan#isNull(50ce9a9e25b4a850).()) { |
| 214 | if (timeZoneDelta.isNegativecxx . . $ CppUtilities/TimeSpan#isNegative(50ce9a9e25b4a850).()) { |
| 215 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-'; |
| 216 | timeZoneDelta =cxx . . $ CppUtilities/TimeSpan#`operator=`(12696833f50715fa). TimeSpancxx . . $ CppUtilities/TimeSpan#(-timeZoneDelta.totalTickscxx . . $ CppUtilities/TimeSpan#totalTicks(57a65ae535d7db84).()); |
| 217 | } else { |
| 218 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '+'; |
| 219 | } |
| 220 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). timeZoneDelta.hourscxx . . $ CppUtilities/TimeSpan#hours(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). timeZoneDelimiter <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). timeZoneDelta.minutescxx . . $ CppUtilities/TimeSpan#minutes(455f465bc33b4cdf).(); |
| 221 | } |
| 222 | return s.strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).(); |
| 223 | } |
| 224 | |
| 225 | /*! |
| 226 | * \brief Returns the string representation of the current instance in the ISO format, |
| 227 | * eg. 2016-08-29T21:32:31.588539814+02:00. |
| 228 | */ |
| 229 | stringcxx . . $ std/string# DateTimecxx . . $ CppUtilities/DateTime#::toIsoStringcxx . . $ CppUtilities/DateTime#toIsoString(e6f522c1ca4180f0).(TimeSpancxx . . $ CppUtilities/TimeSpan# timeZoneDelta) const |
| 230 | { |
| 231 | return toIsoStringWithCustomDelimiterscxx . . $ CppUtilities/DateTime#toIsoStringWithCustomDelimiters(44f5e9ca7d10a61f).(timeZoneDelta); |
| 232 | } |
| 233 | |
| 234 | /*! |
| 235 | * \brief Returns the string representation as C-style string for the given day of week. |
| 236 | * |
| 237 | * If \a abbreviation is true, only the first three letters of the string will |
| 238 | * be returned. |
| 239 | * \sa DayOfWeek |
| 240 | */ |
| 241 | const char *DateTimecxx . . $ CppUtilities/DateTime#::printDayOfWeekcxx . . $ CppUtilities/DateTime#printDayOfWeek(6bdfb5cd057db062).(DayOfWeekcxx . . $ CppUtilities/DayOfWeek# dayOfWeek, bool abbreviation) |
| 242 | { |
| 243 | if (abbreviation) { |
| 244 | switch (dayOfWeek) { |
| 245 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Mondaycxx . . $ CppUtilities/DayOfWeek#Monday.: |
| 246 | return "Mon"; |
| 247 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Tuesdaycxx . . $ CppUtilities/DayOfWeek#Tuesday.: |
| 248 | return "Tue"; |
| 249 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Wednesdaycxx . . $ CppUtilities/DayOfWeek#Wednesday.: |
| 250 | return "Wed"; |
| 251 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Thursdaycxx . . $ CppUtilities/DayOfWeek#Thursday.: |
| 252 | return "Thu"; |
| 253 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Fridaycxx . . $ CppUtilities/DayOfWeek#Friday.: |
| 254 | return "Fri"; |
| 255 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Saturdaycxx . . $ CppUtilities/DayOfWeek#Saturday.: |
| 256 | return "Sat"; |
| 257 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Sundaycxx . . $ CppUtilities/DayOfWeek#Sunday.: |
| 258 | return "Sun"; |
| 259 | } |
| 260 | } else { |
| 261 | switch (dayOfWeek) { |
| 262 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Mondaycxx . . $ CppUtilities/DayOfWeek#Monday.: |
| 263 | return "Monday"; |
| 264 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Tuesdaycxx . . $ CppUtilities/DayOfWeek#Tuesday.: |
| 265 | return "Tuesday"; |
| 266 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Wednesdaycxx . . $ CppUtilities/DayOfWeek#Wednesday.: |
| 267 | return "Wednesday"; |
| 268 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Thursdaycxx . . $ CppUtilities/DayOfWeek#Thursday.: |
| 269 | return "Thursday"; |
| 270 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Fridaycxx . . $ CppUtilities/DayOfWeek#Friday.: |
| 271 | return "Friday"; |
| 272 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Saturdaycxx . . $ CppUtilities/DayOfWeek#Saturday.: |
| 273 | return "Saturday"; |
| 274 | case DayOfWeekcxx . . $ CppUtilities/DayOfWeek#::Sundaycxx . . $ CppUtilities/DayOfWeek#Sunday.: |
| 275 | return "Sunday"; |
| 276 | } |
| 277 | } |
| 278 | return ""; |
| 279 | } |
| 280 | |
| 281 | /*! |
| 282 | * \brief Returns a DateTime object that is set to the current date and time on this computer, expressed as the GMT time. |
| 283 | */ |
| 284 | DateTimecxx . . $ CppUtilities/DateTime# DateTimecxx . . $ CppUtilities/DateTime#::exactGmtNowcxx . . $ CppUtilities/DateTime#exactGmtNow(3a8d563d7eabf3e1).() |
| 285 | { |
| 286 | #ifdef CPP_UTILITIES_CHRONO_BASED_EXACT_TIME |
| 287 | return DateTime(DateTime::unixEpochStart().totalTicks() |
| 288 | + static_cast<std::uint64_t>( |
| 289 | std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch().count()) |
| 290 | / 100); |
| 291 | #else |
| 292 | struct timespec t; |
| 293 | clock_gettime(CLOCK_REALTIMEcxx . . $ `<external>/89459239771508533/time.h:46:10`!, &t); |
| 294 | return DateTimecxx . . $ CppUtilities/DateTime#DateTime(2c44cd906ae4e829).(DateTimecxx . . $ CppUtilities/DateTime#::unixEpochStartcxx . . $ CppUtilities/DateTime#unixEpochStart(3a8d563d7eabf3e1).().totalTickscxx . . $ CppUtilities/DateTime#totalTicks(fe4d2d262d4164a8).() + static_cast<stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t#>(t.tv_sec) * TimeSpancxx . . $ CppUtilities/TimeSpan#::ticksPerSecondcxx . . $ CppUtilities/TimeSpan#ticksPerSecond. |
| 295 | + static_cast<stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t#>(t.tv_nsec) / 100); |
| 296 | #endif |
| 297 | } |
| 298 | |
| 299 | /*! |
| 300 | * \brief Converts the given date expressed in \a year, \a month and \a day to ticks. |
| 301 | */ |
| 302 | DateTimecxx . . $ CppUtilities/DateTime#::TickTypecxx . . $ CppUtilities/DateTime#TickType# DateTimecxx . . $ CppUtilities/DateTime#::dateToTickscxx . . $ CppUtilities/DateTime#dateToTicks(840af37b591364d5).(int year, int month, int day) |
| 303 | { |
| 304 | if (!inRangeInclMaxcxx . . $ CppUtilities/inRangeInclMax(e174ffa2ff62cfae).(year, 1, 9999)) { |
| 305 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("year is out of range"); |
| 306 | } |
| 307 | if (!inRangeInclMaxcxx . . $ CppUtilities/inRangeInclMax(e174ffa2ff62cfae).(month, 1, 12)) { |
| 308 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("month is out of range"); |
| 309 | } |
| 310 | const auto *const daysToMonth = reinterpret_cast<const int *>(isLeapYearcxx . . $ CppUtilities/DateTime#isLeapYear(83c267b20bac841a).(year) ? m_daysToMonth366cxx . . $ CppUtilities/DateTime#m_daysToMonth366. : m_daysToMonth365cxx . . $ CppUtilities/DateTime#m_daysToMonth365.); |
| 311 | const int passedMonth = month - 1; |
| 312 | if (!inRangeInclMaxcxx . . $ CppUtilities/inRangeInclMax(e174ffa2ff62cfae).(day, 1, daysToMonth[month] - daysToMonth[passedMonth])) { |
| 313 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("day is out of range"); |
| 314 | } |
| 315 | const auto passedYears = static_cast<unsigned int>(year - 1); |
| 316 | const auto passedDays = static_cast<unsigned int>(day - 1); |
| 317 | return (passedYears * m_daysPerYearcxx . . $ CppUtilities/DateTime#m_daysPerYear. + passedYears / 4 - passedYears / 100 + passedYears / 400 |
| 318 | + static_cast<unsigned int>(daysToMonth[passedMonth]) + passedDays) |
| 319 | * TimeSpancxx . . $ CppUtilities/TimeSpan#::ticksPerDaycxx . . $ CppUtilities/TimeSpan#ticksPerDay.; |
| 320 | } |
| 321 | |
| 322 | /*! |
| 323 | * \brief Converts the given time expressed in \a hour, \a minute, \a second and \a millisecond to ticks. |
| 324 | */ |
| 325 | DateTimecxx . . $ CppUtilities/DateTime#::TickTypecxx . . $ CppUtilities/DateTime#TickType# DateTimecxx . . $ CppUtilities/DateTime#::timeToTickscxx . . $ CppUtilities/DateTime#timeToTicks(c67881ab8ac3a9c7).(int hour, int minute, int second, double millisecond) |
| 326 | { |
| 327 | if (!inRangeExclMaxcxx . . $ CppUtilities/inRangeExclMax(e174ffa2ff62cfae).(hour, 0, 24)) { |
| 328 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("hour is out of range"); |
| 329 | } |
| 330 | if (!inRangeExclMaxcxx . . $ CppUtilities/inRangeExclMax(e174ffa2ff62cfae).(minute, 0, 60)) { |
| 331 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("minute is out of range"); |
| 332 | } |
| 333 | if (!inRangeExclMaxcxx . . $ CppUtilities/inRangeExclMax(e174ffa2ff62cfae).(second, 0, 60)) { |
| 334 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("second is out of range"); |
| 335 | } |
| 336 | if (!inRangeExclMaxcxx . . $ CppUtilities/inRangeExclMax(e174ffa2ff62cfae).(millisecond, 0.0, 1000.0)) { |
| 337 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("millisecond is out of range"); |
| 338 | } |
| 339 | return static_cast<stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t#>(hour * TimeSpancxx . . $ CppUtilities/TimeSpan#::ticksPerHourcxx . . $ CppUtilities/TimeSpan#ticksPerHour.) + static_cast<stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t#>(minute * TimeSpancxx . . $ CppUtilities/TimeSpan#::ticksPerMinutecxx . . $ CppUtilities/TimeSpan#ticksPerMinute.) |
| 340 | + static_cast<stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t#>(second * TimeSpancxx . . $ CppUtilities/TimeSpan#::ticksPerSecondcxx . . $ CppUtilities/TimeSpan#ticksPerSecond.) + static_cast<stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t#>(millisecond * TimeSpancxx . . $ CppUtilities/TimeSpan#::ticksPerMillisecondcxx . . $ CppUtilities/TimeSpan#ticksPerMillisecond.); |
| 341 | } |
| 342 | |
| 343 | /*! |
| 344 | * \brief Returns the specified date part. |
| 345 | * \sa DatePart |
| 346 | */ |
| 347 | int DateTimecxx . . $ CppUtilities/DateTime#::getDatePartcxx . . $ CppUtilities/DateTime#getDatePart(702a50be8cbce955).(DatePartcxx . . $ CppUtilities/DatePart# part) const |
| 348 | { |
| 349 | const auto fullDays = static_cast<int>(m_tickscxx . . $ CppUtilities/DateTime#m_ticks. / TimeSpancxx . . $ CppUtilities/TimeSpan#::ticksPerDaycxx . . $ CppUtilities/TimeSpan#ticksPerDay.); |
| 350 | const auto full400YearBlocks = fullDays / m_daysPer400Yearscxx . . $ CppUtilities/DateTime#m_daysPer400Years.; |
| 351 | const auto daysMinusFull400YearBlocks = fullDays - full400YearBlocks * m_daysPer400Yearscxx . . $ CppUtilities/DateTime#m_daysPer400Years.; |
| 352 | auto full100YearBlocks = daysMinusFull400YearBlocks / m_daysPer100Yearscxx . . $ CppUtilities/DateTime#m_daysPer100Years.; |
| 353 | if (full100YearBlocks == 4) { |
| 354 | full100YearBlocks = 3; |
| 355 | } |
| 356 | const auto daysMinusFull100YearBlocks = daysMinusFull400YearBlocks - full100YearBlocks * m_daysPer100Yearscxx . . $ CppUtilities/DateTime#m_daysPer100Years.; |
| 357 | const auto full4YearBlocks = daysMinusFull100YearBlocks / m_daysPer4Yearscxx . . $ CppUtilities/DateTime#m_daysPer4Years.; |
| 358 | const auto daysMinusFull4YearBlocks = daysMinusFull100YearBlocks - full4YearBlocks * m_daysPer4Yearscxx . . $ CppUtilities/DateTime#m_daysPer4Years.; |
| 359 | auto full1YearBlocks = daysMinusFull4YearBlocks / m_daysPerYearcxx . . $ CppUtilities/DateTime#m_daysPerYear.; |
| 360 | if (full1YearBlocks == 4) { |
| 361 | full1YearBlocks = 3; |
| 362 | } |
| 363 | if (part == DatePartcxx . . $ CppUtilities/DatePart#::Yearcxx . . $ CppUtilities/DatePart#Year.) { |
| 364 | return full400YearBlocks * 400 + full100YearBlocks * 100 + full4YearBlocks * 4 + full1YearBlocks + 1; |
| 365 | } |
| 366 | const auto restDays = daysMinusFull4YearBlocks - full1YearBlocks * m_daysPerYearcxx . . $ CppUtilities/DateTime#m_daysPerYear.; |
| 367 | if (part == DatePartcxx . . $ CppUtilities/DatePart#::DayOfYearcxx . . $ CppUtilities/DatePart#DayOfYear.) { // day |
| 368 | return restDays + 1; |
| 369 | } |
| 370 | const auto *const daysToMonth = (full1YearBlocks == 3 && (full4YearBlocks != 24 || full100YearBlocks == 3)) ? m_daysToMonth366cxx . . $ CppUtilities/DateTime#m_daysToMonth366. : m_daysToMonth365cxx . . $ CppUtilities/DateTime#m_daysToMonth365.; |
| 371 | auto month = 1; |
| 372 | while (restDays >= daysToMonth[month]) { |
| 373 | ++month; |
| 374 | } |
| 375 | if (part == DatePartcxx . . $ CppUtilities/DatePart#::Monthcxx . . $ CppUtilities/DatePart#Month.) { |
| 376 | return month; |
| 377 | } else if (part == DatePartcxx . . $ CppUtilities/DatePart#::Daycxx . . $ CppUtilities/DatePart#Day.) { |
| 378 | return restDays - daysToMonth[month - 1] + 1; |
| 379 | } |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | /// \cond |
| 384 | static DateTimePartscxx . . $ CppUtilities/DateTimeParts# dateTimePartsFromParsingDistancecxx . . $ CppUtilities/dateTimePartsFromParsingDistance(4c8127f648f1c8d4).(const int *valueIndex, const int *values) |
| 385 | { |
| 386 | return static_cast<DateTimePartscxx . . $ CppUtilities/DateTimeParts#>((1 << (valueIndex - values + 1)) - 1); |
| 387 | } |
| 388 | /// \endcond |
| 389 | |
| 390 | /*! |
| 391 | * \brief Parses the specified ISO date time denotation provided as C-style string. |
| 392 | * \throws Throws a ConversionException if the specified \a str does not match the expected time format. |
| 393 | * \remarks |
| 394 | * - Parsing durations and time intervals is *not* supported. |
| 395 | * - Truncated representations are *not* supported. |
| 396 | * - Standardised extensions (ISO 8601-2:2019) are *not* supported. |
| 397 | * \sa https://en.wikipedia.org/wiki/ISO_8601 |
| 398 | */ |
| 399 | DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression# DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression#::fromIsoStringcxx . . $ CppUtilities/DateTimeExpression#fromIsoString(61528dc78229123e).(const char *str) |
| 400 | { |
| 401 | auto res = DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression#(); |
| 402 | int values[9] = { 0 }; |
| 403 | int *const yearIndex = values + 0; |
| 404 | int *const monthIndex = values + 1; |
| 405 | int *const dayIndex = values + 2; |
| 406 | int *const hourIndex = values + 3; |
| 407 | int *const secondsIndex = values + 5; |
| 408 | int *const miliSecondsIndex = values + 6; |
| 409 | int *const deltaHourIndex = values + 7; |
| 410 | int *const valuesEnd = values + 9; |
| 411 | int *valueIndex = values; |
| 412 | unsigned int remainingDigits = 4; |
| 413 | bool deltaNegative = false; |
| 414 | double millisecondsFact = 100.0, milliseconds = 0.0; |
| 415 | for (const char *strIndex = str;; ++strIndex) { |
| 416 | const char c = *strIndex; |
| 417 | if (c <= '9' && c >= '0') { |
| 418 | if (valueIndex == miliSecondsIndex) { |
| 419 | milliseconds += (c - '0') * millisecondsFact; |
| 420 | millisecondsFact /= 10; |
| 421 | } else { |
| 422 | if (!remainingDigits) { |
| 423 | if (++valueIndex == miliSecondsIndex || valueIndex >= valuesEnd) { |
| 424 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("Max. number of digits exceeded"); |
| 425 | } |
| 426 | remainingDigits = 2; |
| 427 | } |
| 428 | *valueIndex *= 10; |
| 429 | *valueIndex += c - '0'; |
| 430 | remainingDigits -= 1; |
| 431 | } |
| 432 | } else if (c == 'T') { |
| 433 | if (++valueIndex != hourIndex) { |
| 434 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("\"T\" expected before hour"); |
| 435 | } |
| 436 | remainingDigits = 2; |
| 437 | } else if (c == '-') { |
| 438 | if (valueIndex < dayIndex) { |
| 439 | ++valueIndex; |
| 440 | } else if (++valueIndex >= secondsIndex) { |
| 441 | valueIndex = deltaHourIndex; |
| 442 | deltaNegative = true; |
| 443 | } else { |
| 444 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("Unexpected \"-\" after day"); |
| 445 | } |
| 446 | remainingDigits = 2; |
| 447 | } else if (c == '.') { |
| 448 | if (valueIndex != secondsIndex) { |
| 449 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("Unexpected \".\""); |
| 450 | } else { |
| 451 | ++valueIndex; |
| 452 | } |
| 453 | } else if (c == ':') { |
| 454 | if (valueIndex < hourIndex) { |
| 455 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("Unexpected \":\" before hour"); |
| 456 | } else if (valueIndex == secondsIndex) { |
| 457 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("Unexpected \":\" after second"); |
| 458 | } else { |
| 459 | ++valueIndex; |
| 460 | } |
| 461 | remainingDigits = 2; |
| 462 | } else if ((c == '+') && (++valueIndex >= secondsIndex)) { |
| 463 | valueIndex = deltaHourIndex; |
| 464 | deltaNegative = false; |
| 465 | remainingDigits = 2; |
| 466 | } else if ((c == 'Z') && (++valueIndex >= secondsIndex)) { |
| 467 | valueIndex = deltaHourIndex + 2; |
| 468 | remainingDigits = 2; |
| 469 | } else if (c == '\0') { |
| 470 | break; |
| 471 | } else { |
| 472 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#(argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("Unexpected \"", c, '\"')); |
| 473 | } |
| 474 | } |
| 475 | res.deltacxx . . $ CppUtilities/DateTimeExpression#delta. =cxx . . $ CppUtilities/TimeSpan#`operator=`(12696833f50715fa). TimeSpancxx . . $ CppUtilities/TimeSpan#::fromMinutescxx . . $ CppUtilities/TimeSpan#fromMinutes(1a0c28e1b314a5ba).(*deltaHourIndex * 60 + values[8]); |
| 476 | if (deltaNegative) { |
| 477 | res.deltacxx . . $ CppUtilities/DateTimeExpression#delta. =cxx . . $ CppUtilities/TimeSpan#`operator=`(12696833f50715fa). TimeSpancxx . . $ CppUtilities/TimeSpan#(-res.deltacxx . . $ CppUtilities/DateTimeExpression#delta..totalTickscxx . . $ CppUtilities/TimeSpan#totalTicks(57a65ae535d7db84).()); |
| 478 | } |
| 479 | if (valueIndex < monthIndex && !*monthIndex) { |
| 480 | *monthIndex = 1; |
| 481 | } |
| 482 | if (valueIndex < dayIndex && !*dayIndex) { |
| 483 | *dayIndex = 1; |
| 484 | } |
| 485 | res.valuecxx . . $ CppUtilities/DateTimeExpression#value. =cxx . . $ CppUtilities/DateTime#`operator=`(4c75843575c0206c). DateTimecxx . . $ CppUtilities/DateTime#::fromDateAndTimecxx . . $ CppUtilities/DateTime#fromDateAndTime(aa79afcea2b9ba5).(*yearIndex, *monthIndex, *dayIndex, *hourIndex, values[4], *secondsIndex, milliseconds); |
| 486 | res.partscxx . . $ CppUtilities/DateTimeExpression#parts. = dateTimePartsFromParsingDistancecxx . . $ CppUtilities/dateTimePartsFromParsingDistance(4c8127f648f1c8d4).(valueIndex, values); |
| 487 | return res; |
| 488 | } |
| 489 | |
| 490 | /*! |
| 491 | * \brief Parses the given C-style string. |
| 492 | * \throws Throws a ConversionException if the specified \a str does not match the expected time format. |
| 493 | * |
| 494 | * The expected format is something like "2012-02-29 15:34:20.033" or "2012/02/29 15:34:20.033". The |
| 495 | * delimiters '-', ':' and '/' are exchangeable. |
| 496 | * |
| 497 | * \sa DateTimeExpression::fromIsoString() |
| 498 | */ |
| 499 | DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression# DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression#::fromStringcxx . . $ CppUtilities/DateTimeExpression#fromString(61528dc78229123e).(const char *str) |
| 500 | { |
| 501 | auto res = DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression#(); |
| 502 | int values[7] = { 0 }; |
| 503 | int *const monthIndex = values + 1; |
| 504 | int *const dayIndex = values + 2; |
| 505 | int *const secondsIndex = values + 5; |
| 506 | int *valueIndex = values; |
| 507 | int *const valuesEnd = values + 7; |
| 508 | double millisecondsFact = 100.0, milliseconds = 0.0; |
| 509 | for (const char *strIndex = str;; ++strIndex) { |
| 510 | const char c = *strIndex; |
| 511 | if (c <= '9' && c >= '0') { |
| 512 | if (valueIndex > secondsIndex) { |
| 513 | milliseconds += (c - '0') * millisecondsFact; |
| 514 | millisecondsFact /= 10; |
| 515 | } else { |
| 516 | Detailcxx . . $ CppUtilities/Detail/::raiseAndAddcxx . . $ CppUtilities/Detail/raiseAndAdd(ee4f409ca4beb690).(*valueIndex, 10, c); |
| 517 | } |
| 518 | } else if ((c == '-' || c == ':' || c == '/') || (c == '.' && (valueIndex == secondsIndex)) |
| 519 | || ((c == ' ' || c == 'T') && (valueIndex == dayIndex))) { |
| 520 | if (++valueIndex == valuesEnd) { |
| 521 | break; // just ignore further values for now |
| 522 | } |
| 523 | } else if (c == '\0') { |
| 524 | break; |
| 525 | } else { |
| 526 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#(argsToStringcxx . . $ CppUtilities/argsToString(2bd17df601864384).("Unexpected character \"", c, '\"')); |
| 527 | } |
| 528 | } |
| 529 | if (valueIndex < monthIndex && !*monthIndex) { |
| 530 | *monthIndex = 1; |
| 531 | } |
| 532 | if (valueIndex < dayIndex && !*dayIndex) { |
| 533 | *dayIndex = 1; |
| 534 | } |
| 535 | res.valuecxx . . $ CppUtilities/DateTimeExpression#value. =cxx . . $ CppUtilities/DateTime#`operator=`(4c75843575c0206c). DateTimecxx . . $ CppUtilities/DateTime#::fromDateAndTimecxx . . $ CppUtilities/DateTime#fromDateAndTime(aa79afcea2b9ba5).(values[0], values[1], *dayIndex, values[3], values[4], *secondsIndex, milliseconds); |
| 536 | res.partscxx . . $ CppUtilities/DateTimeExpression#parts. = dateTimePartsFromParsingDistancecxx . . $ CppUtilities/dateTimePartsFromParsingDistance(4c8127f648f1c8d4).(valueIndex, values); |
| 537 | return res; |
| 538 | } |
| 539 | |
| 540 | /*! |
| 541 | * \brief Returns the string representation of the current instance in the ISO format. |
| 542 | * \remarks Only present parts will be included. |
| 543 | */ |
| 544 | stdcxx . . $ std/::stringcxx . . $ std/string# DateTimeExpressioncxx . . $ CppUtilities/DateTimeExpression#::toIsoStringcxx . . $ CppUtilities/DateTimeExpression#toIsoString(e97fc8b60e6313bd).(char dateDelimiter, char timeDelimiter, char timeZoneDelimiter) const |
| 545 | { |
| 546 | auto s = stdcxx . . $ std/::stringstreamcxx . . $ std/stringstream#(stdcxx . . $ std/::stringstreamcxx . . $ std/stringstream#::incxx . . $ std/ios_base#in. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). stdcxx . . $ std/::stringstreamcxx . . $ std/stringstream#::outcxx . . $ std/ios_base#out.); |
| 547 | s <<cxx . . $ std/`operator<<`(47f1cf32aeb3f1a2). setfillcxx . . $ std/setfill(ade351e831a1374a).('0'); |
| 548 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::Yearcxx . . $ CppUtilities/DateTimeParts#Year.) { |
| 549 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(4) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). valuecxx . . $ CppUtilities/DateTimeExpression#value..yearcxx . . $ CppUtilities/DateTime#year(455f465bc33b4cdf).(); |
| 550 | } |
| 551 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::Monthcxx . . $ CppUtilities/DateTimeParts#Month.) { |
| 552 | if (s.tellpcxx . . $ std/basic_ostream#tellp(bf66e90edbd3e74a).()) { |
| 553 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). dateDelimiter; |
| 554 | } |
| 555 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). valuecxx . . $ CppUtilities/DateTimeExpression#value..monthcxx . . $ CppUtilities/DateTime#month(455f465bc33b4cdf).(); |
| 556 | } |
| 557 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::Daycxx . . $ CppUtilities/DateTimeParts#Day.) { |
| 558 | if (s.tellpcxx . . $ std/basic_ostream#tellp(bf66e90edbd3e74a).()) { |
| 559 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). dateDelimiter; |
| 560 | } |
| 561 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). valuecxx . . $ CppUtilities/DateTimeExpression#value..daycxx . . $ CppUtilities/DateTime#day(455f465bc33b4cdf).(); |
| 562 | } |
| 563 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::Hourcxx . . $ CppUtilities/DateTimeParts#Hour.) { |
| 564 | if (s.tellpcxx . . $ std/basic_ostream#tellp(bf66e90edbd3e74a).()) { |
| 565 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). 'T'; |
| 566 | } |
| 567 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). valuecxx . . $ CppUtilities/DateTimeExpression#value..hourcxx . . $ CppUtilities/DateTime#hour(455f465bc33b4cdf).(); |
| 568 | } |
| 569 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::Minutecxx . . $ CppUtilities/DateTimeParts#Minute.) { |
| 570 | if (s.tellpcxx . . $ std/basic_ostream#tellp(bf66e90edbd3e74a).()) { |
| 571 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). timeDelimiter; |
| 572 | } |
| 573 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). valuecxx . . $ CppUtilities/DateTimeExpression#value..minutecxx . . $ CppUtilities/DateTime#minute(455f465bc33b4cdf).(); |
| 574 | } |
| 575 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::Secondcxx . . $ CppUtilities/DateTimeParts#Second.) { |
| 576 | if (s.tellpcxx . . $ std/basic_ostream#tellp(bf66e90edbd3e74a).()) { |
| 577 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). timeDelimiter; |
| 578 | } |
| 579 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). valuecxx . . $ CppUtilities/DateTimeExpression#value..secondcxx . . $ CppUtilities/DateTime#second(455f465bc33b4cdf).(); |
| 580 | } |
| 581 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::SubSecondcxx . . $ CppUtilities/DateTimeParts#SubSecond.) { |
| 582 | const auto milli = valuecxx . . $ CppUtilities/DateTimeExpression#value..millisecondcxx . . $ CppUtilities/DateTime#millisecond(455f465bc33b4cdf).(); |
| 583 | const auto micro = valuecxx . . $ CppUtilities/DateTimeExpression#value..microsecondcxx . . $ CppUtilities/DateTime#microsecond(455f465bc33b4cdf).(); |
| 584 | const auto nano = valuecxx . . $ CppUtilities/DateTimeExpression#value..nanosecondcxx . . $ CppUtilities/DateTime#nanosecond(455f465bc33b4cdf).(); |
| 585 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '.' <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(3) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). milli; |
| 586 | if (micro || nano) { |
| 587 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(3) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). micro; |
| 588 | if (nano) { |
| 589 | s <<cxx . . $ std/basic_ostream#`operator<<`(761e6a6e6922c86). nano / TimeSpancxx . . $ CppUtilities/TimeSpan#::nanosecondsPerTickcxx . . $ CppUtilities/TimeSpan#nanosecondsPerTick.; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::TimeZoneDeltacxx . . $ CppUtilities/DateTimeParts#TimeZoneDelta.) { |
| 594 | auto d = deltacxx . . $ CppUtilities/DateTimeExpression#delta.; |
| 595 | if (d.isNegativecxx . . $ CppUtilities/TimeSpan#isNegative(50ce9a9e25b4a850).()) { |
| 596 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '-'; |
| 597 | d =cxx . . $ CppUtilities/TimeSpan#`operator=`(12696833f50715fa). TimeSpancxx . . $ CppUtilities/TimeSpan#(-d.totalTickscxx . . $ CppUtilities/TimeSpan#totalTicks(57a65ae535d7db84).()); |
| 598 | } else { |
| 599 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '+'; |
| 600 | } |
| 601 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::DeltaHourcxx . . $ CppUtilities/DateTimeParts#DeltaHour.) { |
| 602 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). d.hourscxx . . $ CppUtilities/TimeSpan#hours(455f465bc33b4cdf).(); |
| 603 | } |
| 604 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::DeltaMinutecxx . . $ CppUtilities/DateTimeParts#DeltaMinute.) { |
| 605 | if (partscxx . . $ CppUtilities/DateTimeExpression#parts. &&cxx . . $ CppUtilities/FlagEnumClassOperations/`operator&&`(780fb9bd2d2dda6f). DateTimePartscxx . . $ CppUtilities/DateTimeParts#::DeltaHourcxx . . $ CppUtilities/DateTimeParts#DeltaHour.) { |
| 606 | s <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). timeZoneDelimiter; |
| 607 | } |
| 608 | s <<cxx . . $ std/`operator<<`(fe9a269018418773). setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). d.minutescxx . . $ CppUtilities/TimeSpan#minutes(455f465bc33b4cdf).(); |
| 609 | } |
| 610 | } |
| 611 | return s.strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).(); |
| 612 | } |
| 613 | |
| 614 | } // namespace CppUtilities |