blob: 4782df0afa36830a7678df08d89993162051943c (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#
# Only contains checking of time-intervals for
# shutdown-check called BLOCK_SHUTDOWN_INTERVALS
#
time2min() {
local t=${1}
if [ "$t" = "NOW" ]; then
t=$(date +%H:%M)
fi
# alles vor :
local h=${t%:*}
h=${h##0}
# alles nach :
local m=${t#*:}
m=${m##0}
# Wenn die Zeit kein ":" enthaelt
[ "$m" = "$t" ] && m=0
echo $(( ( $h*60 + $m ) % 1440 ))
}
#
# Checks a given time hh:mm against a list of intervals
# Interval: hh[:mm][-hh[:mm]]
# e.g. INTERVALS="2:00-3:47 8-23:9"
#
# bool check_interval (point, intervals)
check_interval() {
local testtime=$(time2min ${1})
local intervals="${2}"
local nr=0
local INSIDE=0
for i in $intervals; do
nr=$(($nr+1))
local HIT=0
case ${i} in
*-*)
local start=${i%-*}
local stop=${i#*-}
start=$(time2min $start)
stop=$(time2min $stop)
if [ "$start" -le "$stop" ]; then
# if (start <= testtime <= stop)
if [ "$start" -le "$testtime" ] && [ "$testtime" -le "$stop" ]; then
HIT=1
fi
else
# itervall ueber mitternacht
# if ( 0 <= testtime <= stop ) || ( start <= testtime <= midnight)
if [ "$testtime" -le "$stop" ] || [ "$start" -le "$testtime" ]; then
HIT=1
fi
fi
;;
*)
local point=$(time2min $i)
if [ "$start" -eq "$testtime" ]; then
HIT=1
fi
;;
esac
if [ "$HIT" = 1 ]; then
INSIDE=$(($INSIDE+1))
fi
done
if [ "$INSIDE" -gt 0 ]; then
return 0
else
return 1
fi
}
|