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) }