File: timefuncs.c

package info (click to toggle)
haskell-snap-core 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 576 kB
  • sloc: haskell: 6,767; sh: 55; ansic: 22; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 573 bytes parent folder | download | duplicates (2)
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
26
27
28
#define _XOPEN_SOURCE
#define _BSD_SOURCE
#include <time.h>
#include <locale.h>


void set_c_locale() {
    setlocale(LC_TIME, "C");
}


time_t c_parse_http_time(char* s) {
    struct tm dest;
    strptime(s, "%a, %d %b %Y %H:%M:%S GMT", &dest);
    return timegm(&dest);
}

void c_format_http_time(time_t src, char* dest) {
    struct tm t;
    gmtime_r(&src, &t);
    strftime(dest, 40, "%a, %d %b %Y %H:%M:%S GMT", &t);
}

void c_format_log_time(time_t src, char* dest) {
    struct tm t;
    localtime_r(&src, &t);
    strftime(dest, 40, "%d/%b/%Y:%H:%M:%S %z", &t);
}