| 91 | } |
| 92 | |
| 93 | void UtcTimestamp::FromIsoDateTime(const std::string &date_time) { |
| 94 | enum DateState { |
| 95 | Start, |
| 96 | Year, |
| 97 | Month, |
| 98 | Day, |
| 99 | Hour, |
| 100 | Minute, |
| 101 | Second, |
| 102 | MilliSecond, |
| 103 | TzHour, |
| 104 | TzMinute, |
| 105 | End |
| 106 | } state = DateState::Start; |
| 107 | |
| 108 | std::ostringstream year; |
| 109 | std::ostringstream month; |
| 110 | std::ostringstream day; |
| 111 | |
| 112 | std::ostringstream hour; |
| 113 | std::ostringstream minute; |
| 114 | std::ostringstream second; |
| 115 | std::ostringstream millisecond; |
| 116 | |
| 117 | std::ostringstream tz_hour; |
| 118 | std::ostringstream tz_minute; |
| 119 | |
| 120 | bool utc = false; |
| 121 | |
| 122 | for (char input : date_time) { |
| 123 | switch (state) { |
| 124 | case DateState::Start: |
| 125 | if ( std::isdigit(input) ) { |
| 126 | year << input; |
| 127 | state = DateState::Year; |
| 128 | } else if (input == 'T') { |
| 129 | year << "1970"; |
| 130 | month << "01"; |
| 131 | day << "01"; |
| 132 | state = DateState::Hour; |
| 133 | } |
| 134 | break; |
| 135 | |
| 136 | case DateState::Year: |
| 137 | if (input == '-') { |
| 138 | state = DateState::Month; |
| 139 | } else if (std::isdigit(input) && year.str().size() < 4) { |
| 140 | year << input; |
| 141 | } else if (std::isdigit(input) && year.str().size() >= 4) { |
| 142 | month << input; |
| 143 | state = DateState::Month; |
| 144 | } else if (input == 'Z') { |
| 145 | utc = true; |
| 146 | } |
| 147 | break; |
| 148 | |
| 149 | case DateState::Month: |
| 150 | if (input == '-') { |