Skip to content

Commit 28e484f

Browse files
authored
Fix for grouping by date issues #5217 (#6134)
1 parent 801da7d commit 28e484f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Files/Extensions/DateTimeExtensions.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,25 @@ public static (string text, string range, string glyph, int index) GetFriendlyTi
6969
var today = DateTime.Today;
7070

7171
var diff = t - dt;
72-
if (t.Month == t2.Month && t.Day == t2.Day)
72+
var y = t.AddDays(-1);
73+
var w = t.AddDays(diff.Days*-1);
74+
75+
if (t.Month == t2.Month && t.Day == t2.Day && t.Year == t2.Year)
7376
{
7477
return ("ItemTimeText_Today".GetLocalized(), today.ToUserDateString(), "\ue184", 0);
7578
}
7679

77-
if (t.Month == t2.Month && t.Day - t2.Day < 2)
80+
if (y.Month == t2.Month && y.Day == t2.Day && y.Year == t2.Year)
7881
{
7982
return ("ItemTimeText_Yesterday".GetLocalized(), today.Subtract(TimeSpan.FromDays(1)).ToUserDateString(), "\ue161", 1);
8083
}
8184

82-
if (diff.Days <= 7 && t.GetWeekOfYear() == t2.GetWeekOfYear())
85+
if (diff.Days <= 7 && w.GetWeekOfYear() == t2.GetWeekOfYear() && w.Year == t2.Year)
8386
{
8487
return ("ItemTimeText_ThisWeek".GetLocalized(), t.Subtract(TimeSpan.FromDays((int)t.DayOfWeek)).ToUserDateString(), "\uE162", 2);
8588
}
8689

87-
if (diff.Days <= 14 && t.GetWeekOfYear() - 1 == t2.GetWeekOfYear())
90+
if (diff.Days <= 14 && w.GetWeekOfYear() == t2.GetWeekOfYear() && w.Year == t2.Year)
8891
{
8992
return ("ItemTimeText_LastWeek".GetLocalized(), t.Subtract(TimeSpan.FromDays((int)t.DayOfWeek + 7)).Date.ToShortDateString(), "\uE162", 3);
9093
}
@@ -94,7 +97,7 @@ public static (string text, string range, string glyph, int index) GetFriendlyTi
9497
return ("ItemTimeText_ThisMonth".GetLocalized(), t.Subtract(TimeSpan.FromDays(t.Day - 1)).ToUserDateString(), "\ue163", 4);
9598
}
9699

97-
if (t.Year == t2.Year && t.Month - 1 == t2.Month)
100+
if (t.AddMonths(-1).Year == t2.Year && t.AddMonths(-1).Month == t2.Month)
98101
{
99102
return ("ItemTimeText_LastMonth".GetLocalized(), t.Subtract(TimeSpan.FromDays(t.Day - 1 + calendar.GetDaysInMonth(t.Year, t.Month - 1))).ToUserDateString(), "\ue163", 5);
100103
}
@@ -136,4 +139,4 @@ public static string ToUserDateString(this DateTime t)
136139
return t.ToShortDateString();
137140
}
138141
}
139-
}
142+
}

0 commit comments

Comments
 (0)