-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimehelper.sh
42 lines (32 loc) · 917 Bytes
/
timehelper.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
#!/bin/ash
format_seconds() {
local seconds=$1
output=""
leftover_seconds=$((seconds % 60))
leftover_minutes=$(((seconds / 60) % 60))
leftover_hours=$(((seconds / 3600) % 24))
leftover_days=$(((seconds / 86400) % 7))
leftover_weeks=$(((seconds / 604800) % 4))
leftover_months=$((seconds / 2592000))
if [ "$leftover_months" != 0 ]; then
output="$output$leftover_months month, "
fi
if [ "$leftover_weeks" != 0 ]; then
output="$output$leftover_weeks week, "
fi
if [ "$leftover_days" != 0 ]; then
output="$output$leftover_days day, "
fi
if [ "$leftover_hours" != 0 ]; then
output="$output$leftover_hours hour, "
fi
if [ "$leftover_minutes" != 0 ]; then
output="$output$leftover_minutes min, "
fi
if [ "$leftover_seconds" != 0 ]; then
if [ "$output" == "" ]; then
output="$output$leftover_seconds sec"
fi
fi
echo "${output%, }"
}