From f15dd52fddaaa1aba9d8e24808330897060a3640 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 15 Jul 2024 17:20:55 +0800 Subject: [PATCH] code_style: use `?:` instead of `if...else` branches --- src/Models/Commit.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index f3980eec..055a2c22 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -40,10 +40,7 @@ namespace SourceGit.Models if (timespan.TotalHours > 1) return $"{(int)timespan.TotalHours} hours ago"; - if (timespan.TotalMinutes > 1) - return $"{(int)timespan.TotalMinutes} minutes ago"; - - return $"Just now"; + return timespan.TotalMinutes < 1 ? "Just now" : $"{(int)timespan.TotalMinutes} minutes ago"; } var diffYear = today.Year - committerTime.Year; @@ -54,16 +51,10 @@ namespace SourceGit.Models return diffMonth == 1 ? "Last month" : $"{diffMonth} months ago"; var diffDay = today.Day - committerTime.Day; - if (diffDay > 0) - return diffDay == 1 ? "Yesterday" : $"{diffDay} days ago"; - - return "Today"; + return diffDay == 1 ? "Yesterday" : $"{diffDay} days ago"; } - if (diffYear == 1) - return "Last year"; - - return $"{diffYear} years ago"; + return diffYear == 1 ? "Last year" : $"{diffYear} years ago"; } } }