1 // vim:ts=4:sw=4:expandtab
7 #include <yajl/yajl_gen.h>
8 #include <yajl/yajl_version.h>
12 static bool local_timezone_init = false;
13 static const char *local_timezone = NULL;
14 static const char *current_timezone = NULL;
16 void set_timezone(const char *tz) {
17 if (!local_timezone_init) {
18 /* First call, initialize. */
19 local_timezone = getenv("TZ");
20 local_timezone_init = true;
22 if (tz == NULL || tz[0] == '\0') {
23 /* User wants localtime. */
26 if (tz != current_timezone) {
33 current_timezone = tz;
37 void print_time(yajl_gen json_gen, char *buffer, const char *title, const char *format, const char *tz, const char *locale, const char *format_time, time_t t) {
39 char *outwalk = buffer;
50 setlocale(LC_ALL, locale);
53 if (format_time == NULL) {
54 strftime(timebuf, sizeof(timebuf), format, &tm);
55 maybe_escape_markup(timebuf, &outwalk);
57 for (walk = format; *walk != '\0'; walk++) {
63 if (BEGINS_WITH(walk + 1, "time")) {
64 strftime(timebuf, sizeof(timebuf), format_time, &tm);
65 maybe_escape_markup(timebuf, &outwalk);
66 walk += strlen("time");
72 setlocale(LC_ALL, "");
76 OUTPUT_FULL_TEXT(buffer);