-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDeltaTime
More file actions
executable file
·50 lines (48 loc) · 980 Bytes
/
getDeltaTime
File metadata and controls
executable file
·50 lines (48 loc) · 980 Bytes
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
#!/usr/bin/env bash
if [ "$1" = '--help' ]; then
exit 1
elif [ "$1" = '--version' ]; then
exit 1
fi
declare from=
declare result=''
declare format='%-s'
declare fTruncate='false'
while (($# > 0)); do
case "$1" in
-f | --from)
shift
declare -r from="$1"
;;
-t | --to)
shift
[ -n "$1" ] && declare -r result="$1"
;;
-s | --seconds)
declare -r format='%-s'
declare -r fTruncate='false'
;;
-m | --milliseconds)
declare -r format='%-s%0N'
declare -r fTruncate='true'
;;
-n | --nanoseconds)
declare -r format='%-s%0N'
declare -r fTruncate='false'
;;
# *) ;;
esac
shift
done
((eCode=0))
# set -e
if [ -z "$result" ]; then
result="$(date -u +"$format")"
((eCode=$?))
if eval "$fTruncate"; then result="${result:0:-6}"; fi
# declare -r result
fi
# if [ -n "$from" ]; then result="$(bc -l <<< "$result - $from")"; ((eCode=$?)); fi
if [ -n "$from" ]; then bc -l <<< "$result - $from"; exit; fi
echo -E "$result"
exit $eCode