-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[PT Run][Time and Date] Add friendly date/time result (#16809) #46803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -66,7 +66,7 @@ private DateTime GetDateTimeForTest(bool embedUtc = false) | |||||
| public void LocalFormatsWithShortTimeAndShortDate(string formatLabel, string expectedResult) | ||||||
| { | ||||||
| // Setup | ||||||
| var helperResults = AvailableResultsList.GetList(true, false, false, GetDateTimeForTest(), CalendarWeekRule.FirstDay, DayOfWeek.Sunday); | ||||||
| var helperResults = AvailableResultsList.GetList(true, false, false, GetDateTimeForTest(), now: null, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); | ||||||
|
|
||||||
| // Act | ||||||
| var result = helperResults.FirstOrDefault(x => x.Label.Equals(formatLabel, StringComparison.OrdinalIgnoreCase)); | ||||||
|
|
@@ -101,7 +101,7 @@ public void LocalFormatsWithShortTimeAndShortDate(string formatLabel, string exp | |||||
| public void LocalFormatsWithShortTimeAndLongDate(string formatLabel, string expectedResult) | ||||||
| { | ||||||
| // Setup | ||||||
| var helperResults = AvailableResultsList.GetList(true, false, true, GetDateTimeForTest(), CalendarWeekRule.FirstDay, DayOfWeek.Sunday); | ||||||
| var helperResults = AvailableResultsList.GetList(true, false, true, GetDateTimeForTest(), now: null, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); | ||||||
|
||||||
| var helperResults = AvailableResultsList.GetList(true, false, true, GetDateTimeForTest(), now: null, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); | |
| var helperResults = AvailableResultsList.GetList(true, false, true, GetDateTimeForTest(), now: null, firstWeekOfYear: CalendarWeekRule.FirstDay, firstDayOfWeek: DayOfWeek.Sunday); |
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
| var helperResults = AvailableResultsList.GetList(true, true, false, GetDateTimeForTest(), now: null, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); | |
| var helperResults = AvailableResultsList.GetList(true, true, false, GetDateTimeForTest(), now: null, firstWeekOfYear: CalendarWeekRule.FirstDay, firstDayOfWeek: DayOfWeek.Sunday); |
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
| var helperResults = AvailableResultsList.GetList(true, true, true, GetDateTimeForTest(), now: null, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); | |
| var helperResults = AvailableResultsList.GetList(true, true, true, GetDateTimeForTest(), now: null, firstWeekOfYear: CalendarWeekRule.FirstDay, firstDayOfWeek: DayOfWeek.Sunday); |
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same compile issue as above: positional arguments are used after the named now: argument. Name the remaining parameters (firstWeekOfYear:, firstDayOfWeek:) or keep all arguments positional.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -417,6 +417,72 @@ internal static DayOfWeek GetFirstDayOfWeek(int pluginSetting) | |
| return DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns a friendly human-readable representation of a timestamp relative to a reference "now". | ||
| /// Uses local date boundaries for Today / Yesterday / Tomorrow. | ||
| /// </summary> | ||
| internal static string GetFriendlyDateTime(DateTime target, DateTime referenceNow) | ||
| { | ||
| // Use local date boundaries. If the input carries UTC kind, convert for comparison/display purposes. | ||
| DateTime localTarget = target.Kind == DateTimeKind.Utc ? target.ToLocalTime() : target; | ||
| DateTime localNow = referenceNow.Kind == DateTimeKind.Utc ? referenceNow.ToLocalTime() : referenceNow; | ||
|
|
||
| int dayDiff = (localTarget.Date - localNow.Date).Days; | ||
| if (dayDiff == 0) | ||
| { | ||
| return Resources.Microsoft_plugin_timedate_Friendly_Today; | ||
| } | ||
|
|
||
| if (dayDiff == -1) | ||
| { | ||
| return Resources.Microsoft_plugin_timedate_Friendly_Yesterday; | ||
| } | ||
|
|
||
| if (dayDiff == 1) | ||
| { | ||
| return Resources.Microsoft_plugin_timedate_Friendly_Tomorrow; | ||
| } | ||
|
Comment on lines
+431
to
+445
|
||
|
|
||
| TimeSpan span = localTarget - localNow; | ||
| bool isFuture = span.Ticks > 0; | ||
| TimeSpan abs = span.Duration(); | ||
|
|
||
| if (abs.TotalSeconds < 10) | ||
| { | ||
| return Resources.Microsoft_plugin_timedate_Friendly_JustNow; | ||
| } | ||
|
|
||
| if (abs.TotalMinutes < 60) | ||
| { | ||
| int minutes = (int)Math.Round(abs.TotalMinutes, MidpointRounding.AwayFromZero); | ||
| if (minutes <= 1) | ||
| { | ||
| return isFuture ? Resources.Microsoft_plugin_timedate_Friendly_InMinute : Resources.Microsoft_plugin_timedate_Friendly_MinuteAgo; | ||
| } | ||
|
|
||
| return string.Format(CultureInfo.CurrentCulture, isFuture ? Resources.Microsoft_plugin_timedate_Friendly_InMinutes : Resources.Microsoft_plugin_timedate_Friendly_MinutesAgo, minutes); | ||
| } | ||
|
|
||
| if (abs.TotalHours < 24) | ||
| { | ||
| int hours = (int)Math.Round(abs.TotalHours, MidpointRounding.AwayFromZero); | ||
| if (hours <= 1) | ||
| { | ||
| return isFuture ? Resources.Microsoft_plugin_timedate_Friendly_InHour : Resources.Microsoft_plugin_timedate_Friendly_HourAgo; | ||
| } | ||
|
|
||
| return string.Format(CultureInfo.CurrentCulture, isFuture ? Resources.Microsoft_plugin_timedate_Friendly_InHours : Resources.Microsoft_plugin_timedate_Friendly_HoursAgo, hours); | ||
| } | ||
|
Comment on lines
+451
to
+476
|
||
|
|
||
| int days = (int)Math.Round(abs.TotalDays, MidpointRounding.AwayFromZero); | ||
| if (days <= 1) | ||
| { | ||
| return isFuture ? Resources.Microsoft_plugin_timedate_Friendly_InDay : Resources.Microsoft_plugin_timedate_Friendly_DayAgo; | ||
| } | ||
|
|
||
| return string.Format(CultureInfo.CurrentCulture, isFuture ? Resources.Microsoft_plugin_timedate_Friendly_InDays : Resources.Microsoft_plugin_timedate_Friendly_DaysAgo, days); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
GetList(...)calls use a named argument (now: null) followed by positional arguments (CalendarWeekRule.FirstDay,DayOfWeek.Sunday). C# doesn’t allow positional arguments after a named argument, so this won’t compile. Please name the remaining parameters as well (e.g.,firstWeekOfYear: ...,firstDayOfWeek: ...) or pass all parameters positionally.