1 // vim:ts=4:sw=4:expandtab
6 #include <yajl/yajl_gen.h>
7 #include <yajl/yajl_version.h>
11 static bool local_timezone_init = false;
12 static const char *local_timezone = NULL;
13 static const char *current_timezone = NULL;
15 void set_timezone(const char *tz) {
16 if (!local_timezone_init) {
17 /* First call, initialize. */
18 local_timezone = getenv("TZ");
19 local_timezone_init = true;
21 if (tz == NULL || tz[0] == '\0') {
22 /* User wants localtime. */
25 if (tz != current_timezone) {
32 current_timezone = tz;
36 void print_time(yajl_gen json_gen, char *buffer, const char *title, const char *format, const char *tz, const char *format_time, time_t t) {
38 char *outwalk = buffer;
48 if (format_time == NULL) {
49 strftime(timebuf, sizeof(timebuf), format, &tm);
50 maybe_escape_markup(timebuf, &outwalk);
52 for (walk = format; *walk != '\0'; walk++) {
58 if (BEGINS_WITH(walk + 1, "time")) {
59 strftime(timebuf, sizeof(timebuf), format_time, &tm);
60 maybe_escape_markup(timebuf, &outwalk);
61 walk += strlen("time");
67 OUTPUT_FULL_TEXT(buffer);