# HG changeset patch # User Oleksandr Gavenko # Date 1389705149 -7200 # Node ID c2b825bf035370fc936feb2608a48fef7e85d2c4 # Parent 95b15ebd8e1e1040600626a879b281dd831414fc Add datediff useful function. diff -r 95b15ebd8e1e -r c2b825bf0353 .bashrc --- a/.bashrc Tue Jan 14 11:24:18 2014 +0200 +++ b/.bashrc Tue Jan 14 15:12:29 2014 +0200 @@ -176,3 +176,19 @@ . ~/.env.local fi +################################################################ +# Useful functions. + +datediff() { + [[ -n "$1" ]] || { echo first argument is missing; return 1; } + [[ -n "$2" ]] || { echo second argument is missing; return 1; } + local diff=$(( $(date -d "$2" +%s) - $(date -d "$1" +%s) )) + local sec=$(( diff % 60 )) + diff=$(( diff / 60 )) + local min=$(( diff % 60 )) + diff=$(( diff / 60 )) + local hour=$(( diff % 24 )) + local day=$(( diff / 24 )) + echo $day days $hour hours $min minutes $sec seconds +} +