summaryrefslogtreecommitdiff
path: root/Juick/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/Classes')
-rw-r--r--Juick/Classes/DateHelper.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/Juick/Classes/DateHelper.cs b/Juick/Classes/DateHelper.cs
new file mode 100644
index 0000000..072c56a
--- /dev/null
+++ b/Juick/Classes/DateHelper.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using System.Globalization;
+
+namespace Juick.Classes
+{
+ public class DateHelper
+ {
+ public static string PrettyDate(DateTime dateTime)
+ {
+ var timeSpan = DateTime.Now - dateTime;
+
+ // span is less than or equal to 60 seconds, measure in seconds.
+ if (timeSpan <= TimeSpan.FromSeconds(60))
+ {
+ return timeSpan.Seconds > 5
+ ? "about " + timeSpan.Seconds + " seconds ago"
+ : "just now";
+ }
+
+ // span is less than or equal to 60 minutes, measure in minutes.
+ if (timeSpan <= TimeSpan.FromMinutes(60))
+ {
+ return timeSpan.Minutes > 1
+ ? "about " + timeSpan.Minutes + " minutes ago"
+ : "about a minute ago";
+ }
+
+ // span is less than or equal to 24 hours, measure in hours.
+ if (timeSpan <= TimeSpan.FromHours(24))
+ {
+ return timeSpan.Hours > 1
+ ? "about " + timeSpan.Hours + " hours ago"
+ : "about an hour ago";
+ }
+
+ // span is less than or equal to 30 days (1 month), measure in days.
+ if (timeSpan <= TimeSpan.FromDays(30))
+ {
+ return timeSpan.Days > 1
+ ? "about " + timeSpan.Days + " days ago"
+ : "about a day ago";
+ }
+
+ // span is less than or equal to 365 days (1 year), measure in months.
+ if (timeSpan <= TimeSpan.FromDays(365))
+ {
+ return timeSpan.Days > 30
+ ? "about " + timeSpan.Days / 30 + " months ago"
+ : "about a month ago";
+ }
+
+ // span is greater than 365 days (1 year), measure in years.
+ return timeSpan.Days > 365
+ ? "about " + timeSpan.Days / 365 + " years ago"
+ : "about a year ago";
+ }
+ }
+}