Skip to content

Commit 46e946e

Browse files
committed
Make message timestamps better
1 parent e99e55c commit 46e946e

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

Signal-Windows/Controls/Message.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
<ItemsControl>
1919
<TextBlock Name="MessageAuthor" FontWeight="Bold" />
2020
<TextBlock Name="MessageContentTextBlock" TextWrapping="Wrap" MaxWidth="300" IsTextSelectionEnabled="True" FontSize="14" Foreground="Black" />
21-
<Grid Name="FooterPanel">
21+
<Grid Name="FooterPanel" MaxWidth="300">
2222
<Grid.ColumnDefinitions>
2323
<ColumnDefinition Width="Auto"/>
24-
<ColumnDefinition />
25-
<ColumnDefinition />
26-
<ColumnDefinition />
24+
<ColumnDefinition Width="*"/>
25+
<ColumnDefinition Width="Auto"/>
26+
<ColumnDefinition Width="Auto"/>
2727
</Grid.ColumnDefinitions>
2828
<TextBlock Grid.Column="0" Name="ResendTextBlock" Margin="0 0 5 0" Foreground="Red" FontWeight="SemiBold" Tapped="ResendTextBlock_Tapped" Visibility="Collapsed">Send again</TextBlock>
29-
<TextBlock Name="FancyTimestampBlock" Grid.Column="1" Margin="0 0 5 0" />
29+
<TextBlock Name="FancyTimestampBlock" Grid.Column="1" Margin="0 0 5 0" FontSize="12" />
3030
<Image Grid.Column="2" Name="CheckImage" Source="{StaticResource Check}" Width="16" Height="16" Visibility="Collapsed"/>
3131
<Image Grid.Column="3" Name="DoubleCheckImage" Source="{StaticResource DoubleCheck}" Width="16" Height="16" Visibility="Collapsed"/>
3232
</Grid>

Signal-Windows/Controls/Message.xaml.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,42 @@ private void UpdateUI()
9393
}
9494
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(Model.Message.ComposedTimestamp / 1000);
9595
DateTime dt = dateTimeOffset.UtcDateTime.ToLocalTime();
96-
FancyTimestampBlock.Text = dt.ToString();
96+
DateTime now = DateTimeOffset.Now.LocalDateTime;
97+
if (GetMidnightDateTime(now) - GetMidnightDateTime(dt) < TimeSpan.FromDays(7))
98+
{
99+
if (now.Day == dt.Day)
100+
{
101+
// on the same day
102+
FancyTimestampBlock.Text = dt.ToString("t");
103+
}
104+
else
105+
{
106+
// within the last week
107+
FancyTimestampBlock.Text = $"{dt.ToString("ddd")}, {dt.ToString("t")}";
108+
}
109+
110+
}
111+
else
112+
{
113+
if (now.Year == dt.Year)
114+
{
115+
// greater than one week and in the same year
116+
FancyTimestampBlock.Text = $"{dt.ToString("M")}, {dt.ToString("t")}";
117+
}
118+
else
119+
{
120+
// not in the same year
121+
FancyTimestampBlock.Text = dt.ToString("g");
122+
}
123+
}
97124
}
98125
}
99126

127+
private DateTime GetMidnightDateTime(DateTime dateTime)
128+
{
129+
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, dateTime.Kind);
130+
}
131+
100132
private void MessageBox_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
101133
{
102134
UpdateUI();

0 commit comments

Comments
 (0)