Skip to content

Commit

Permalink
Calculate total time compilation plurification
Browse files Browse the repository at this point in the history
  • Loading branch information
FrangaL committed May 20, 2023
1 parent b010cce commit 019d0f1
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions rpi-img-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,22 @@ status_i=0
status_t=$(($(grep '.*status ' $0 | wc -l) -1))

# Calculate total time compilation.
total_time() {
local T=$1
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
printf '\nTiempo final: '
[[ $H -gt 0 ]] && printf '%d hours ' $H
[[ $M -gt 0 ]] && printf '%d minutes ' $M
[[ $D -gt 0 || $H -gt 0 || $M -gt 0 ]] && printf 'and '
printf '%d seconds\n' $S
function fmt_plural() {
[[ $1 -gt 1 ]] && printf "%d %s" $1 "${3}" || printf "%d %s" $1 "${2}"
}


function total_time() {
local t=$(( $1 ))
local h=$(( t / 3600 ))
local m=$(( t % 3600 / 60 ))
local s=$(( t % 60 ))

printf "Duración: "
[[ $h -gt 0 ]] && { fmt_plural $h "hora" "horas"; printf " "; }
[[ $m -gt 0 ]] && { fmt_plural $m "minuto" "minutos"; printf " "; }
[[ $s -gt 0 ]] && fmt_plural $s "segundo" "segundos"
printf "\n"
}

installdeps() {
Expand Down

0 comments on commit 019d0f1

Please sign in to comment.