summaryrefslogtreecommitdiff
path: root/src/util/time.cpp
blob: 1953975b1876deee535be795d5a0bceccfe1d7e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <mbgl/util/time.hpp>
#include <mbgl/util/uv_detail.hpp>

namespace mbgl {
namespace util {

timestamp now() {
    return uv_hrtime();
}

static const char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
                               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

std::string rfc1123(std::time_t time) {
    std::tm info;
    gmtime_r(&time, &info);
    char buffer[30];
    snprintf(buffer, 30, "%s, %02d %s %4d %02d:%02d:%02d GMT", week[info.tm_wday], info.tm_mday,
             months[info.tm_mon], 1900 + info.tm_year, info.tm_hour, info.tm_min, info.tm_sec);
    return buffer;
}

}
}