diff options
Diffstat (limited to '')
-rw-r--r-- | cmd/slocalc/main.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cmd/slocalc/main.go b/cmd/slocalc/main.go new file mode 100644 index 0000000..ae4998b --- /dev/null +++ b/cmd/slocalc/main.go @@ -0,0 +1,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) +} |