5 #include <yajl/yajl_gen.h>
6 #include <yajl/yajl_version.h>
10 static int local_timezone_init = 0;
11 static const char *local_timezone = NULL;
12 static const char *current_timezone = NULL;
14 void set_timezone(const char *timezone) {
15 if (!local_timezone_init) {
16 /* First call, initialize. */
17 local_timezone = getenv("TZ");
18 local_timezone_init = 1;
20 if (timezone == NULL || timezone[0] == '\0') {
21 /* User wants localtime. */
22 timezone = local_timezone;
24 if (timezone != current_timezone) {
26 setenv("TZ", timezone, 1);
31 current_timezone = timezone;
35 void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *timezone, time_t t) {
36 char *outwalk = buffer;
39 /* Convert time and format output. */
40 set_timezone(timezone);
42 outwalk += strftime(outwalk, 4095, format, &tm);
44 OUTPUT_FULL_TEXT(buffer);