From 2842caf36ac0bfe55ef9b6811c0926c650cc395c Mon Sep 17 00:00:00 2001 From: aktheknight Date: Mon, 1 Apr 2019 16:05:59 +0100 Subject: [PATCH 1/3] Change strategy to add Weeks. Add Week property This also breaks lots of tests that are missing the property, not sure what we do --- .../DateTimeHumanizeAlgorithms.cs | 9 +++++++-- src/Humanizer/Properties/Resources.resx | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs index 1b25eea6e..4434eefff 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs @@ -150,11 +150,16 @@ public static string DefaultHumanize(DateTime input, DateTime comparisonBase, Cu return formatter.DateHumanize(TimeUnit.Day, tense, days); } - if (ts.TotalDays < 28) + if (ts.TotalDays < 7) { return formatter.DateHumanize(TimeUnit.Day, tense, ts.Days); } + if (ts.TotalDays < 28) + { + return formatter.DateHumanize(TimeUnit.Week, tense, ts.Days); + } + if (ts.TotalDays >= 28 && ts.TotalDays < 30) { if (comparisonBase.Date.AddMonths(tense == Tense.Future ? 1 : -1) == input.Date) @@ -180,4 +185,4 @@ public static string DefaultHumanize(DateTime input, DateTime comparisonBase, Cu return formatter.DateHumanize(TimeUnit.Year, tense, years); } } -} \ No newline at end of file +} diff --git a/src/Humanizer/Properties/Resources.resx b/src/Humanizer/Properties/Resources.resx index 678f0d5cf..0fdc70487 100644 --- a/src/Humanizer/Properties/Resources.resx +++ b/src/Humanizer/Properties/Resources.resx @@ -141,6 +141,9 @@ {0} days ago + + {0} weeks ago + one month ago From e68e8aab1c4e988264c1b17ceb2eef94f262fde8 Mon Sep 17 00:00:00 2001 From: Alex Knight Date: Thu, 20 Jun 2019 22:53:37 +0100 Subject: [PATCH 2/3] Add MultipleWeeksFromNow value --- src/Humanizer/Properties/Resources.resx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Humanizer/Properties/Resources.resx b/src/Humanizer/Properties/Resources.resx index 0fdc70487..ff1f80d5b 100644 --- a/src/Humanizer/Properties/Resources.resx +++ b/src/Humanizer/Properties/Resources.resx @@ -210,6 +210,9 @@ {0} seconds from now + + {0} weeks from now + {0} years from now From 019dedd9c820cf6732e4eff4f0b916afce66c42c Mon Sep 17 00:00:00 2001 From: Alex Knight Date: Thu, 20 Jun 2019 23:09:36 +0100 Subject: [PATCH 3/3] Fix English tests JUst 85 localized tests left --- .../DateHumanizeDefaultStrategyTests.cs | 8 ++++---- .../DateTimeHumanizeAlgorithms.cs | 2 +- src/Humanizer/Properties/Resources.resx | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Humanizer.Tests.Shared/DateHumanizeDefaultStrategyTests.cs b/src/Humanizer.Tests.Shared/DateHumanizeDefaultStrategyTests.cs index 9e850640e..3722c5105 100644 --- a/src/Humanizer.Tests.Shared/DateHumanizeDefaultStrategyTests.cs +++ b/src/Humanizer.Tests.Shared/DateHumanizeDefaultStrategyTests.cs @@ -88,8 +88,8 @@ public void HoursFromNowNotTomorrow(int hours, string expected) [Theory] [InlineData(1, "yesterday")] - [InlineData(10, "10 days ago")] - [InlineData(27, "27 days ago")] + [InlineData(10, "one week ago")] + [InlineData(27, "3 weeks ago")] [InlineData(32, "one month ago")] public void DaysAgo(int days, string expected) { @@ -98,8 +98,8 @@ public void DaysAgo(int days, string expected) [Theory] [InlineData(1, "tomorrow")] - [InlineData(10, "10 days from now")] - [InlineData(27, "27 days from now")] + [InlineData(10, "one week from now")] + [InlineData(27, "3 weeks from now")] [InlineData(32, "one month from now")] public void DaysFromNow(int days, string expected) { diff --git a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs index 4434eefff..25b525637 100644 --- a/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs +++ b/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs @@ -157,7 +157,7 @@ public static string DefaultHumanize(DateTime input, DateTime comparisonBase, Cu if (ts.TotalDays < 28) { - return formatter.DateHumanize(TimeUnit.Week, tense, ts.Days); + return formatter.DateHumanize(TimeUnit.Week, tense, ts.Days / 7); } if (ts.TotalDays >= 28 && ts.TotalDays < 30) diff --git a/src/Humanizer/Properties/Resources.resx b/src/Humanizer/Properties/Resources.resx index ff1f80d5b..9acdd3439 100644 --- a/src/Humanizer/Properties/Resources.resx +++ b/src/Humanizer/Properties/Resources.resx @@ -141,6 +141,9 @@ {0} days ago + + one week ago + {0} weeks ago @@ -234,6 +237,9 @@ one second from now + + one week from now + one year from now