From 9844bccd28d93c8d17a15fa879eb3ac589d084f0 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 16 Dec 2019 17:54:19 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20TimeSpan.Ago?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Humanizer package fulfills this feature --- X10D/README.md | 1 - X10D/TimeSpanExtensions.cs | 55 -------------------------------------- 2 files changed, 56 deletions(-) delete mode 100644 X10D/TimeSpanExtensions.cs diff --git a/X10D/README.md b/X10D/README.md index 20ff9b0..991d92c 100644 --- a/X10D/README.md +++ b/X10D/README.md @@ -24,4 +24,3 @@ Below is a list of the number of extension methods written for a given type. Ove | `IList` | `X10D` | 2 | | `Random` | `X10D` | 2 | | `string` / `SecureString` | `X10D` | 8 | -| `TimeSpan` | `X10D` | 1 | diff --git a/X10D/TimeSpanExtensions.cs b/X10D/TimeSpanExtensions.cs deleted file mode 100644 index d9bc39a..0000000 --- a/X10D/TimeSpanExtensions.cs +++ /dev/null @@ -1,55 +0,0 @@ -namespace X10D -{ - #region Using Directives - - using System; - - #endregion - - /// - /// Extension methods for . - /// - public static class TimeSpanExtensions - { - /// - /// Calculates how long ago a specified was. - /// - /// The . Defaults to . - /// Returns a human-readable describing how long ago - /// represents from now. - 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"; - } - } -}