Browse Source

Blog module Added ConvertDatetimeToTimeAgo method

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
cc7f50e4e7
  1. 7
      modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/en.json
  2. 7
      modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json
  3. 44
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs

7
modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/en.json

@ -5,6 +5,13 @@
"Title": "Title",
"ContinueReading": "Continue Reading",
"DaysAgo": "days ago",
"YearsAgo": "years ago",
"MonthsAgo": "months ago",
"WeeksAgo": "weeks ago",
"MinutesAgo": "minutes ago",
"SecondsAgo": "seconds ago",
"HoursAgo": "hours ago",
"Now": "now",
"Content": "Content",
"SeeAll": "See All",
"PopularTags": "Popular Tags",

7
modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json

@ -5,6 +5,13 @@
"Title": "Başlık",
"ContinueReading": "Devamı...",
"DaysAgo": "Gün Önce",
"YearsAgo": "yıl önce",
"MonthsAgo": "ay önce",
"WeeksAgo": "hafta önce",
"MinutesAgo": "dakika önce",
"SecondsAgo": "saniye önce",
"HoursAgo": "saat önce",
"Now": "şimdi",
"Content": "İçerik",
"SeeAll": "Hepsini Gör",
"PopularTags": "Popüler Etiketler",

44
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.Localization;
using System;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.AspNetCore.Mvc.Razor.Internal;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Blogging.Localization;
@ -21,5 +22,46 @@ namespace Volo.Blogging.Pages.Blog
return title;
}
public string ConvertDatetimeToTimeAgo(DateTime dt)
{
var timeDiff = DateTime.Now - dt;
var diffInDays = (int) timeDiff.TotalDays;
if (diffInDays >= 365)
{
return diffInDays / 365 + L["YearsAgo"].Value;
}
if (diffInDays >= 30)
{
return diffInDays / 30 + L["MonthsAgo"].Value;
}
if (diffInDays >= 7)
{
return diffInDays / 7 + L["WeeksAgo"].Value;
}
if (diffInDays >= 1)
{
return diffInDays + L["DaysAgo"].Value;
}
var diffInSeconds = (int) timeDiff.TotalSeconds;
if (diffInSeconds >= 3600)
{
return diffInSeconds / 3600 + L["HoursAgo"].Value;
}
if (diffInSeconds >= 60)
{
return diffInSeconds / 60 + L["MinutesAgo"].Value;
}
if (diffInSeconds >= 1)
{
return diffInSeconds + L["SecondsAgo"].Value;
}
return L["Now"].Value;
}
}
}

Loading…
Cancel
Save