From adb6d9d0804da2df0d7488fbd05249a6da576b00 Mon Sep 17 00:00:00 2001 From: Holmed Date: Fri, 2 May 2014 23:37:06 -0300 Subject: [PATCH 1/4] Added future dates to Resources.pt-BR.resx. New unit tests created in Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs --- .../Localisation/pt-BR/DateHumanizeTests.cs | 85 +++++++++++++++---- src/Humanizer/Properties/Resources.pt-BR.resx | 36 ++++++++ 2 files changed, 103 insertions(+), 18 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs index 172a3bd02..51fdb0c5d 100644 --- a/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs @@ -1,4 +1,5 @@ using System; +using Humanizer.Localisation; using Xunit; using Xunit.Extensions; @@ -9,23 +10,21 @@ public class DateHumanizeTests : AmbientCulture public DateHumanizeTests() : base("pt-BR") { } [Theory] - [InlineData(-10, "10 dias atrás")] - [InlineData(-3, "3 dias atrás")] - [InlineData(-2, "2 dias atrás")] - [InlineData(-1, "ontem")] - public void DaysAgo(int days, string expected) + [InlineData(-10, "10 segundos atrás")] + [InlineData(-3, "3 segundos atrás")] + [InlineData(-2, "2 segundos atrás")] + [InlineData(-1, "um segundo atrás")] + public void SecondsAgo(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); } [Theory] - [InlineData(-10, "10 horas atrás")] - [InlineData(-3, "3 horas atrás")] - [InlineData(-2, "2 horas atrás")] - [InlineData(-1, "uma hora atrás")] - public void HoursAgo(int hours, string expected) + [InlineData(1, "em um segundo")] + [InlineData(2, "em 2 segundos")] + public void SecondsFromNow(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future); } [Theory] @@ -38,6 +37,50 @@ public void MinutesAgo(int minutes, string expected) Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); } + [Theory] + [InlineData(1, "em um minuto")] + [InlineData(2, "em 2 minutos")] + public void MinutesFromNow(int minutes, string expected) + { + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future); + } + + [Theory] + [InlineData(-10, "10 horas atrás")] + [InlineData(-3, "3 horas atrás")] + [InlineData(-2, "2 horas atrás")] + [InlineData(-1, "uma hora atrás")] + public void HoursAgo(int hours, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + } + + [Theory] + [InlineData(1, "em uma hora")] + [InlineData(2, "em 2 horas")] + public void HoursFromNow(int hours, string expected) + { + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future); + } + + [Theory] + [InlineData(-10, "10 dias atrás")] + [InlineData(-3, "3 dias atrás")] + [InlineData(-2, "2 dias atrás")] + [InlineData(-1, "ontem")] + public void DaysAgo(int days, string expected) + { + Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + } + + [Theory] + [InlineData(1, "amanhã")] + [InlineData(2, "em 2 dias")] + public void DaysFromNow(int days, string expected) + { + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future); + } + [Theory] [InlineData(-10, "10 meses atrás")] [InlineData(-3, "3 meses atrás")] @@ -49,13 +92,11 @@ public void MonthsAgo(int months, string expected) } [Theory] - [InlineData(-10, "10 segundos atrás")] - [InlineData(-3, "3 segundos atrás")] - [InlineData(-2, "2 segundos atrás")] - [InlineData(-1, "um segundo atrás")] - public void SecondsAgo(int seconds, string expected) + [InlineData(1, "em um mês")] + [InlineData(2, "em 2 meses")] + public void MonthsFromNow(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future); } [Theory] @@ -67,5 +108,13 @@ public void YearsAgo(int years, string expected) { Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); } + + [Theory] + [InlineData(1, "em um ano")] + [InlineData(2, "em 2 anos")] + public void YearsFromNow(int years, string expected) + { + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); + } } } diff --git a/src/Humanizer/Properties/Resources.pt-BR.resx b/src/Humanizer/Properties/Resources.pt-BR.resx index e7d3f029e..0b6d55797 100644 --- a/src/Humanizer/Properties/Resources.pt-BR.resx +++ b/src/Humanizer/Properties/Resources.pt-BR.resx @@ -120,39 +120,75 @@ um segundo atrás + + em um segundo + {0} segundos atrás + + em {0} segundos + um minuto atrás + + em um minuto + {0} minutos atrás + + em {0} minutos + uma hora atrás + + em uma hora + {0} horas atrás + + em {0} horas + ontem + + amanhã + {0} dias atrás + + em {0} dias + um mês atrás + + em um mês + + + em {0} meses + {0} meses atrás um ano atrás + + em um ano + {0} anos atrás + + em {0} anos + {0} dias From e6a336d1a83dc659aeddccfd7b99a5fdaf9b9e42 Mon Sep 17 00:00:00 2001 From: Holmed Date: Sat, 3 May 2014 09:51:37 -0300 Subject: [PATCH 2/4] Changed past date tests in pt-BR/DateHumanizeTests.cs to use DateHumanize.Verify() instead of Assert.Equal. --- .../Localisation/pt-BR/DateHumanizeTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs index 51fdb0c5d..52af5eec9 100644 --- a/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs @@ -16,7 +16,7 @@ public DateHumanizeTests() : base("pt-BR") { } [InlineData(-1, "um segundo atrás")] public void SecondsAgo(int seconds, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddSeconds(seconds).Humanize()); + DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past); } [Theory] @@ -34,7 +34,7 @@ public void SecondsFromNow(int seconds, string expected) [InlineData(-1, "um minuto atrás")] public void MinutesAgo(int minutes, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMinutes(minutes).Humanize()); + DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past); } [Theory] @@ -52,7 +52,7 @@ public void MinutesFromNow(int minutes, string expected) [InlineData(-1, "uma hora atrás")] public void HoursAgo(int hours, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddHours(hours).Humanize()); + DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past); } [Theory] @@ -70,7 +70,7 @@ public void HoursFromNow(int hours, string expected) [InlineData(-1, "ontem")] public void DaysAgo(int days, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddDays(days).Humanize()); + DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past); } [Theory] @@ -88,7 +88,7 @@ public void DaysFromNow(int days, string expected) [InlineData(-1, "um mês atrás")] public void MonthsAgo(int months, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddMonths(months).Humanize()); + DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past); } [Theory] @@ -106,7 +106,7 @@ public void MonthsFromNow(int months, string expected) [InlineData(-1, "um ano atrás")] public void YearsAgo(int years, string expected) { - Assert.Equal(expected, DateTime.UtcNow.AddYears(years).Humanize()); + DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past); } [Theory] From 4418bcb674c1d3ef9803499ff9bf1882e0fc993d Mon Sep 17 00:00:00 2001 From: Holmed Date: Sat, 3 May 2014 09:52:38 -0300 Subject: [PATCH 3/4] Added "now" to Resources.pt-BR.resx. --- src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs | 6 ++++++ src/Humanizer/Properties/Resources.pt-BR.resx | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs b/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs index 52af5eec9..7c10bd9a6 100644 --- a/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs +++ b/src/Humanizer.Tests/Localisation/pt-BR/DateHumanizeTests.cs @@ -116,5 +116,11 @@ public void YearsFromNow(int years, string expected) { DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future); } + + [Fact] + public void Now() + { + DateHumanize.Verify("agora", 0, TimeUnit.Day, Tense.Future); + } } } diff --git a/src/Humanizer/Properties/Resources.pt-BR.resx b/src/Humanizer/Properties/Resources.pt-BR.resx index 0b6d55797..686f15f88 100644 --- a/src/Humanizer/Properties/Resources.pt-BR.resx +++ b/src/Humanizer/Properties/Resources.pt-BR.resx @@ -146,7 +146,7 @@ em uma hora - + {0} horas atrás @@ -228,4 +228,7 @@ 1 semana + + agora + \ No newline at end of file From 2916c554910f9c6826e0343de90fe43aa642c2dd Mon Sep 17 00:00:00 2001 From: Holmed Date: Sat, 3 May 2014 09:53:35 -0300 Subject: [PATCH 4/4] Moved field closer to the property where it is used in Configurator. --- src/Humanizer/Configuration/Configurator.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Humanizer/Configuration/Configurator.cs b/src/Humanizer/Configuration/Configurator.cs index 440fd9a2e..258d7ff91 100644 --- a/src/Humanizer/Configuration/Configurator.cs +++ b/src/Humanizer/Configuration/Configurator.cs @@ -36,9 +36,7 @@ public static LocaliserRegistry Ordinalizers { get { return _ordinalizers; } } - - private static IDateTimeHumanizeStrategy _dateTimeHumanizeStrategy = new DefaultDateTimeHumanizeStrategy(); - + /// /// The formatter to be used /// @@ -72,6 +70,7 @@ internal static IOrdinalizer Ordinalizer } } + private static IDateTimeHumanizeStrategy _dateTimeHumanizeStrategy = new DefaultDateTimeHumanizeStrategy(); /// /// The strategy to be used for DateTime.Humanize ///