in squangle/mysql_client/Row.cpp [193:221]
std::chrono::microseconds parseTimeOnly(
folly::StringPiece mysql_time,
enum_field_types field_type) {
static re2::RE2 time_pattern(
"([-]?\\d{1,3}):(\\d{2}):(\\d{2})(?:\\.(\\d{1,6}))?");
int hours = 0, minutes = 0, seconds = 0, microseconds = 0;
std::string microseconds_str;
if (field_type != MYSQL_TYPE_TIME) {
throw std::range_error("No conversion available");
}
re2::StringPiece re2_mysql_time(mysql_time.data(), mysql_time.size());
if (!re2::RE2::FullMatch(
re2_mysql_time.data(),
time_pattern,
&hours,
&minutes,
&seconds,
µseconds_str)) {
throw std::range_error("Can't parse time");
}
if (!microseconds_str.empty()) {
microseconds_str.resize(6, '0');
microseconds = folly::to<int>(microseconds_str.c_str());
}
auto result = std::chrono::hours(hours) + std::chrono::minutes(minutes) +
std::chrono::seconds(seconds) + std::chrono::microseconds(microseconds);
return result;
}