Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d616d08

Browse files
refactor: relative time display mode (#777)
1 parent 4392893 commit d616d08

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

‎src/Views/Histories.axaml.cs‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -430,31 +430,43 @@ private string GetDisplayText()
430430
if (ShowAsDateTime)
431431
return DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
432432

433-
var today = DateTime.Today;
433+
var now = DateTime.Now;
434434
var localTime = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime();
435+
var span = now - localTime;
436+
if (span.TotalMinutes < 1)
437+
return App.Text("Period.JustNow");
435438

436-
if (localTime >= today)
437-
{
438-
var now = DateTime.Now;
439-
var timespan = now - localTime;
440-
if (timespan.TotalHours > 1)
441-
return App.Text("Period.HoursAgo", (int)timespan.TotalHours);
439+
if (span.TotalHours < 1)
440+
return App.Text("Period.MinutesAgo", (int)span.TotalMinutes);
442441

443-
returntimespan.TotalMinutes < 1?App.Text("Period.JustNow"):App.Text("Period.MinutesAgo",(int)timespan.TotalMinutes);
444-
}
442+
if(span.TotalDays < 1)
443+
returnApp.Text("Period.HoursAgo",(int)span.TotalHours);
445444

446-
var diffYear = today.Year - localTime.Year;
447-
if (diffYear == 0)
445+
var lastDay = now.AddDays(-1).Date;
446+
if (localTime >= lastDay)
447+
return App.Text("Period.Yesterday");
448+
449+
if ((localTime.Year == now.Year && localTime.Month == now.Month) || span.TotalDays < 28)
448450
{
449-
var diffMonth = today.Month - localTime.Month;
450-
if(diffMonth>0)
451-
returndiffMonth==1?App.Text("Period.LastMonth"):App.Text("Period.MonthsAgo",diffMonth);
451+
var diffDay = now.Date - localTime.Date;
452+
returnApp.Text("Period.DaysAgo",(int)diffDay.TotalDays);
453+
}
452454

453-
var diffDay = today.Day - localTime.Day;
454-
return diffDay == 1 ? App.Text("Period.Yesterday") : App.Text("Period.DaysAgo", diffDay);
455+
var lastMonth = now.AddMonths(-1).Date;
456+
if (localTime.Year == lastMonth.Year && localTime.Month == lastMonth.Month)
457+
return App.Text("Period.LastMonth");
458+
459+
if (localTime.Year == now.Year || localTime > now.AddMonths(-11))
460+
{
461+
var diffMonth = (12 + now.Month - localTime.Month) % 12;
462+
return App.Text("Period.MonthsAgo", diffMonth);
455463
}
456464

457-
return diffYear == 1 ? App.Text("Period.LastYear") : App.Text("Period.YearsAgo", diffYear);
465+
var diffYear = now.Year - localTime.Year;
466+
if (diffYear == 1)
467+
return App.Text("Period.LastYear");
468+
469+
return App.Text("Period.YearsAgo", diffYear);
458470
}
459471

460472
private IDisposable _refreshTimer = null;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /