To be able to show my birth country's time zone in that country's locale, and my local time in my current locale.
cfg_opt_t tztime_opts[] = {
CFG_STR("format", "%Y-%m-%d %H:%M:%S %Z", CFGF_NONE),
CFG_STR("timezone", "", CFGF_NONE),
+ CFG_STR("locale", "", CFGF_NONE),
CFG_STR("format_time", NULL, CFGF_NONE),
CFG_CUSTOM_ALIGN_OPT,
CFG_CUSTOM_MIN_WIDTH_OPT,
CASE_SEC("time") {
SEC_OPEN_MAP("time");
- print_time(json_gen, buffer, NULL, cfg_getstr(sec, "format"), NULL, NULL, tv.tv_sec);
+ print_time(json_gen, buffer, NULL, cfg_getstr(sec, "format"), NULL, NULL, NULL, tv.tv_sec);
SEC_CLOSE_MAP;
}
CASE_SEC_TITLE("tztime") {
SEC_OPEN_MAP("tztime");
- print_time(json_gen, buffer, title, cfg_getstr(sec, "format"), cfg_getstr(sec, "timezone"), cfg_getstr(sec, "format_time"), tv.tv_sec);
+ print_time(json_gen, buffer, title, cfg_getstr(sec, "format"), cfg_getstr(sec, "timezone"), cfg_getstr(sec, "locale"), cfg_getstr(sec, "format_time"), tv.tv_sec);
SEC_CLOSE_MAP;
}
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *format_not_mounted, const char *prefix_type, const char *threshold_type, const double low_threshold);
void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_unk, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds);
-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);
+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);
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t);
const char *get_ip_addr(const char *interface);
void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
Files below that path make for valid timezone strings, e.g. for
+/usr/share/zoneinfo/Europe/Berlin+ you can set timezone to +Europe/Berlin+
in the +tztime+ module.
+To override the locale settings of your environment, set the +locale+ option.
*Example order*: +tztime berlin+
*Example timezone*: +Europe/Berlin+
+*Example locale*: +de_DE.UTF-8+
+
If you would like to use markup in this section, there is a separate
+format_time+ option that is automatically escaped. Its output then replaces
%time in the format string.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
+#include <locale.h>
#include <yajl/yajl_gen.h>
#include <yajl/yajl_version.h>
}
}
-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) {
+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) {
const char *walk;
char *outwalk = buffer;
struct tm tm;
set_timezone(tz);
localtime_r(&t, &tm);
+ if (locale != NULL) {
+ setlocale(LC_ALL, locale);
+ }
+
if (format_time == NULL) {
strftime(timebuf, sizeof(timebuf), format, &tm);
maybe_escape_markup(timebuf, &outwalk);
}
}
+ if (locale != NULL) {
+ setlocale(LC_ALL, "");
+ }
+
*outwalk = '\0';
OUTPUT_FULL_TEXT(buffer);
}