summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2022-07-16 18:06:29 -0600
committerAaron Ball <nullspoon@oper.io>2022-07-16 18:09:16 -0600
commit9f5c2bda3a42c64f7708bda1ba800671f1bb6a87 (patch)
tree9884b33f765ffcec55606489bad950f39c486c4d
parentca9231bb239ca6116828f731e077c6f10da14a04 (diff)
downloadi3cstat-9f5c2bda3a42c64f7708bda1ba800671f1bb6a87.tar.gz
i3cstat-9f5c2bda3a42c64f7708bda1ba800671f1bb6a87.tar.xz
Support new locale key for time and date
Since different locales support different date formats, this allows specification of the locale for a given time/date instance, rather than setting the locale for the entire program instance and affecting all other instances. Note that this probably will not have much of an effect unless the default `fmt` value is overridden (try `%c` for fun).
-rw-r--r--src/config_time.c10
-rw-r--r--src/config_time.h2
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*);

Generated by cgit