From c01a8110a46ac084ae1fe2f55048c6bf71f6b57d Mon Sep 17 00:00:00 2001 From: Iakov Davydov Date: Wed, 5 Feb 2014 11:12:47 +0100 Subject: Add hide_seconds option fixes: #1134 --- src/print_battery_info.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/print_battery_info.c') 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)); -- cgit v1.2.3