Created
March 25, 2010 19:25
-
-
Save lucasmazza/344002 to your computer and use it in GitHub Desktop.
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
| // C# version of :http://gist.github.com/59087 as an Extension method | |
| public static String InWords(this DateTime from) | |
| { | |
| double minutes = Math.Floor((DateTime.Now - from).TotalSeconds / 60); | |
| if (minutes == 0) { return "less than a minute ago"; } | |
| if (minutes == 1) { return "a minute ago"; } | |
| if (minutes < 45) { return minutes + " minutes ago"; } | |
| if (minutes < 90) { return "about 1 hour ago"; } | |
| if (minutes < 1440) { return "about " + Math.Floor(minutes / 60) + " hours ago"; } | |
| if (minutes < 2880) { return "1 day ago"; } | |
| if (minutes < 43200) { return Math.Floor(minutes / 1440) + " days ago"; } | |
| if (minutes < 86400) { return "about 1 month ago"; } | |
| if (minutes < 525960) { return Math.Floor(minutes / 43200) + " months ago"; } | |
| if (minutes < 1051199) { return "about 1 year ago"; } | |
| return "over " + Math.Floor(minutes / 525960) + " years ago"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment