prezto/modules/last_command/functions/time_to_human
Alex Reece 36559d9978 Add changes from sorin codereview
-    autoload functions aren't surrounded in an addition function { }
-    export cross platform notify function
-    control notify behavior with zstyles
2013-06-13 16:22:53 -04:00

24 lines
700 B
Text

#
# Pretty prints a time in human readable format.
#
# Authors:
# Alex Reece <awreece@gmail.com>
#
# Converts a floating point time duration in seconds to a human readable string.
seconds=$1
if (( seconds < 10 )); then
printf "%6.3fs" $seconds
elif (( seconds < 60 )); then
printf "%6.3fs" $seconds
elif (( seconds < (60*60) )); then
printf "%6.3fm" $(( seconds / 60 ))
elif (( seconds < (60*60*24) )); then
printf "%6.3fh" $(( seconds / (60*60) ))
elif (( seconds < (60*60*24*30) )); then
printf "%6.3fd" $(( seconds / (60*60*24) ))
elif (( seconds < (60*60*24*30*12) )); then
printf "%6.3fm" $(( seconds / (60*60*24*30) ))
else
printf "%6.3fy" $(( seconds / (60*60*24*30*12) ))
fi