18 namespace SWC {
namespace Time {
22 int8_t default_v = 0) noexcept {
24 while(**bufp && **bufp ==
'0') ++*bufp;
27 int64_t v = strtoll(*bufp, &last, 0);
37 int64_t
parse_ns(
int& err,
const std::string& buf) {
43 const char* ptr = buf.c_str();
55 info.tm_yday = info.tm_wday = 0;
57 info.tm_year = ns - 1900;
61 if(info.tm_mon < 1 || info.tm_mon > 12) {
75 if(info.tm_mday < 1 || info.tm_mday > 31) {
83 if(info.tm_hour < 0 || info.tm_hour > 23) {
91 if(info.tm_min < 0 || info.tm_min > 59) {
99 if(info.tm_sec < 0 || info.tm_sec > 59) {
104 ns = mktime(&info) * 1000000000;
107 for(
int places = 100000000;
108 *ptr && std::isdigit(*ptr) && places >= 1;
110 res += (*ptr - 48) * places;
118 (ns -= 1000000000 - res) += 1000000000;
120 (ns += res + 1000000000) -= 1000000000;
130 return mktime(&info) * 1000000000;
134 int64_t secs = ns/1000000000;
135 time_t t_secs = secs;
139 uint32_t n = -ns + secs * 1000000000;
149 std::strftime(res, 20,
"%Y/%m/%d %H:%M:%S", std::gmtime(&t_secs));
152 nanos.insert(nanos.cbegin(), 9-nanos.size(),
'0');
153 return std::string(res) +
"." + nanos;