-
Notifications
You must be signed in to change notification settings - Fork 50
/
core_date
executable file
·53 lines (40 loc) · 1.02 KB
/
core_date
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Copyright (c) 2016 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/common.sh" || exit 1
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"
shift
else
v="${FLATCAR_VERSION}"
fi
# strip of a v prefix or .0.0 suffix
v="${v#v}"
v="${v%%.*}"
export TZ=${TZ:=UTC}
date -d @$(( (v * 86400) + COREOS_EPOCH )) "$@"
;;
*)
t=$(date +%s "$@")
echo $(( (t - COREOS_EPOCH) / 86400 ))
;;
esac