Created
February 20, 2018 12:06
-
-
Save SecretDeveloper/7fe750fce0565a57ac09271cbffbcdec to your computer and use it in GitHub Desktop.
Uptime calculation for SLAs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Uptime calculation for SLAs. | |
Gary Kenneally | |
*/ | |
const double daysInYear = 365.2425; | |
const double monthsInYear = 12; | |
const double daysInMonth = daysInYear / monthsInYear; | |
const double second = 1; | |
const double secondsInMinute = second * 60; // :) | |
const double secondsInHour = secondsInMinute * 60; | |
const double secondsInDay = secondsInHour * 24; | |
const double secondsInWeek = secondsInDay * 7; | |
const double secondsInMonth = secondsInDay * daysInMonth; | |
const double secondsInYear = secondsInDay * daysInYear; | |
void Main() | |
{ | |
string per = "99.99"; | |
double perc = double.Parse(per); | |
perc = perc /100; | |
Console.WriteLine("Daily: " + LabelSecondsAsPeriods(secondsInDay - (secondsInDay * perc))); | |
Console.WriteLine("Weekly: " + LabelSecondsAsPeriods(secondsInWeek - (secondsInWeek * perc))); | |
Console.WriteLine("Monthly: " + LabelSecondsAsPeriods(secondsInMonth - (secondsInMonth * perc))); | |
Console.WriteLine("Yearly: " + LabelSecondsAsPeriods(secondsInYear - (secondsInYear * perc))); | |
} | |
string LabelSecondsAsPeriods(double seconds) | |
{ | |
TimeSpan ts = TimeSpan.FromSeconds(seconds); | |
return ts.Hours.ToString() + "h " + ts.Minutes + "m " + ts.Seconds + "s "+ ts.Milliseconds + "ms "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment