From 370f9bd0e1719c3a51bb42d1b1272c8ea8c1501f Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Fri, 18 Mar 2022 18:56:10 -0600 Subject: config_time: Support new key, fmt This key allows the time format to be configurable. The default is '%T', but some users may not want the seconds or may want additional information. --- src/config_time.c | 6 +++++- src/config_time.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/config_time.c b/src/config_time.c index d6931ff..39c8427 100644 --- a/src/config_time.c +++ b/src/config_time.c @@ -22,12 +22,16 @@ void config_time_init(struct node* n) { n->type = CTYPE_TIME; n->loadfunc = &config_time_load; n->loadkey = &load_time_key; + + strcpy(((struct config_time*) n->data)->fmt, "%T"); } void load_time_key(struct node* n, char* key, char* val) { if(strcmp(key, "tz") == 0) strcpy(((struct config_time*) n->data)->tz, val); + else if(strcmp(key, "fmt") == 0) + strcpy(((struct config_time*) n->data)->fmt, val); else printf("ERROR: Unknown time key %s\n", key); } @@ -41,7 +45,7 @@ int config_time_load(struct node* n) { time(&timep); info = localtime(&timep); - strftime(n->text, 256, "%T", info); + strftime(n->text, 256, ((struct config_time*)n->data)->fmt, info); strcpy(n->color, C_DGREY); strcpy(n->label_color, C_LGREY); diff --git a/src/config_time.h b/src/config_time.h index 31155be..e8d1ea1 100644 --- a/src/config_time.h +++ b/src/config_time.h @@ -29,6 +29,7 @@ struct config_time { char tz[256]; + char fmt[128]; }; void config_time_init(struct node*); -- cgit v1.2.3