Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue 238 - Change DefaultDateTimeHumanizeStrategy to turn 60 min ... #278

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
###In Development
- [#257](https://github.com/Mehdik/Humanizer/pull/257): Added German localisation for ToOrdinalWords and Ordinalize
- [#261](https://github.com/Mehdik/Humanizer/pull/261): Added future dates to Portuguese - Brazil

- [#278](https://github.com/MehdiK/Humanizer/pull/278): Added "60 minutes" to "an hour ago" test cases for all locals

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.25.4...master)

###v1.25.1 - 2014-04-27
Expand Down
6 changes: 4 additions & 2 deletions src/Humanizer.Tests/DateHumanizeDefaultStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public void SecondsFromNow(int seconds, string expected)
[InlineData(1, "a minute ago")]
[InlineData(10, "10 minutes ago")]
[InlineData(44, "44 minutes ago")]
[InlineData(45, "an hour ago")]
[InlineData(45, "45 minutes ago")]
[InlineData(59, "59 minutes ago")]
[InlineData(60, "an hour ago")]
[InlineData(119, "an hour ago")]
[InlineData(120, "2 hours ago")]
public void MinutesAgo(int minutes, string expected)
Expand All @@ -47,7 +49,7 @@ public void MinutesAgo(int minutes, string expected)
[InlineData(1, "a minute from now")]
[InlineData(10, "10 minutes from now")]
[InlineData(44, "44 minutes from now")]
[InlineData(45, "an hour from now")]
[InlineData(45, "45 minutes from now")]
[InlineData(119, "an hour from now")]
[InlineData(120, "2 hours from now")]
public void MinutesFromNow(int minutes, string expected)
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/ar/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void HoursFromNow(int hours, string expected)
[InlineData(-1, "منذ دقيقة واحدة")]
[InlineData(-3, "منذ 3 دقائق")]
[InlineData(-11, "منذ 11 دقيقة")]
[InlineData(60, "منذ ساعة واحدة")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/bg/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "преди минута")]
[InlineData(2, "преди 2 минути")]
[InlineData(60, "преди час")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/cs/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void SecondsAgo(int seconds, string expected)
[InlineData(5, "před 5 minutami")]
[InlineData(6, "před 6 minutami")]
[InlineData(10, "před 10 minutami")]
[InlineData(60, "před hodinou")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
3 changes: 2 additions & 1 deletion src/Humanizer.Tests/Localisation/da/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void HoursFromNow(int hours, string expected)
[InlineData(-3, "3 minutter siden")]
[InlineData(-2, "2 minutter siden")]
[InlineData(-1, "et minut siden")]
[InlineData(60, "en time siden")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand All @@ -71,7 +72,7 @@ public void MinutesAgo(int minutes, string expected)
[InlineData(1, "et minut fra nu")]
[InlineData(10, "10 minutter fra nu")]
[InlineData(44, "44 minutter fra nu")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add 60 minutes for all languages please as that's currently missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool will do that today

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry MehdiK didn't get that. I have added the 60 minutes to the strategy it self hence it now works for all languages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Previously the logic was to return "an hour" for 45 minutes and we had test coverage for that in all locales. The code is now changed/fixed to return "one hour" for 60 minutes but we no longer have unit tests for that in any of the other locales. Just need to fix the tests to reflect the change. Thanks.

[InlineData(45, "en time fra nu")]
[InlineData(45, "45 minutter fra nu")]
[InlineData(119, "en time fra nu")]
[InlineData(120, "2 timer fra nu")]
public void MinutesFromNow(int minutes, string expected)
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/de/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void HoursFromNow(int hours, string expected)
[InlineData(-3, "vor 3 Minuten")]
[InlineData(-2, "vor 2 Minuten")]
[InlineData(-1, "vor einer Minute")]
[InlineData(60, "vor einer Stunde")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/es/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "hace un minuto")]
[InlineData(2, "hace 2 minutos")]
[InlineData(60, "hace una hora")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/fa/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void MinutesFromNow(int minutes, string expected)
[Theory]
[InlineData(-1, "یک دقیقه پیش")]
[InlineData(-13, "13 دقیقه پیش")]
[InlineData(60,"یک ساعت پیش")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void HoursAgo(int hours, string expected)
[InlineData(3, "3 minuuttia sitten")]
[InlineData(2, "2 minuuttia sitten")]
[InlineData(1, "minuutti sitten")]
[InlineData(60, "tunti sitten")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "il y a une minute")]
[InlineData(10, "il y a 10 minutes")]
[InlineData(60, "il y a une heure")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/fr/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "il y a une minute")]
[InlineData(10, "il y a 10 minutes")]
[InlineData(60, "il y a une heure")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/he/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void HoursAgo(int hours, string expected)
[InlineData(1, "לפני דקה")]
[InlineData(3, "לפני 3 דקות")]
[InlineData(11, "לפני 11 דקות")]
[InlineData(60, "לפני שעה")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/hu/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "egy perce")]
[InlineData(10, "10 perce")]
[InlineData(60, "egy órája")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/id/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "semenit yang lalu")]
[InlineData(10, "10 menit yang lalu")]
[InlineData(60, "sejam yang lalu")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/ja/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "1 分前")]
[InlineData(2, "2 分前")]
[InlineData(60, "1 時間前")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
3 changes: 2 additions & 1 deletion src/Humanizer.Tests/Localisation/nb-NO/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void HoursFromNow(int hours, string expected)
[InlineData(-3, "3 minutter siden")]
[InlineData(-2, "2 minutter siden")]
[InlineData(-1, "ett minutt siden")]
[InlineData(60, "en time siden")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand All @@ -74,7 +75,7 @@ public void MinutesAgo(int minutes, string expected)
[InlineData(1, "ett minutt fra nå")]
[InlineData(10, "10 minutter fra nå")]
[InlineData(44, "44 minutter fra nå")]
[InlineData(45, "en time fra nå")]
[InlineData(45, "45 minutter fra nå")]
[InlineData(119, "en time fra nå")]
[InlineData(120, "2 timer fra nå")]
public void MinutesFromNow(int minutes, string expected)
Expand Down
4 changes: 3 additions & 1 deletion src/Humanizer.Tests/Localisation/nl/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Humanizer.Localisation;
using Xunit;
using Xunit.Extensions;

Expand Down Expand Up @@ -33,9 +34,10 @@ public void HoursAgo(int hours, string expected)
[InlineData(-3, "3 minuten geleden")]
[InlineData(-2, "2 minuten geleden")]
[InlineData(-1, "één minuut geleden")]
[InlineData(60, "één uur geleden")]
public void MinutesAgo(int minutes, string expected)
{
Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize());
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
}

[Theory]
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/pl/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void SecondsAgo(int seconds, string expected)
[InlineData(5, "przed 5 minutami")]
[InlineData(6, "przed 6 minutami")]
[InlineData(10, "przed 10 minutami")]
[InlineData(60, "przed godziną")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(-2, "2 minutos atrás")]
[InlineData(-1, "um minuto atrás")]
[InlineData(60, "uma hora atrás")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
6 changes: 6 additions & 0 deletions src/Humanizer.Tests/Localisation/ro-Ro/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public void RomanianTranslationIsCorrectFor19MinutesAgo()
DateHumanize.Verify("acum 19 minute", 19, TimeUnit.Minute, Tense.Past);
}

[Fact]
public void RomanianTranslationIsCorrectFor60MinutesAgo()
{
DateHumanize.Verify("acum o oră", 60, TimeUnit.Minute, Tense.Past);
}

[Fact]
public void RomanianTranslationIsCorrectFor44MinutesAgo()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void SecondsFromNow(int seconds, string expected)
[InlineData(24, "24 минуты назад")]
[InlineData(25, "25 минут назад")]
[InlineData(40, "40 минут назад")]
[InlineData(60, "час назад")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/sk/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void SecondsAgo(int seconds, string expected)
[InlineData(5, "pred 5 minútami")]
[InlineData(6, "pred 6 minútami")]
[InlineData(10, "pred 10 minútami")]
[InlineData(60, "pred hodinou")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/sl/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void HoursFromNow(int hours, string expected)
[InlineData(-3, "pred 3 minutami")]
[InlineData(-2, "pred 2 minutama")]
[InlineData(-1, "pred eno minuto")]
[InlineData(60, "pred eno uro")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "pre minut")]
[InlineData(10, "pre 10 minuta")]
[InlineData(60, "pre sat vremena")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/sr/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "пре минут")]
[InlineData(10, "пре 10 минута")]
[InlineData(60, "пре сат времена")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/sv/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void SecondsAgo(int seconds, string expected)
[Theory]
[InlineData(1, "en minut sedan")]
[InlineData(2, "för 2 minuter sedan")]
[InlineData(60, "en timme sedan")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Localisation/tr/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void SecondsFromNow(int seconds, string expected)
[Theory]
[InlineData(1, "bir dakika önce")]
[InlineData(10, "10 dakika önce")]
[InlineData(60, "bir saat önce")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public string Humanize(DateTime input, DateTime comparisonBase)
if (ts.TotalMinutes < 45)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is not needed any more, as it also included in the next condition < 60.
We should remove it.

return Configurator.Formatter.DateHumanize(TimeUnit.Minute, tense, ts.Minutes);

if (ts.TotalMinutes < 60)
return Configurator.Formatter.DateHumanize(TimeUnit.Minute, tense, ts.Minutes);

if (ts.TotalMinutes < 90)
return Configurator.Formatter.DateHumanize(TimeUnit.Hour, tense, 1);

Expand Down
8 changes: 5 additions & 3 deletions src/Humanizer/FluentDate/On.Days.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;

using System;

namespace Humanizer
{
/// <summary>
/// </summary>
public class On
public partial class On
{

/// <summary>
/// Provides fluent date accessors for January
/// </summary>
Expand Down Expand Up @@ -3101,5 +3103,5 @@ public static DateTime The31st
get { return new DateTime(DateTime.Now.Year, 12, 31); }
}
}
}
}
}