From: Michael Tremer Date: Wed, 14 Sep 2016 08:35:42 +0000 (+0200) Subject: DHCP: Format lease time in human-readable format X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d13929d49de9298b74940d254915adc637dab63b;p=people%2Fjschlag%2Fnetwork.git DHCP: Format lease time in human-readable format Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.util b/src/functions/functions.util index 91b5148..9c3601b 100644 --- a/src/functions/functions.util +++ b/src/functions/functions.util @@ -113,6 +113,26 @@ format() { printf -v "${key}" "${format}" "$@" } +format_time() { + local s=${1} + local ret m + + local units="s m h" + + local unit + for unit in ${units}; do + m=$(( ${s} % 60 )) + s=$(( ${s} / 60 )) + + if [ ${m} -gt 0 ]; then + ret="${m}${unit} ${ret}" + fi + done + + # Remove whitespace + echo ${ret} +} + assign() { local key=${1} assert isset key diff --git a/src/network b/src/network index e45e8ad..719664e 100644 --- a/src/network +++ b/src/network @@ -840,11 +840,11 @@ cli_dhcpd_show() { ipv6) cli_headline 2 "Lease times" if isinteger VALID_LIFETIME; then - cli_print_fmt1 2 "Valid lifetime" "${VALID_LIFETIME}s" + cli_print_fmt1 2 "Valid lifetime" "$(format_time ${VALID_LIFETIME})" fi if isinteger PREFERRED_LIFETIME; then - cli_print_fmt1 2 "Preferred lifetime" "${PREFERRED_LIFETIME}s" + cli_print_fmt1 2 "Preferred lifetime" "$(format_time ${PREFERRED_LIFETIME})" fi cli_space @@ -854,11 +854,11 @@ cli_dhcpd_show() { cli_space cli_headline 2 "Lease times" - cli_print_fmt1 2 "Default lease time" "${DEFAULT_LEASE_TIME}s" - cli_print_fmt1 2 "Max. lease time" "${MAX_LEASE_TIME}s" + cli_print_fmt1 2 "Default lease time" "$(format_time ${DEFAULT_LEASE_TIME})" + cli_print_fmt1 2 "Max. lease time" "$(format_time ${MAX_LEASE_TIME})" if isset MIN_LEASE_TIME; then - cli_print_fmt1 2 "Min. lease time" "${MIN_LEASE_TIME}s" + cli_print_fmt1 2 "Min. lease time" "$(format_time ${MIN_LEASE_TIME})" fi cli_space