I have ran into this just last week. I wish TimeSpan
had a few more From
methods for bigger time periods like weeks months and years, but I made due with these:
/// <summary>
/// Number of minutes in an hour.
/// </summary>
private static readonly double minutesInHour = TimeSpan.FromHours(1).TotalMinutes;
/// <summary>
/// Number of hours in a day.
/// </summary>
private static readonly double hoursInDay = TimeSpan.FromDays(1).TotalHours;
/// <summary>
/// Number of hours in a week (7 days).
/// </summary>
private static readonly double hoursInWeek = 7.0D * hoursInDay;
/// <summary>
/// Number of hours in a month (30 days).
/// </summary>
private static readonly double hoursInMonth = 30.0D * hoursInDay;
The reason they're double
s are to do multiplication and division calculations later on with user input that could be in a different "base" unit.
MinutesPerMonth
is of course approxiamate, which may not be quite what you want. \$\endgroup\$