Merge pull request #552 from crawford/core_date

core_date: add help message
This commit is contained in:
Alex Crawford 2016-06-01 15:02:38 -07:00
commit 05c491d333

View File

@ -7,7 +7,29 @@
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/common.sh" || exit 1
if [[ "$1" == "-v" ]]; then
USAGE="USAGE: $0 [-v] [date flags]
This script calculates the date given the CoreOS major version or calculates
the version given a date.
Examples:
$0 -v 1000
Sun Mar 27 00:00:00 UTC 2016
$0 -v 1000 --iso-8601
2016-03-27
$0 --date 'Jun 1, 2016'
1066
"
case "$1" in
"-h")
echo "$USAGE"
;;
"-v")
shift
if [[ $# -ge 1 ]] && [[ "$1" != [-+]* ]]; then
v="$1"
@ -22,7 +44,10 @@ if [[ "$1" == "-v" ]]; then
export TZ=${TZ:=UTC}
date -d @$(( (v * 86400) + COREOS_EPOCH )) "$@"
else
;;
*)
t=$(date +%s "$@")
echo $(( (t - COREOS_EPOCH) / 86400 ))
fi
;;
esac