mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 17:31:42 +08:00
225358982e
* feat:add AntComment * refactor(comment): change namespcae to AntDesign * docs: fix comment de
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Text;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public static class MomentHelper
|
|
{
|
|
private const int DaysPerYear = 365;
|
|
private const int DaysPerMonth = 31;
|
|
private const int DaysPerWeek = 7;
|
|
private const int HoursPerDay = 24;
|
|
|
|
public static string FromNow(DateTime time )
|
|
{
|
|
var timespan = DateTime.Now - time;
|
|
|
|
if (timespan.TotalDays >= DaysPerYear)
|
|
{
|
|
return $"{Math.Floor(timespan.TotalDays / DaysPerYear)} years ago";
|
|
}
|
|
if (timespan.TotalDays >= DaysPerMonth)
|
|
{
|
|
return $"{Math.Floor(timespan.TotalDays / DaysPerMonth)} months ago";
|
|
}
|
|
if (timespan.TotalDays >= DaysPerWeek)
|
|
{
|
|
return $"{Math.Floor(timespan.TotalDays / DaysPerWeek)} weeks ago";
|
|
}
|
|
if (timespan.TotalHours >= HoursPerDay)
|
|
{
|
|
return $"{Math.Floor(timespan.TotalDays)} days ago";
|
|
}
|
|
if (timespan.TotalHours >= 1)
|
|
{
|
|
return $"{Math.Floor(timespan.TotalHours)} hours ago";
|
|
}
|
|
if (timespan.TotalMinutes >= 1)
|
|
{
|
|
return $"{Math.Floor(timespan.TotalMinutes)} minutes ago";
|
|
}
|
|
return "a few seconds ago";
|
|
}
|
|
}
|
|
}
|