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
|
package main
import (
"fmt"
"os"
"strconv"
)
const (
secondsPerHour = 3600
)
func main() {
if len(os.Args) <= 1 {
fmt.Println("Please provide a value")
os.Exit(1)
}
uptime, _ := strconv.ParseFloat(os.Args[1], 64)
switch {
case uptime <= 0:
uptime = 0
case uptime >= 100:
uptime = 100
}
allowedDowntime := (((100 * 100) - (uptime * 100)) / (100 * 100))
dailySeconds := secondsPerHour * 24 * allowedDowntime
weekSeconds := dailySeconds * 7
monthSeconds := dailySeconds * 30
quarterSeconds := dailySeconds * 90
yearSeconds := dailySeconds * 365
fmt.Printf("daily : %s\n", secondsToHumanTime(int(dailySeconds)))
fmt.Printf("weekly : %s\n", secondsToHumanTime(int(weekSeconds)))
fmt.Printf("monthly : %s\n", secondsToHumanTime(int(monthSeconds)))
fmt.Printf("quarterly: %s\n", secondsToHumanTime(int(quarterSeconds)))
fmt.Printf("yearly : %s\n", secondsToHumanTime(int(yearSeconds)))
}
// secondsToHumanTime converts seconds to human readable time
func secondsToHumanTime(seconds int) string {
days := seconds / 86400
seconds = seconds % 86400
hours := seconds / 3600
seconds = seconds % 3600
minutes := seconds / 60
seconds = seconds % 60
return fmt.Sprintf("%d days, %d hours, %d minutes, %d seconds", days, hours, minutes, seconds)
}
|