1 #pragma once
2 
3 #include <chrono>
4 #include <string>
5 
6 namespace mbgl {
7 
8 using Clock = std::chrono::steady_clock;
9 
10 using Seconds = std::chrono::seconds;
11 using Milliseconds = std::chrono::milliseconds;
12 
13 using TimePoint = Clock::time_point;
14 using Duration  = Clock::duration;
15 
16 // Used to measure second-precision times, such as times gathered from HTTP responses.
17 using Timestamp = std::chrono::time_point<std::chrono::system_clock, Seconds>;
18 
19 namespace util {
20 
now()21 inline Timestamp now() {
22     return std::chrono::time_point_cast<Seconds>(std::chrono::system_clock::now());
23 }
24 
25 // Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT"
26 std::string rfc1123(Timestamp);
27 
28 // YYYY-mm-dd HH:MM:SS e.g. "2015-11-26 16:11:23"
29 std::string iso8601(Timestamp);
30 
31 Timestamp parseTimestamp(const char *);
32 
33 Timestamp parseTimestamp(const int32_t timestamp);
34 
35 // C++17 polyfill
36 template <class Rep, class Period, class = std::enable_if_t<
37    std::chrono::duration<Rep, Period>::min() < std::chrono::duration<Rep, Period>::zero()>>
abs(std::chrono::duration<Rep,Period> d)38 constexpr std::chrono::duration<Rep, Period> abs(std::chrono::duration<Rep, Period> d)
39 {
40     return d >= d.zero() ? d : -d;
41 }
42 
43 } // namespace util
44 
45 } // namespace mbgl
46