diff options
author | Iakov Davydov <davydov@xkcd.ru> | 2014-02-05 11:12:47 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2014-02-08 20:36:59 +0100 |
commit | c01a8110a46ac084ae1fe2f55048c6bf71f6b57d (patch) | |
tree | 95f7bd801e69bf4a6386bd879b593b0e0c48ca24 /src/print_battery_info.c | |
parent | 38938c344474d90ce4c5750efa5c26c893c76c80 (diff) |
Add hide_seconds option
fixes: #1134
Diffstat (limited to 'src/print_battery_info.c')
-rw-r--r-- | src/print_battery_info.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 03bacdf..bd3ff5c 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -30,7 +30,7 @@ * worn off your battery is. * */ -void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity) { +void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds) { time_t empty_time; struct tm *empty_tm; char buf[1024]; @@ -166,15 +166,23 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char } } - (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d", - max(hours, 0), max(minutes, 0), max(seconds, 0)); + if (hide_seconds) + (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d", + max(hours, 0), max(minutes, 0)); + else + (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d", + max(hours, 0), max(minutes, 0), max(seconds, 0)); empty_time = time(NULL); empty_time += seconds_remaining; empty_tm = localtime(&empty_time); - (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d", - max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0)); + if (hide_seconds) + (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d", + max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0)); + else + (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d", + max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0)); (void)snprintf(consumptionbuf, sizeof(consumptionbuf), "%1.2fW", ((float)present_rate / 1000.0 / 1000.0)); |