diff options
author | Aaron Ball <nullspoon@oper.io> | 2022-07-16 18:10:01 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2022-07-16 18:10:01 -0600 |
commit | 587ffaabbd941fbe69ab7d085218d5a4c483b0db (patch) | |
tree | 9884b33f765ffcec55606489bad950f39c486c4d | |
parent | ca9231bb239ca6116828f731e077c6f10da14a04 (diff) | |
parent | 9f5c2bda3a42c64f7708bda1ba800671f1bb6a87 (diff) | |
download | i3cstat-master.tar.gz i3cstat-master.tar.xz |
-rw-r--r-- | src/config_time.c | 10 | ||||
-rw-r--r-- | src/config_time.h | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/config_time.c b/src/config_time.c index 39c8427..a480a60 100644 --- a/src/config_time.c +++ b/src/config_time.c @@ -23,6 +23,12 @@ void config_time_init(struct node* n) { n->loadfunc = &config_time_load; n->loadkey = &load_time_key; + if(getenv("LANG") != NULL) { + strcpy(( (struct config_time*) n->data)->locale, getenv("LANG")); + } else { + strcpy(( (struct config_time*) n->data)->locale, "POSIX"); + } + strcpy(((struct config_time*) n->data)->fmt, "%T"); } @@ -32,6 +38,8 @@ void load_time_key(struct node* n, char* key, char* val) { strcpy(((struct config_time*) n->data)->tz, val); else if(strcmp(key, "fmt") == 0) strcpy(((struct config_time*) n->data)->fmt, val); + else if(strcmp(key, "locale") == 0) + strcpy(((struct config_time*) n->data)->locale, val); else printf("ERROR: Unknown time key %s\n", key); } @@ -42,6 +50,8 @@ int config_time_load(struct node* n) { struct tm* info; setenv("TZ", ((struct config_time*)n->data)->tz, 1); + setlocale(LC_ALL, ((struct config_time*)n->data)->locale); + time(&timep); info = localtime(&timep); diff --git a/src/config_time.h b/src/config_time.h index e8d1ea1..8d07b63 100644 --- a/src/config_time.h +++ b/src/config_time.h @@ -24,12 +24,14 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include <locale.h> #include "common.h" #include "config_node.h" struct config_time { char tz[256]; char fmt[128]; + char locale[64]; }; void config_time_init(struct node*); |