diff options
Diffstat (limited to '')
-rw-r--r-- | cmd/slocalc/README.md | 20 | ||||
-rw-r--r-- | cmd/slocalc/main.go | 51 |
2 files changed, 0 insertions, 71 deletions
diff --git a/cmd/slocalc/README.md b/cmd/slocalc/README.md deleted file mode 100644 index 660b653..0000000 --- a/cmd/slocalc/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# slocalc - -A simple SLO calculator for the command line. - -## Usage - -```bash -slocalc <availability> -``` - -## Example - -```bash -% slocalc 99.9 -daily : 0 days, 0 hours, 0 minutes, 4 seconds -weekly : 0 days, 0 hours, 0 minutes, 30 seconds -monthly : 0 days, 0 hours, 2 minutes, 9 seconds -quarterly: 0 days, 0 hours, 6 minutes, 28 seconds -yearly : 0 days, 0 hours, 26 minutes, 16 seconds -``` diff --git a/cmd/slocalc/main.go b/cmd/slocalc/main.go deleted file mode 100644 index ae4998b..0000000 --- a/cmd/slocalc/main.go +++ /dev/null @@ -1,51 +0,0 @@ -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) -} |