Skip to content

Instantly share code, notes, and snippets.

@jesatrix
Last active Aug 5, 2021
Embed
What would you like to do?
Bash Utils
get_duration () {
: ${1?"You must provide a number value"}
num=$1
min=0
hour=0
day=0
if((num>59));then
((sec=num%60))
((num=num/60))
if((num>59));then
((min=num%60))
((num=num/60))
if((num>23));then
((hour=num%24))
((day=num/24))
else
((hour=num))
fi
else
((min=num))
fi
else
((sec=num))
fi
echo "$day"d "$hour"h "$min"m "$sec"s
}
timestamp_now() {
date -u +%Y-%m-%dT%H:%M:%SZ
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment