Last active
July 6, 2018 12:53
-
-
Save ramonsmits/5594942 to your computer and use it in GitHub Desktop.
Some simple TimeSpan extension methods that add approximations for total weeks, months and years in a timespan.
This file contains hidden or 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
| using System; | |
| public static class TimeSpanExtensions | |
| { | |
| const double DaysInWeek = 7d; | |
| const double DaysInMonth = 365d / 12d; | |
| const double DaysInYear = 365d; | |
| public static double TotalWeeks(this TimeSpan val) | |
| { | |
| return val.TotalDays / DaysInWeek; | |
| } | |
| public static double TotalMonths(this TimeSpan val) | |
| { | |
| return val.TotalDays / DaysInMonth; | |
| } | |
| public static double TotalYears(this TimeSpan val) | |
| { | |
| return val.TotalDays / DaysInYear; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment