2 #ifndef HOBBES_UTIL_TIME_HPP_INCLUDED 3 #define HOBBES_UTIL_TIME_HPP_INCLUDED 22 while (s.size() > 0) {
27 if (u.first ==
"us") {
29 }
else if (u.first ==
"ms") {
31 }
else if (u.first ==
"s") {
33 }
else if (u.first ==
"m" || u.first ==
"min") {
35 }
else if (u.first ==
"h" || u.first ==
"hour") {
37 }
else if (u.first ==
"d" || u.first ==
"day") {
38 m = 1000000L*60*60*24;
41 r += str::to<uint64_t>(p.first) * m;
57 static const long msus = 1000;
58 static const long sus = msus * 1000;
59 static const long mus = sus * 60;
60 static const long hus = mus * 60;
61 static const long dayus = hus * 24;
63 uint64_t x = labs(ts);
64 uint64_t d = x / dayus; x -= d*dayus;
65 uint64_t h = x / hus; x -= h*hus;
66 uint64_t
m = x / mus; x -= m*mus;
67 uint64_t s = x / sus; x -= s*sus;
68 uint64_t ms = x / msus; x -= ms*msus;
71 std::ostringstream ss;
72 if (ts < 0) ss <<
"-";
73 if (d > 0) ss << d <<
"d";
74 if (h > 0) ss << h <<
"h";
75 if (m > 0) ss << m <<
"m";
76 if (s > 0 || (d == 0 && h == 0 && m == 0 && ms == 0 && us == 0)) {
79 if (ms > 0) ss << ms <<
"ms";
80 if (us > 0) ss << us <<
"us";
91 inline long mkTime(
int h,
int m,
int s,
int u) {
93 memset(&t, 0,
sizeof(t));
103 return (mktime(&t) * 1000 * 1000) + u;
111 int h = h_msu.first.empty() ? 0 : str::to<int>(h_msu.first);
112 int m = m_su.first.empty() ? 0 : str::to<int>(m_su.first);
113 int s = s_u.first.empty() ? 0 : str::to<int>(s_u.first);
114 int u = s_u.second.empty() ? 0 : str::to<int>(s_u.second);
120 int64_t s = x / (1000 * 1000);
121 int64_t us = x % (1000 * 1000);
123 static char buf[256];
124 strftime(buf,
sizeof(buf),
"%H:%M:%S", localtime((time_t*)&s));
126 std::ostringstream uss;
129 std::ostringstream ss;
132 ss << std::string((uss.str().size() < 6) ? (6 - uss.str().size()) : 0,
'0') << uss.str();
143 inline long mkDateTime(
int y,
int mon,
int d,
int h,
int min,
int s,
int u) {
145 memset(&t, 0,
sizeof(t));
152 t.tm_year = y - 1900;
155 return (mktime(&t) * 1000L * 1000L) + u;
159 int64_t s = x / (1000L * 1000L);
160 int64_t us = x % (1000L * 1000L);
161 tm* t = localtime((time_t*)&s);
164 return mkTime(t->tm_hour, t->tm_min, t->tm_sec, us);
166 return mkTime(0, 0, 0, 0);
171 int64_t s = x / (1000L * 1000L);
173 localtime_r((time_t*)&s, &t);
179 return mktime(&t) * 1000L * 1000L;
190 int y = y_mdThmsu.first.empty() ? 0 : str::to<int>(y_mdThmsu.first);
191 int mon = m_dThmsu.first.empty() ? 0 : str::to<int>(m_dThmsu.first);
192 int d = d_Thmsu.first.empty() ? 0 : str::to<int>(d_Thmsu.first);
194 int h = h_msu.first.empty() ? 0 : str::to<int>(h_msu.first);
195 int min = m_su.first.empty() ? 0 : str::to<int>(m_su.first);
196 int s = s_u.first.empty() ? 0 : str::to<int>(s_u.first);
197 int u = s_u.second.empty() ? 0 : str::to<int>(s_u.second);
203 int64_t s = x / (1000L * 1000L);
204 int64_t us = x % (1000L * 1000L);
206 static char buf[256];
207 strftime(buf,
sizeof(buf),
"%Y-%m-%dT%H:%M:%S", localtime((time_t*)&s));
209 std::ostringstream uss;
212 std::ostringstream ss;
215 ss << std::string((uss.str().size() < 6) ? (6 - uss.str().size()) : 0,
'0') << uss.str();
std::string showDateTime(long x)
Definition: time.H:202
pair lsplit(const std::string &s, const std::string &ss)
Definition: str.C:215
pair readWhile(bool(*P)(char), const std::string &s)
Definition: str.C:254
std::pair< std::string, std::string > pair
Definition: str.H:220
std::string showTimespan(long ts)
Definition: time.H:56
long mkDateTime(int y, int mon, int d, int h, int min, int s, int u)
Definition: time.H:143
size_t r(const reader::MetaData &md, size_t o, T *t)
Definition: storage.H:1730
std::vector< std::string > seq
Definition: str.H:19
long timeFromDateTime(long x)
Definition: time.H:158
long mkTime(int h, int m, int s, int u)
Definition: time.H:91
std::string showTime(long x)
Definition: time.H:119
long dateFromDateTime(long x)
Definition: time.H:170
long readDateTime(const std::string &x)
Definition: time.H:182
long readTime(const std::string &x)
Definition: time.H:106
LexicalAnnotation m(const YYLTYPE &p)
Definition: hexpr.parse.C:127
long readTimespan(std::string s)
Definition: time.H:19
bool isDigit(char c)
Definition: str.C:467
bool isNotDigit(char c)
Definition: str.C:471