From 797fd1710f2f1ea082bf111f2c930c7c36cb59b4 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Thu, 12 Dec 2019 00:23:42 +1030 Subject: added meridem flag you can now toggle whether to show the meridem tag on each clock you configure --- components.c | 23 +++++++++++++++++++---- config.h | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components.c b/components.c index 09c1fc0..8244432 100644 --- a/components.c +++ b/components.c @@ -52,21 +52,36 @@ converthour(int hour) char *currenttime(char *store, size_t size, int flag) { int time[2]; + char meridiem[3]; gettime(time); + if (flag & SHOWMERIDIEM) + { + meridiem[1] = 'M'; + meridiem[2] = '\0'; + if (time[0] < 12) + meridiem[0] = 'A'; + else + meridiem[0] = 'P'; + + } if (flag & NORMALTIME) { - if (time[0] > 12) + if (time[0] == 0) + time[0] = 12; + else if (time[0] > 12) time[0] = converthour(time[0]); } if (flag & BINARYTIME) { - snprintf(store, size, "%05d:%05d ", dectobin(time[0]), - dectobin(time[1])); + snprintf(store, size, "%05d:%05d %s ", dectobin(time[0]), + dectobin(time[1]), + meridiem); } /* military time is the default, so we need not do anything */ else { - snprintf(store, size, "%02d:%02d ", time[0], time[1]); + snprintf(store, size, "%02d:%02d %s ", time[0], time[1], + meridiem); } return store; } diff --git a/config.h b/config.h index b006afd..a6b7039 100644 --- a/config.h +++ b/config.h @@ -23,6 +23,7 @@ enum flag NORMALTIME = 1<<1, BINARYTIME = 1<<2, MILITARYTIME = 1<<3, + SHOWMERIDIEM = 1<<4, }; struct component @@ -37,7 +38,7 @@ struct component */ static const struct component components[] ={ /* function flag */ - {currenttime, NORMALTIME}, + {currenttime, NORMALTIME|SHOWMERIDIEM}, {battery, 0}, {charging, 0}, }; -- cgit v1.2.3