diff options
author | Björn Lindström <bkhl@elektrubadur.se> | 2016-10-24 13:43:04 +0700 |
---|---|---|
committer | Michael Stapelberg <stapelberg@users.noreply.github.com> | 2016-10-24 08:43:04 +0200 |
commit | be87c5ac3881886b2274dc270535d34c4eb82bf3 (patch) | |
tree | fa75a7bf7fe835dca9c575b94db7512200cfbff6 /src/print_time.c | |
parent | 707ceffc8b556a3797651d78c0c0f37bae9884ea (diff) |
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.
Diffstat (limited to 'src/print_time.c')
-rw-r--r-- | src/print_time.c | 11 |
1 files changed, 10 insertions, 1 deletions
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 <stdio.h> #include <stdlib.h> #include <stdbool.h> +#include <locale.h> #include <yajl/yajl_gen.h> #include <yajl/yajl_version.h> @@ -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); } |