summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
Diffstat (limited to 'Juick')
-rw-r--r--Juick/Classes/DateHelper.cs67
-rw-r--r--Juick/DataTemplates/PostItemDataTemplate.xaml4
-rw-r--r--Juick/Juick.csproj1
-rw-r--r--Juick/ViewModels/PostItem.cs9
4 files changed, 77 insertions, 4 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";
+ }
+ }
+}
diff --git a/Juick/DataTemplates/PostItemDataTemplate.xaml b/Juick/DataTemplates/PostItemDataTemplate.xaml
index 285a5dc..4668a48 100644
--- a/Juick/DataTemplates/PostItemDataTemplate.xaml
+++ b/Juick/DataTemplates/PostItemDataTemplate.xaml
@@ -1,7 +1,7 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:bindings="clr-namespace:Juick.Classes"
- xmlns:usercontrols="clr-namespace:Juick.Controls"
+ xmlns:usercontrols="clr-namespace:Juick.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<DataTemplate x:Key="PostItemDataTemplate">
@@ -36,7 +36,7 @@
Style="{StaticResource PhoneTextAccentStyle}"
FontSize="{StaticResource PhoneFontSizeSmall}"
Margin="5,0,5,5" VerticalAlignment="Top"
- TextWrapping="Wrap" HorizontalAlignment="Left"/>
+ TextWrapping="NoWrap" TextAlignment="Right"/>
</Grid>
</Border>
diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj
index 9d7c770..c3fe200 100644
--- a/Juick/Juick.csproj
+++ b/Juick/Juick.csproj
@@ -82,6 +82,7 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Classes\AccountManager.cs" />
+ <Compile Include="Classes\DateHelper.cs" />
<Compile Include="Classes\DelegateCommand.cs" />
<Compile Include="Classes\ExpressionHelper.cs" />
<Compile Include="Classes\InvokeDelegateCommandAction.cs" />
diff --git a/Juick/ViewModels/PostItem.cs b/Juick/ViewModels/PostItem.cs
index 97935b3..88f6b86 100644
--- a/Juick/ViewModels/PostItem.cs
+++ b/Juick/ViewModels/PostItem.cs
@@ -1,6 +1,8 @@
using System;
using System.Net;
using JuickApi;
+using Juick.Classes;
+using System.Globalization;
namespace Juick.ViewModels
{
@@ -11,8 +13,11 @@ namespace Juick.ViewModels
MID = message.Mid;
RID = message.Rid;
Username = message.User.UName;
- Status = string.Format("Posted on: {0}, replies: {1}", message.Timestamp, message.Replies);
-
+ // Juick timestamp in utc: 2013-04-22 13:14:30
+ var timestamp = DateTime.ParseExact(message.Timestamp, "yyyy-MM-dd HH:mm:ss", null);
+ Status = string.Format("{0}", DateHelper.PrettyDate(timestamp.ToLocalTime()));
+ if (message.Replies > 0)
+ Status = string.Format("{0}, replies: {1}", Status, message.Replies);
MessageText = HttpUtility.HtmlDecode(message.Body);
if (message.Tags != null)