From 7720a868ba60a3200d3484faf41a421b1bcdf866 Mon Sep 17 00:00:00 2001 From: Engincan VESKE <43685404+EngincanV@users.noreply.github.com> Date: Thu, 22 Jun 2023 16:59:08 +0300 Subject: [PATCH] Refactoring #16941 --- .../Pages/Blogs/BloggingPageHelper.cs | 18 +++++++++--------- .../Pages/Blogs/Posts/Detail.cshtml | 6 +++--- .../Pages/Blogs/Posts/Index.cshtml | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs index a8929e0f63..10047fcb2b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageHelper.cs @@ -98,7 +98,7 @@ namespace Volo.Blogging.Pages.Blog .Build()); } - public LocalizedHtmlString ConvertDatetimeToTimeAgo(DateTime dt) + public LocalizedHtmlString GetLocalizedTimeAgoText(DateTime dt) { var timeDiff = DateTime.Now - dt; @@ -107,13 +107,13 @@ namespace Volo.Blogging.Pages.Blog switch (diffInDays) { case >= 365: - return GetLocalizedTimeAgoText("YearsAgo", "YearAgo", diffInDays / 365); + return GetLocalizedTextAsSingularOrPlural("YearsAgo", "YearAgo", diffInDays / 365); case >= 30: - return GetLocalizedTimeAgoText("MonthsAgo", "MonthAgo", diffInDays / 30); + return GetLocalizedTextAsSingularOrPlural("MonthsAgo", "MonthAgo", diffInDays / 30); case >= 7: - return GetLocalizedTimeAgoText("WeeksAgo", "WeekAgo", diffInDays / 7); + return GetLocalizedTextAsSingularOrPlural("WeeksAgo", "WeekAgo", diffInDays / 7); case >= 1: - return GetLocalizedTimeAgoText("DaysAgo", "DayAgo", diffInDays); + return GetLocalizedTextAsSingularOrPlural("DaysAgo", "DayAgo", diffInDays); } var diffInSeconds = (int) timeDiff.TotalSeconds; @@ -121,17 +121,17 @@ namespace Volo.Blogging.Pages.Blog switch (diffInSeconds) { case >= 3600: - return GetLocalizedTimeAgoText("HoursAgo", "HourAgo", diffInSeconds / 3600); + return GetLocalizedTextAsSingularOrPlural("HoursAgo", "HourAgo", diffInSeconds / 3600); case >= 60: - return GetLocalizedTimeAgoText("MinutesAgo", "MinuteAgo", diffInSeconds / 60); + return GetLocalizedTextAsSingularOrPlural("MinutesAgo", "MinuteAgo", diffInSeconds / 60); case >= 1: - return GetLocalizedTimeAgoText("SecondsAgo", "SecondAgo", diffInSeconds); + return GetLocalizedTextAsSingularOrPlural("SecondsAgo", "SecondAgo", diffInSeconds); default: return L["Now"]; } } - protected virtual LocalizedHtmlString GetLocalizedTimeAgoText(string pluralKey, string singularKey, int value) + protected virtual LocalizedHtmlString GetLocalizedTextAsSingularOrPlural(string pluralKey, string singularKey, int value) { return value != 1 ? L[pluralKey, value] : L[singularKey, value]; } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml index cc37c15c89..09ab99a121 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml @@ -79,7 +79,7 @@ @(Model.Post.Writer.UserName) - @BloggingPageHelper.ConvertDatetimeToTimeAgo(Model.Post.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(Model.Post.CreationTime) } @@ -262,7 +262,7 @@
@(commentWithRepliesDto.Comment.Writer == null ? "" : commentWithRepliesDto.Comment.Writer.UserName) - @BloggingPageHelper.ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(commentWithRepliesDto.Comment.CreationTime)

@commentWithRepliesDto.Comment.Text @@ -342,7 +342,7 @@

@(reply.Writer == null ? "" : reply.Writer.UserName) - @BloggingPageHelper.ConvertDatetimeToTimeAgo(reply.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(reply.CreationTime)

@reply.Text diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml index 236ac47008..b509c00fc4 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml @@ -69,7 +69,7 @@ @post.Writer.UserName - @BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime) @L["WiewsWithCount", post.ReadCount] @*| @@ -130,7 +130,7 @@ @post.Writer.UserName - @BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime) } @L["WiewsWithCount", post.ReadCount] @@ -199,7 +199,7 @@ @post.Writer.UserName - @BloggingPageHelper.ConvertDatetimeToTimeAgo(post.CreationTime) + @BloggingPageHelper.GetLocalizedTimeAgoText(post.CreationTime) @L["WiewsWithCount", post.ReadCount] @*|