🔥 Remove TimeSpan.Ago

Humanizer package fulfills this feature
This commit is contained in:
Oliver Booth 2019-12-16 17:54:19 +00:00
parent a699446112
commit 9844bccd28
No known key found for this signature in database
GPG Key ID: 0D7F2EF1C8D2B9C0
2 changed files with 0 additions and 56 deletions

View File

@ -24,4 +24,3 @@ Below is a list of the number of extension methods written for a given type. Ove
| `IList<T>` | `X10D` | 2 |
| `Random` | `X10D` | 2 |
| `string` / `SecureString` | `X10D` | 8 |
| `TimeSpan` | `X10D` | 1 |

View File

@ -1,55 +0,0 @@
namespace X10D
{
#region Using Directives
using System;
#endregion
/// <summary>
/// Extension methods for <see cref="TimeSpan"/>.
/// </summary>
public static class TimeSpanExtensions
{
/// <summary>
/// Calculates how long ago a specified <see cref="TimeSpan"/> was.
/// </summary>
/// <param name="span">The <see cref="TimeSpan"/>. Defaults to <see langword="false"/>.</param>
/// <returns>Returns a human-readable <see cref="String"/> describing how long ago <paramref name="span"/>
/// represents from now.</returns>
public static string Ago(this TimeSpan span)
{
if (span < TimeSpan.FromSeconds(60))
{
return $"{span.Seconds} seconds ago";
}
if (span < TimeSpan.FromMinutes(60))
{
return span.Minutes > 1 ? $"about {span.Minutes} minutes ago" : "about a minute ago";
}
if (span < TimeSpan.FromHours(24))
{
return span.Hours > 1 ? $"about {span.Hours} hours ago" : "about an hour ago";
}
if (span <= TimeSpan.FromDays(7))
{
return span.Days > 1 ? $"about {span.Days} days ago" : "yesterday";
}
if (span < TimeSpan.FromDays(30))
{
return $"about {span.Days} days ago";
}
if (span < TimeSpan.FromDays(365))
{
return span.Days > 30 ? $"about {span.Days} months ago" : "about a month ago";
}
return span.Days > 365 ? $"about {span.Days / 365} years ago" : "about a year ago";
}
}
}