forked from jdpedersen1/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.sh
executable file
·54 lines (47 loc) · 1.11 KB
/
clock.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
#!/usr/bin/bash
hours=("zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve")
hour=$(date +'%I')
minute=$(date +'%M')
# strips leading zero to prevent octal number assumption
hour=$(( "10#$hour" ))
minute=$(( "10#$minute" ))
# if the hour is more than half done, we make reference to the next hour, set adverb to "to" and subract 30 from minutes
if (( minute >= 33 ))
then
if (( hour == 12 ))
then
hour=1
else
hour=$(( hour + 1 ))
fi
minute=$(( 60 - minute ))
adverb="to"
else
adverb="past"
fi
hour_as_text=${hours[$hour]}
if (( minute < 3 ))
then
time_as_text="$hour_as_text o'clock"
elif (( minute < 8 ))
then
time_as_text="five $adverb $hour_as_text"
elif (( minute < 13 ))
then
time_as_text="ten $adverb $hour_as_text"
elif (( minute < 18 ))
then
time_as_text="quarter $adverb $hour_as_text"
elif (( minute < 23 ))
then
time_as_text="twenty $adverb $hour_as_text"
elif (( minute < 28 ))
then
time_as_text="twenty-five $adverb $hour_as_text"
elif (( minute < 33 ))
then
time_as_text="half past $hour_as_text"
else
exit 1
fi
echo "$time_as_text"