From be87c5ac3881886b2274dc270535d34c4eb82bf3 Mon Sep 17 00:00:00 2001 From: Björn Lindström Date: Mon, 24 Oct 2016 13:43:04 +0700 Subject: Setting of custom locale in tztime configuration. (#168) To be able to show my birth country's time zone in that country's locale, and my local time in my current locale. --- src/print_time.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/print_time.c') diff --git a/src/print_time.c b/src/print_time.c index 9fa6642..c8da9d6 100644 --- a/src/print_time.c +++ b/src/print_time.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -33,7 +34,7 @@ void set_timezone(const char *tz) { } } -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; @@ -45,6 +46,10 @@ void print_time(yajl_gen json_gen, char *buffer, const char *title, const char * 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); @@ -63,6 +68,10 @@ void print_time(yajl_gen json_gen, char *buffer, const char *title, const char * } } + if (locale != NULL) { + setlocale(LC_ALL, ""); + } + *outwalk = '\0'; OUTPUT_FULL_TEXT(buffer); } -- cgit v1.2.3