forked from aks/bash-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-time-utils.sh
executable file
·61 lines (50 loc) · 1.17 KB
/
test-time-utils.sh
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
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
# Copyright 2014-2022, Alan K. Stebbens <[email protected]>
#
# test time-utils.sh
#
# uses test-utils.sh
PATH=.:$PATH:$HOME/lib
source test-utils.sh
. time-utils.sh
testdata='test-times.dat'
# check_time TIMESTRING HH MM SS
check_time() {
time_parse "$1"
check_eq $hours $2
check_eq $mins $3
check_eq $secs $4
}
test_01_parse_time() {
start_test
check_time '00:00:00' 0 0 0
check_time '12:00:00' 12 0 0
check_time '12:01:02' 12 1 2
check_time '23:22:11' 23 22 11
check_time '23:59:59' 23 59 59
check_time '12:01' 12 01 00
end_test
}
# check_t2secs TIMESTRING SECS
check_t2secs() {
local secs=`time2secs "$1"`
check_eq $secs "$2"
}
test_10_time2secs() {
start_test
check_t2secs '00:00:01' 1
check_t2secs '00:00:59' 59
check_t2secs '00:01:00' 60
check_t2secs '00:01:59' 119
check_t2secs '00:11:22' 682 # 11*60+22
check_t2secs '00:59:59' 3599
check_t2secs '01:00:00' 3600
check_t2secs '01:02:03' 3723
check_t2secs '12:34:56' 45296
check_t2secs '23:59:59' 86399
end_test
}
init_tests "$@"
run_tests
summarize_tests
exit