diff --git a/readme.md b/readme.md index 40304c308..0997a9e45 100644 --- a/readme.md +++ b/readme.md @@ -426,6 +426,11 @@ In addition, a maximum unit of time may be specified to avoid rolling up to the TimeSpan.FromDays(7).Humanize(maxUnit: TimeUnit.Day) => "7 days" // instead of 1 week TimeSpan.FromMilliseconds(2000).Humanize(maxUnit: TimeUnit.Millisecond) => "2000 milliseconds" // instead of 2 seconds ``` +The default maxUnit is `TimeUnit.Week` because it gives exact results. You can increase this value to `TimeUnit.Month` or `TimeUnit.Year` which will give you an approximation based on 365.2425 days a year and 30.436875 days a month. Therefore the months are alternating between 30 and 31 days in length and every fourth year is 366 days long. +```C# +TimeSpan.FromDays(486).Humanize(maxUnit: TimeUnit.Year, precision: 7) => "1 year, 3 months, 29 days" // One day further is 1 year, 4 month +TimeSpan.FromDays(517).Humanize(maxUnit: TimeUnit.Year, precision: 7) => "1 year, 4 months, 30 days" // This month has 30 days and one day further is 1 year, 5 months +``` When there are multiple time units, they are combined using the `", "` string: diff --git a/src/Humanizer.Tests.Shared/Localisation/DefaultFormatterTests.cs b/src/Humanizer.Tests.Shared/Localisation/DefaultFormatterTests.cs index 23a0ca6c6..daa38f51c 100644 --- a/src/Humanizer.Tests.Shared/Localisation/DefaultFormatterTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/DefaultFormatterTests.cs @@ -8,17 +8,6 @@ namespace Humanizer.Tests.Localisation { public class DefaultFormatterTests { - [Theory] - [InlineData(TimeUnit.Month, 1)] - [InlineData(TimeUnit.Month, 2)] - [InlineData(TimeUnit.Month, 10)] - [InlineData(TimeUnit.Year, 1)] - [InlineData(TimeUnit.Year, 2)] - [InlineData(TimeUnit.Year, 10)] - public void TimeSpanHumanizeThrowsExceptionForTimeUnitsLargerThanWeek(TimeUnit timeUnit, int unit) - { - Assert.Throws(() => new DefaultFormatter(CultureInfo.InvariantCulture.Name).TimeSpanHumanize(timeUnit, unit)); - } [Fact] [UseCulture("es")] diff --git a/src/Humanizer.Tests.Shared/Localisation/af/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/af/TimeSpanHumanizeTests.cs index 92e147736..fbda08ef7 100644 --- a/src/Humanizer.Tests.Shared/Localisation/af/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/af/TimeSpanHumanizeTests.cs @@ -7,6 +7,28 @@ namespace Humanizer.Tests.Localisation.af public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 jaar")] + [InlineData(731, "2 jaar")] + [InlineData(1096, "3 jaar")] + [InlineData(4018, "11 jaar")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 maand")] + [InlineData(61, "2 maande")] + [InlineData(92, "3 maande")] + [InlineData(335, "11 maande")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Fact] public void TwoWeeks() { diff --git a/src/Humanizer.Tests.Shared/Localisation/ar/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/ar/TimeSpanHumanizeTests.cs index 52b23bb2e..cffa58d52 100644 --- a/src/Humanizer.Tests.Shared/Localisation/ar/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/ar/TimeSpanHumanizeTests.cs @@ -6,6 +6,28 @@ namespace Humanizer.Tests.Localisation.ar [UseCulture("ar")] public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "السنة 1")] + [InlineData(731, "سنتين")] + [InlineData(1096, "3 سنة")] + [InlineData(4018, "11 سنة")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "شهر 1")] + [InlineData(61, "شهرين")] + [InlineData(92, "3 أشهر")] + [InlineData(335, "11 أشهر")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "أسبوع واحد")] [InlineData(14, "أسبوعين")] diff --git a/src/Humanizer.Tests.Shared/Localisation/bg/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/bg/TimeSpanHumanizeTests.cs index 130b4952c..feb0d80ea 100644 --- a/src/Humanizer.Tests.Shared/Localisation/bg/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/bg/TimeSpanHumanizeTests.cs @@ -6,6 +6,28 @@ namespace Humanizer.Tests.Localisation.bg [UseCulture("bg-BG")] public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "една година")] + [InlineData(731, "2 години")] + [InlineData(1096, "3 години")] + [InlineData(4018, "11 години")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "един месец")] + [InlineData(61, "2 месеца")] + [InlineData(92, "3 месеца")] + [InlineData(335, "11 месеца")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "една седмица")] [InlineData(14, "2 седмици")] diff --git a/src/Humanizer.Tests.Shared/Localisation/bn-BD/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/bn-BD/TimeSpanHumanizeTests.cs index dbf42307b..ef459ffd8 100644 --- a/src/Humanizer.Tests.Shared/Localisation/bn-BD/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/bn-BD/TimeSpanHumanizeTests.cs @@ -6,6 +6,29 @@ namespace Humanizer.Tests.Localisation.bnBD [UseCulture("bn-BD")] public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "এক বছর")] + [InlineData(731, "2 বছর")] + [InlineData(1096, "3 বছর")] + [InlineData(4018, "11 বছর")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "এক মাসের")] + [InlineData(61, "2 মাস")] + [InlineData(92, "3 মাস")] + [InlineData(335, "11 মাস")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "এক সপ্তাহ")] [InlineData(14, "2 সপ্তাহ")] diff --git a/src/Humanizer.Tests.Shared/Localisation/cs/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/cs/TimeSpanHumanizeTests.cs index d773116c7..53e54a87e 100644 --- a/src/Humanizer.Tests.Shared/Localisation/cs/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/cs/TimeSpanHumanizeTests.cs @@ -7,6 +7,28 @@ namespace Humanizer.Tests.Localisation.cs public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 rok")] + [InlineData(731, "2 roky")] + [InlineData(1096, "3 roky")] + [InlineData(4018, "11 let")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 měsíc")] + [InlineData(61, "2 měsíce")] + [InlineData(92, "3 měsíce")] + [InlineData(335, "11 měsíců")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(1, "1 milisekunda")] [InlineData(2, "2 milisekundy")] @@ -80,7 +102,7 @@ public void Days(int number, string expected) [InlineData(6, "6 týdnů")] public void Weeks(int number, string expected) { - Assert.Equal(expected, TimeSpan.FromDays(number*7).Humanize()); + Assert.Equal(expected, TimeSpan.FromDays(number * 7).Humanize()); } } } diff --git a/src/Humanizer.Tests.Shared/Localisation/da/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/da/TimeSpanHumanizeTests.cs index 3fc6512af..2ea633eda 100644 --- a/src/Humanizer.Tests.Shared/Localisation/da/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/da/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.da { [UseCulture("da-DK")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "et år")] + [InlineData(731, "2 år")] + [InlineData(1096, "3 år")] + [InlineData(4018, "11 år")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "en måned")] + [InlineData(61, "2 måneder")] + [InlineData(92, "3 måneder")] + [InlineData(335, "11 måneder")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "en uge")] [InlineData(14, "2 uger")] diff --git a/src/Humanizer.Tests.Shared/Localisation/de/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/de/TimeSpanHumanizeTests.cs index ba5d2ed70..588fc2998 100644 --- a/src/Humanizer.Tests.Shared/Localisation/de/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/de/TimeSpanHumanizeTests.cs @@ -3,8 +3,31 @@ namespace Humanizer.Tests.Localisation.de { [UseCulture("de-DE")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "Ein Jahr")] + [InlineData(731, "2 Jahre")] + [InlineData(1096, "3 Jahre")] + [InlineData(4018, "11 Jahre")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "Ein Monat")] + [InlineData(61, "2 Monate")] + [InlineData(92, "3 Monate")] + [InlineData(335, "11 Monate")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "Eine Woche")] [InlineData(14, "2 Wochen")] diff --git a/src/Humanizer.Tests.Shared/Localisation/es/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/es/TimeSpanHumanizeTests.cs index 758496b80..e327a6df6 100644 --- a/src/Humanizer.Tests.Shared/Localisation/es/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/es/TimeSpanHumanizeTests.cs @@ -6,6 +6,27 @@ namespace Humanizer.Tests.Localisation.es [UseCulture("es-ES")] public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "un año")] + [InlineData(731, "2 años")] + [InlineData(1096, "3 años")] + [InlineData(4018, "11 años")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "un mes")] + [InlineData(61, "2 meses")] + [InlineData(92, "3 meses")] + [InlineData(335, "11 meses")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } [Fact] public void TwoWeeks() diff --git a/src/Humanizer.Tests.Shared/Localisation/fa/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/fa/TimeSpanHumanizeTests.cs index cd8e74414..c8362926b 100644 --- a/src/Humanizer.Tests.Shared/Localisation/fa/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/fa/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.fa { [UseCulture("fa")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "یک سال")] + [InlineData(731, "2 سال")] + [InlineData(1096, "3 سال")] + [InlineData(4018, "11 سال")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "یک ماه")] + [InlineData(61, "2 ماه")] + [InlineData(92, "3 ماه")] + [InlineData(335, "11 ماه")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "یک هفته")] [InlineData(77, "11 هفته")] diff --git a/src/Humanizer.Tests.Shared/Localisation/fr-BE/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/fr-BE/TimeSpanHumanizeTests.cs index e34574458..b4925a08f 100644 --- a/src/Humanizer.Tests.Shared/Localisation/fr-BE/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/fr-BE/TimeSpanHumanizeTests.cs @@ -4,12 +4,35 @@ namespace Humanizer.Tests.Localisation.frBE { [UseCulture("fr-BE")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 année")] + [InlineData(731, "2 ans")] + [InlineData(1096, "3 ans")] + [InlineData(4018, "11 ans")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mois")] + [InlineData(61, "2 mois")] + [InlineData(92, "3 mois")] + [InlineData(335, "11 mois")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(14, "2 semaines")] [InlineData(7, "1 semaine")] - public void Weeks(int days, string expected) + public void Weeks(int days, string expected) { var actual = TimeSpan.FromDays(days).Humanize(); Assert.Equal(expected, actual); @@ -18,7 +41,7 @@ public void Weeks(int days, string expected) [Theory] [InlineData(6, "6 jours")] [InlineData(1, "1 jour")] - public void Days(int days, string expected) + public void Days(int days, string expected) { var actual = TimeSpan.FromDays(days).Humanize(); Assert.Equal(expected, actual); @@ -27,7 +50,7 @@ public void Days(int days, string expected) [Theory] [InlineData(2, "2 heures")] [InlineData(1, "1 heure")] - public void Hours(int hours, string expected) + public void Hours(int hours, string expected) { var actual = TimeSpan.FromHours(hours).Humanize(); Assert.Equal(expected, actual); @@ -36,7 +59,7 @@ public void Hours(int hours, string expected) [Theory] [InlineData(2, "2 minutes")] [InlineData(1, "1 minute")] - public void Minutes(int minutes, string expected) + public void Minutes(int minutes, string expected) { var actual = TimeSpan.FromMinutes(minutes).Humanize(); Assert.Equal(expected, actual); @@ -45,7 +68,7 @@ public void Minutes(int minutes, string expected) [Theory] [InlineData(2, "2 secondes")] [InlineData(1, "1 seconde")] - public void Seconds(int seconds, string expected) + public void Seconds(int seconds, string expected) { var actual = TimeSpan.FromSeconds(seconds).Humanize(); Assert.Equal(expected, actual); @@ -54,14 +77,14 @@ public void Seconds(int seconds, string expected) [Theory] [InlineData(2, "2 millisecondes")] [InlineData(1, "1 milliseconde")] - public void Milliseconds(int ms, string expected) + public void Milliseconds(int ms, string expected) { var actual = TimeSpan.FromMilliseconds(ms).Humanize(); Assert.Equal(expected, actual); } [Fact] - public void NoTime() + public void NoTime() { var noTime = TimeSpan.Zero; var actual = noTime.Humanize(); diff --git a/src/Humanizer.Tests.Shared/Localisation/fr/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/fr/TimeSpanHumanizeTests.cs index 12c2514f4..dfda48ad0 100644 --- a/src/Humanizer.Tests.Shared/Localisation/fr/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/fr/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.fr { [UseCulture("fr")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [InlineData(366, "1 année")] + [InlineData(731, "2 ans")] + [InlineData(1096, "3 ans")] + [InlineData(4018, "11 ans")] + [Theory] + [Trait("Translation", "Google")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mois")] + [InlineData(61, "2 mois")] + [InlineData(92, "3 mois")] + [InlineData(335, "11 mois")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(14, "2 semaines")] [InlineData(7, "1 semaine")] diff --git a/src/Humanizer.Tests.Shared/Localisation/he/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/he/TimeSpanHumanizeTests.cs index 21dfcf1a9..f1750fef2 100644 --- a/src/Humanizer.Tests.Shared/Localisation/he/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/he/TimeSpanHumanizeTests.cs @@ -4,8 +4,31 @@ namespace Humanizer.Tests.Localisation.he { [UseCulture("he")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "שנה")] + [InlineData(731, "שנתיים")] + [InlineData(1096, "3 שנים")] + [InlineData(4018, "11 שנים")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "חודש")] + [InlineData(61, "חודשיים")] + [InlineData(92, "3 חודשים")] + [InlineData(335, "11 חודשים")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "שבוע")] [InlineData(14, "שבועיים")] diff --git a/src/Humanizer.Tests.Shared/Localisation/hr/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/hr/TimeSpanHumanizeTests.cs index 5cf5886dc..8d58c7ec2 100644 --- a/src/Humanizer.Tests.Shared/Localisation/hr/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/hr/TimeSpanHumanizeTests.cs @@ -6,6 +6,29 @@ namespace Humanizer.Tests.Localisation.hr [UseCulture("hr-HR")] public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 godina")] + [InlineData(731, "2 godine")] + [InlineData(1096, "3 godine")] + [InlineData(4018, "11 godina")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mjesec")] + [InlineData(61, "2 mjeseca")] + [InlineData(92, "3 mjeseca")] + [InlineData(335, "11 mjeseci")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(1, "1 dan")] [InlineData(2, "2 dana")] diff --git a/src/Humanizer.Tests.Shared/Localisation/hu/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/hu/TimeSpanHumanizeTests.cs index 5f05e1f1a..86b2210df 100644 --- a/src/Humanizer.Tests.Shared/Localisation/hu/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/hu/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.hu { [UseCulture("hu-HU")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "egy év")] + [InlineData(731, "2 év")] + [InlineData(1096, "3 év")] + [InlineData(4018, "11 év")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "egy hónap")] + [InlineData(61, "2 hónap")] + [InlineData(92, "3 hónap")] + [InlineData(335, "11 hónap")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(14, "2 hét")] [InlineData(7, "1 hét")] diff --git a/src/Humanizer.Tests.Shared/Localisation/id/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/id/TimeSpanHumanizeTests.cs index 25e10f282..63ebc55e6 100644 --- a/src/Humanizer.Tests.Shared/Localisation/id/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/id/TimeSpanHumanizeTests.cs @@ -4,8 +4,31 @@ namespace Humanizer.Tests.Localisation.id { [UseCulture("id-ID")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 tahun")] + [InlineData(731, "2 tahun")] + [InlineData(1096, "3 tahun")] + [InlineData(4018, "11 tahun")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 bulan")] + [InlineData(61, "2 bulan")] + [InlineData(92, "3 bulan")] + [InlineData(335, "11 bulan")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(14, "2 minggu")] [InlineData(7, "1 minggu")] diff --git a/src/Humanizer.Tests.Shared/Localisation/it/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/it/TimeSpanHumanizeTests.cs index 0a88ebe2b..bfcfa3c19 100644 --- a/src/Humanizer.Tests.Shared/Localisation/it/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/it/TimeSpanHumanizeTests.cs @@ -4,9 +4,32 @@ namespace Humanizer.Tests.Localisation.it { [UseCulture("it")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 anno")] + [InlineData(731, "2 anni")] + [InlineData(1096, "3 anni")] + [InlineData(4018, "11 anni")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mese")] + [InlineData(61, "2 mesi")] + [InlineData(92, "3 mesi")] + [InlineData(335, "11 mesi")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "1 settimana")] [InlineData(14, "2 settimane")] diff --git a/src/Humanizer.Tests.Shared/Localisation/ja/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/ja/TimeSpanHumanizeTests.cs index a47829837..db5b3f9f0 100644 --- a/src/Humanizer.Tests.Shared/Localisation/ja/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/ja/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.ja { [UseCulture("ja")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 年間の")] + [InlineData(731, "2 年")] + [InlineData(1096, "3 年")] + [InlineData(4018, "11 年")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 ヶ月")] + [InlineData(61, "2 ヶ月")] + [InlineData(92, "3 ヶ月")] + [InlineData(335, "11 ヶ月")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "1 週間")] [InlineData(14, "2 週間")] diff --git a/src/Humanizer.Tests.Shared/Localisation/nb-NO/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/nb-NO/TimeSpanHumanizeTests.cs index 2681e6157..2c3b57252 100644 --- a/src/Humanizer.Tests.Shared/Localisation/nb-NO/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/nb-NO/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.nbNO { [UseCulture("nb-NO")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "ett år")] + [InlineData(731, "2 år")] + [InlineData(1096, "3 år")] + [InlineData(4018, "11 år")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "en måned")] + [InlineData(61, "2 måneder")] + [InlineData(92, "3 måneder")] + [InlineData(335, "11 måneder")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "en uke")] [InlineData(14, "2 uker")] diff --git a/src/Humanizer.Tests.Shared/Localisation/nb/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/nb/TimeSpanHumanizeTests.cs index 8b267b15b..2f8aab112 100644 --- a/src/Humanizer.Tests.Shared/Localisation/nb/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/nb/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.nb { [UseCulture("nb")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "ett år")] + [InlineData(731, "2 år")] + [InlineData(1096, "3 år")] + [InlineData(4018, "11 år")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "en måned")] + [InlineData(61, "2 måneder")] + [InlineData(92, "3 måneder")] + [InlineData(335, "11 måneder")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "en uke")] [InlineData(14, "2 uker")] diff --git a/src/Humanizer.Tests.Shared/Localisation/nl/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/nl/TimeSpanHumanizeTests.cs index 746fbcdf7..8cb748e94 100644 --- a/src/Humanizer.Tests.Shared/Localisation/nl/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/nl/TimeSpanHumanizeTests.cs @@ -4,9 +4,32 @@ namespace Humanizer.Tests.Localisation.nl { [UseCulture("nl-NL")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "1 jaar")] + [InlineData(731, "2 jaar")] + [InlineData(1096, "3 jaar")] + [InlineData(4018, "11 jaar")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "1 maand")] + [InlineData(61, "2 maanden")] + [InlineData(92, "3 maanden")] + [InlineData(335, "11 maanden")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Fact] public void TwoWeeks() { diff --git a/src/Humanizer.Tests.Shared/Localisation/pl/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/pl/TimeSpanHumanizeTests.cs index d87d562c9..1f57e80fc 100644 --- a/src/Humanizer.Tests.Shared/Localisation/pl/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/pl/TimeSpanHumanizeTests.cs @@ -4,7 +4,7 @@ namespace Humanizer.Tests.Localisation.pl { [UseCulture("pl")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { [Theory] [InlineData(1, "1 milisekunda")] @@ -82,6 +82,29 @@ public void Weeks(int number, string expected) Assert.Equal(expected, TimeSpan.FromDays(number * 7).Humanize()); } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 miesiąc")] + [InlineData(61, "2 miesiące")] + [InlineData(92, "3 miesiące")] + [InlineData(335, "11 miesięcy")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 rok")] + [InlineData(731, "2 lata")] + [InlineData(1096, "3 lata")] + [InlineData(4018, "11 lat")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Fact] public void NoTime() { diff --git a/src/Humanizer.Tests.Shared/Localisation/pt-BR/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/pt-BR/TimeSpanHumanizeTests.cs index 13faeb869..156dcada3 100644 --- a/src/Humanizer.Tests.Shared/Localisation/pt-BR/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/pt-BR/TimeSpanHumanizeTests.cs @@ -6,6 +6,29 @@ namespace Humanizer.Tests.Localisation.ptBR [UseCulture("pt-BR")] public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 ano")] + [InlineData(731, "2 anos")] + [InlineData(1096, "3 anos")] + [InlineData(4018, "11 anos")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mês")] + [InlineData(61, "2 meses")] + [InlineData(92, "3 meses")] + [InlineData(335, "11 meses")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Fact] public void TwoWeeks() { diff --git a/src/Humanizer.Tests.Shared/Localisation/pt/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/pt/TimeSpanHumanizeTests.cs index e442ebae0..54540c10f 100644 --- a/src/Humanizer.Tests.Shared/Localisation/pt/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/pt/TimeSpanHumanizeTests.cs @@ -6,6 +6,29 @@ namespace Humanizer.Tests.Localisation.pt [UseCulture("pt")] public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 ano")] + [InlineData(731, "2 anos")] + [InlineData(1096, "3 anos")] + [InlineData(4018, "11 anos")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mês")] + [InlineData(61, "2 meses")] + [InlineData(92, "3 meses")] + [InlineData(335, "11 meses")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Fact] public void TwoWeeks() { diff --git a/src/Humanizer.Tests.Shared/Localisation/ro-Ro/TimeSpanHumanizerTests.cs b/src/Humanizer.Tests.Shared/Localisation/ro-Ro/TimeSpanHumanizerTests.cs index 194f557d8..7eba8663c 100644 --- a/src/Humanizer.Tests.Shared/Localisation/ro-Ro/TimeSpanHumanizerTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/ro-Ro/TimeSpanHumanizerTests.cs @@ -11,7 +11,7 @@ namespace Humanizer.Tests.Localisation.roRO /// There is no test for months since there are only 12 of them in a year. /// [UseCulture("ro-RO")] - public class TimeSpanHumanizerTests + public class TimeSpanHumanizerTests { [Theory] @@ -57,7 +57,7 @@ public void Hours(int hours, string expected) var actual = TimeSpan.FromHours(hours).Humanize(); Assert.Equal(expected, actual); } - + [Theory] [InlineData(1, "1 zi")] [InlineData(6, "6 zile")] @@ -79,5 +79,28 @@ public void Weeks(int weeks, string expected) var actual = TimeSpan.FromDays(7 * weeks).Humanize(); Assert.Equal(expected, actual); } + + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 luna")] + [InlineData(61, "2 luni")] + [InlineData(92, "3 luni")] + [InlineData(335, "11 luni")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 ani")] + [InlineData(731, "2 ani")] + [InlineData(1096, "3 ani")] + [InlineData(4018, "11 ani")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } } } diff --git a/src/Humanizer.Tests.Shared/Localisation/ru-RU/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/ru-RU/TimeSpanHumanizeTests.cs index 21ed8650b..aa8b2c0ae 100644 --- a/src/Humanizer.Tests.Shared/Localisation/ru-RU/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/ru-RU/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.ruRU { [UseCulture("ru-RU")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "один год")] + [InlineData(731, "2 года")] + [InlineData(1096, "3 года")] + [InlineData(4018, "11 лет")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "один месяц")] + [InlineData(61, "2 месяца")] + [InlineData(92, "3 месяца")] + [InlineData(335, "11 месяцев")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "одна неделя")] [InlineData(14, "2 недели")] diff --git a/src/Humanizer.Tests.Shared/Localisation/sk/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/sk/TimeSpanHumanizeTests.cs index 833c9cafb..e6f2acfea 100644 --- a/src/Humanizer.Tests.Shared/Localisation/sk/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/sk/TimeSpanHumanizeTests.cs @@ -7,6 +7,28 @@ namespace Humanizer.Tests.Localisation.sk public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 rok")] + [InlineData(731, "2 roky")] + [InlineData(1096, "3 roky")] + [InlineData(4018, "11 rokov")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mesiac")] + [InlineData(61, "2 mesiace")] + [InlineData(92, "3 mesiace")] + [InlineData(335, "11 mesiacov")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(1, "1 milisekunda")] [InlineData(2, "2 milisekundy")] @@ -16,7 +38,7 @@ public class TimeSpanHumanizeTests [InlineData(6, "6 milisekúnd")] [InlineData(10, "10 milisekúnd")] public void Milliseconds(int number, string expected) - { + { Assert.Equal(expected, TimeSpan.FromMilliseconds(number).Humanize()); } @@ -29,7 +51,7 @@ public void Milliseconds(int number, string expected) [InlineData(6, "6 sekúnd")] [InlineData(10, "10 sekúnd")] public void Seconds(int number, string expected) - { + { Assert.Equal(expected, TimeSpan.FromSeconds(number).Humanize()); } @@ -55,7 +77,7 @@ public void Minutes(int number, string expected) [InlineData(6, "6 hodín")] [InlineData(10, "10 hodín")] public void Hours(int number, string expected) - { + { Assert.Equal(expected, TimeSpan.FromHours(number).Humanize()); } @@ -67,7 +89,7 @@ public void Hours(int number, string expected) [InlineData(5, "5 dní")] [InlineData(6, "6 dní")] public void Days(int number, string expected) - { + { Assert.Equal(expected, TimeSpan.FromDays(number).Humanize()); } diff --git a/src/Humanizer.Tests.Shared/Localisation/sl/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/sl/TimeSpanHumanizeTests.cs index 78dad0c0a..3909946dc 100644 --- a/src/Humanizer.Tests.Shared/Localisation/sl/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/sl/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.sl { [UseCulture("sl-SI")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 leto")] + [InlineData(731, "2 leti")] + [InlineData(1096, "3 leta")] + [InlineData(4018, "11 let")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mesec")] + [InlineData(61, "2 meseca")] + [InlineData(92, "3 mesece")] + [InlineData(335, "11 mesecev")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "1 teden")] [InlineData(14, "2 tedna")] diff --git a/src/Humanizer.Tests.Shared/Localisation/sr-Latn/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/sr-Latn/TimeSpanHumanizeTests.cs index 94af4be25..d3797dc4d 100644 --- a/src/Humanizer.Tests.Shared/Localisation/sr-Latn/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/sr-Latn/TimeSpanHumanizeTests.cs @@ -4,8 +4,31 @@ namespace Humanizer.Tests.Localisation.srLatn { [UseCulture("sr-Latn")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 godina")] + [InlineData(731, "2 godine")] + [InlineData(1096, "3 godine")] + [InlineData(4018, "11 godina")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 mesec")] + [InlineData(61, "2 meseca")] + [InlineData(92, "3 meseca")] + [InlineData(335, "11 meseci")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(35, "5 nedelja")] [InlineData(14, "2 nedelje")] diff --git a/src/Humanizer.Tests.Shared/Localisation/sr/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/sr/TimeSpanHumanizeTests.cs index f47dec099..283498594 100644 --- a/src/Humanizer.Tests.Shared/Localisation/sr/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/sr/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.sr { [UseCulture("sr")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 година")] + [InlineData(731, "2 године")] + [InlineData(1096, "3 године")] + [InlineData(4018, "11 година")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 месец")] + [InlineData(61, "2 месеца")] + [InlineData(92, "3 месеца")] + [InlineData(335, "11 месеци")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(35, "5 недеља")] [InlineData(14, "2 недеље")] diff --git a/src/Humanizer.Tests.Shared/Localisation/sv/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/sv/TimeSpanHumanizeTests.cs index 123e0fdf7..da70eab51 100644 --- a/src/Humanizer.Tests.Shared/Localisation/sv/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/sv/TimeSpanHumanizeTests.cs @@ -54,5 +54,28 @@ public void Weeks(int number, string expected) { Assert.Equal(expected, TimeSpan.FromDays(number * 7).Humanize()); } + + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "en månad")] + [InlineData(61, "2 månader")] + [InlineData(92, "3 månader")] + [InlineData(335, "11 månader")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "ett år")] + [InlineData(731, "2 år")] + [InlineData(1096, "3 år")] + [InlineData(4018, "11 år")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } } } diff --git a/src/Humanizer.Tests.Shared/Localisation/tr/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/tr/TimeSpanHumanizeTests.cs index 732442ea8..cbce3d31b 100644 --- a/src/Humanizer.Tests.Shared/Localisation/tr/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/tr/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.tr { [UseCulture("tr")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 yıl")] + [InlineData(731, "2 yıl")] + [InlineData(1096, "3 yıl")] + [InlineData(4018, "11 yıl")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 ay")] + [InlineData(61, "2 ay")] + [InlineData(92, "3 ay")] + [InlineData(335, "11 ay")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(14, "2 hafta")] [InlineData(7, "1 hafta")] diff --git a/src/Humanizer.Tests.Shared/Localisation/uk-UA/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/uk-UA/TimeSpanHumanizeTests.cs index 40d6ebc91..02432c9fe 100644 --- a/src/Humanizer.Tests.Shared/Localisation/uk-UA/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/uk-UA/TimeSpanHumanizeTests.cs @@ -4,8 +4,31 @@ namespace Humanizer.Tests.Localisation.ukUA { [UseCulture("uk-UA")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "один рік")] + [InlineData(731, "2 роки")] + [InlineData(1096, "3 роки")] + [InlineData(4018, "11 років")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "один місяць")] + [InlineData(61, "2 місяці")] + [InlineData(92, "3 місяці")] + [InlineData(335, "11 місяців")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "один тиждень")] [InlineData(14, "2 тижні")] diff --git a/src/Humanizer.Tests.Shared/Localisation/uz-Cyrl-UZ/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/uz-Cyrl-UZ/TimeSpanHumanizeTests.cs index 2283b1aab..b9cf5873b 100644 --- a/src/Humanizer.Tests.Shared/Localisation/uz-Cyrl-UZ/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/uz-Cyrl-UZ/TimeSpanHumanizeTests.cs @@ -4,8 +4,32 @@ namespace Humanizer.Tests.Localisation.uzCyrl { [UseCulture("uz-Cyrl-UZ")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 йил")] + [InlineData(731, "2 йил")] + [InlineData(1096, "3 йил")] + [InlineData(4018, "11 йил")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 ой")] + [InlineData(61, "2 ой")] + [InlineData(92, "3 ой")] + [InlineData(335, "11 ой")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(14, "2 ҳафта")] [InlineData(7, "1 ҳафта")] diff --git a/src/Humanizer.Tests.Shared/Localisation/uz-Latn-UZ/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/uz-Latn-UZ/TimeSpanHumanizeTests.cs index 735bff718..f4e6638a2 100644 --- a/src/Humanizer.Tests.Shared/Localisation/uz-Latn-UZ/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/uz-Latn-UZ/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.uzLatn { [UseCulture("uz-Latn-UZ")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { - + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 yil")] + [InlineData(731, "2 yil")] + [InlineData(1096, "3 yil")] + [InlineData(4018, "11 yil")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 oy")] + [InlineData(61, "2 oy")] + [InlineData(92, "3 oy")] + [InlineData(335, "11 oy")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(14, "2 hafta")] [InlineData(7, "1 hafta")] diff --git a/src/Humanizer.Tests.Shared/Localisation/vi/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/vi/TimeSpanHumanizeTests.cs index 2825f9969..02c331222 100644 --- a/src/Humanizer.Tests.Shared/Localisation/vi/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/vi/TimeSpanHumanizeTests.cs @@ -4,8 +4,31 @@ namespace Humanizer.Tests.Localisation.vi { [UseCulture("vi")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Google")] + [InlineData(366, "1 năm")] + [InlineData(731, "2 năm")] + [InlineData(1096, "3 năm")] + [InlineData(4018, "11 năm")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Google")] + [InlineData(31, "1 tháng")] + [InlineData(61, "2 tháng")] + [InlineData(92, "3 tháng")] + [InlineData(335, "11 tháng")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(14, "2 tuần")] [InlineData(7, "1 tuần")] diff --git a/src/Humanizer.Tests.Shared/Localisation/zh-CN/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/zh-CN/TimeSpanHumanizeTests.cs index c1317d653..ed9b60dd0 100644 --- a/src/Humanizer.Tests.Shared/Localisation/zh-CN/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/zh-CN/TimeSpanHumanizeTests.cs @@ -4,8 +4,31 @@ namespace Humanizer.Tests.Localisation.zhCN { [UseCulture("zh-CN")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "1 年")] + [InlineData(731, "2 年")] + [InlineData(1096, "3 年")] + [InlineData(4018, "11 年")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "1 个月")] + [InlineData(61, "2 个月")] + [InlineData(92, "3 个月")] + [InlineData(335, "11 个月")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "1 周")] [InlineData(14, "2 周")] diff --git a/src/Humanizer.Tests.Shared/Localisation/zh-Hans/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/zh-Hans/TimeSpanHumanizeTests.cs index 83c1582b6..f85c67dcb 100644 --- a/src/Humanizer.Tests.Shared/Localisation/zh-Hans/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/zh-Hans/TimeSpanHumanizeTests.cs @@ -4,9 +4,31 @@ namespace Humanizer.Tests.Localisation.zhHans { [UseCulture("zh-Hans")] - public class TimeSpanHumanizeTests + public class TimeSpanHumanizeTests { + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "1 年")] + [InlineData(731, "2 年")] + [InlineData(1096, "3 年")] + [InlineData(4018, "11 年")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "1 个月")] + [InlineData(61, "2 个月")] + [InlineData(92, "3 个月")] + [InlineData(335, "11 个月")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "1 周")] [InlineData(14, "2 周")] diff --git a/src/Humanizer.Tests.Shared/Localisation/zh-Hant/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/Localisation/zh-Hant/TimeSpanHumanizeTests.cs index 241e833a2..2bee5a24f 100644 --- a/src/Humanizer.Tests.Shared/Localisation/zh-Hant/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/Localisation/zh-Hant/TimeSpanHumanizeTests.cs @@ -6,6 +6,30 @@ namespace Humanizer.Tests.Localisation.zhHant [UseCulture("zh-Hant")] public class TimeSpanHumanizeTests { + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(366, "1 年")] + [InlineData(731, "2 年")] + [InlineData(1096, "3 年")] + [InlineData(4018, "11 年")] + public void Years(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + + [Theory] + [Trait("Translation", "Native speaker")] + [InlineData(31, "1 個月")] + [InlineData(61, "2 個月")] + [InlineData(92, "3 個月")] + [InlineData(335, "11 個月")] + public void Months(int days, string expected) + { + Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year)); + } + [Theory] [InlineData(7, "1 周")] [InlineData(14, "2 周")] diff --git a/src/Humanizer.Tests.Shared/TimeSpanHumanizeTests.cs b/src/Humanizer.Tests.Shared/TimeSpanHumanizeTests.cs index 9eadfb056..ecaa11fb7 100644 --- a/src/Humanizer.Tests.Shared/TimeSpanHumanizeTests.cs +++ b/src/Humanizer.Tests.Shared/TimeSpanHumanizeTests.cs @@ -2,17 +2,70 @@ using System.Globalization; using Humanizer.Localisation; using Xunit; +using System.Linq; namespace Humanizer.Tests { [UseCulture("en-US")] public class TimeSpanHumanizeTests { + [Fact] + public void AllTimeSpansMustBeUniqueForASequenceOfDays() + { + var culture = new CultureInfo("en-US"); + var qry = from i in Enumerable.Range(0, 100000) + let ts = TimeSpan.FromDays(i) + let text = ts.Humanize(precision: 3, culture: culture, maxUnit: TimeUnit.Year) + select text; + var grouping = from t in qry + group t by t into g + select new { Key = g.Key, Count = g.Count() }; + var allUnique = grouping.All(g => g.Count == 1); + Assert.True(allUnique); + } + + [Theory] + [InlineData(365, "11 months, 30 days")] + [InlineData(365 + 1, "1 year")] + [InlineData(365 + 365, "1 year, 11 months, 29 days")] + [InlineData(365 + 365 + 1, "2 years")] + [InlineData(365 + 365 + 365, "2 years, 11 months, 29 days")] + [InlineData(365 + 365 + 365 + 1, "3 years")] + [InlineData(365 + 365 + 365 + 365, "3 years, 11 months, 29 days")] + [InlineData(365 + 365 + 365 + 365 + 1, "4 years")] + [InlineData(365 + 365 + 365 + 365 + 366, "4 years, 11 months, 30 days")] + [InlineData(365 + 365 + 365 + 365 + 366 + 1, "5 years")] + public void Year(int days, string expected) + { + string actual = TimeSpan.FromDays(days).Humanize(precision: 7, maxUnit: TimeUnit.Year); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(30, "4 weeks, 2 days")] + [InlineData(30 + 1, "1 month")] + [InlineData(30 + 30, "1 month, 29 days")] + [InlineData(30 + 30 + 1, "2 months")] + [InlineData(30 + 30 + 31, "2 months, 30 days")] + [InlineData(30 + 30 + 31 + 1, "3 months")] + [InlineData(30 + 30 + 31 + 30, "3 months, 29 days")] + [InlineData(30 + 30 + 31 + 30 + 1, "4 months")] + [InlineData(30 + 30 + 31 + 30 + 31, "4 months, 30 days")] + [InlineData(30 + 30 + 31 + 30 + 31 + 1, "5 months")] + [InlineData(365, "11 months, 30 days")] + [InlineData(366, "1 year")] + public void Month(int days, string expected) + { + string actual = TimeSpan.FromDays(days).Humanize(precision: 7, maxUnit: TimeUnit.Year); + Assert.Equal(expected, actual); + } + [Theory] [InlineData(14, "2 weeks")] [InlineData(7, "1 week")] [InlineData(-14, "2 weeks")] [InlineData(-7, "1 week")] + [InlineData(730, "104 weeks")] public void Weeks(int days, string expected) { var actual = TimeSpan.FromDays(days).Humanize(); @@ -86,12 +139,14 @@ public void Milliseconds(int ms, string expected) } [Theory] + [InlineData((long)366 * 24 * 60 * 60 * 1000, "12 months", TimeUnit.Month)] + [InlineData((long)6 * 7 * 24 * 60 * 60 * 1000, "6 weeks", TimeUnit.Week)] [InlineData(7 * 24 * 60 * 60 * 1000, "7 days", TimeUnit.Day)] [InlineData(24 * 60 * 60 * 1000, "24 hours", TimeUnit.Hour)] [InlineData(60 * 60 * 1000, "60 minutes", TimeUnit.Minute)] [InlineData(60 * 1000, "60 seconds", TimeUnit.Second)] [InlineData(1000, "1000 milliseconds", TimeUnit.Millisecond)] - public void TimeSpanWithMaxTimeUnit(int ms, string expected, TimeUnit maxUnit) + public void TimeSpanWithMaxTimeUnit(long ms, string expected, TimeUnit maxUnit) { var actual = TimeSpan.FromMilliseconds(ms).Humanize(maxUnit: maxUnit); Assert.Equal(expected, actual); @@ -134,9 +189,25 @@ public void TimeSpanWithMaxTimeUnit(int ms, string expected, TimeUnit maxUnit) [InlineData(694922500, "1 week, 1 day, 1 hour", TimeUnit.Hour)] [InlineData(694922500, "1 week, 1 day", TimeUnit.Day)] [InlineData(694922500, "1 week", TimeUnit.Week)] - public void TimeSpanWithMinTimeUnit(int ms, string expected, TimeUnit minUnit) + [InlineData(2768462500, "1 month, 1 day, 1 hour, 1 minute, 2 seconds, 500 milliseconds", TimeUnit.Millisecond)] + [InlineData(2768462500, "1 month, 1 day, 1 hour, 1 minute, 2 seconds", TimeUnit.Second)] + [InlineData(2768462500, "1 month, 1 day, 1 hour, 1 minute", TimeUnit.Minute)] + [InlineData(2768462500, "1 month, 1 day, 1 hour", TimeUnit.Hour)] + [InlineData(2768462500, "1 month, 1 day", TimeUnit.Day)] + [InlineData(2768462500, "1 month", TimeUnit.Week)] + [InlineData(2768462500, "1 month", TimeUnit.Month)] + [InlineData(2768462500, "no time", TimeUnit.Year)] + [InlineData(34390862500, "1 year, 1 month, 2 days, 1 hour, 1 minute, 2 seconds, 500 milliseconds", TimeUnit.Millisecond)] + [InlineData(34390862500, "1 year, 1 month, 2 days, 1 hour, 1 minute, 2 seconds", TimeUnit.Second)] + [InlineData(34390862500, "1 year, 1 month, 2 days, 1 hour, 1 minute", TimeUnit.Minute)] + [InlineData(34390862500, "1 year, 1 month, 2 days, 1 hour", TimeUnit.Hour)] + [InlineData(34390862500, "1 year, 1 month, 2 days", TimeUnit.Day)] + [InlineData(34390862500, "1 year, 1 month", TimeUnit.Week)] + [InlineData(34390862500, "1 year, 1 month", TimeUnit.Month)] + [InlineData(34390862500, "1 year", TimeUnit.Year)] + public void TimeSpanWithMinTimeUnit(long ms, string expected, TimeUnit minUnit) { - var actual = TimeSpan.FromMilliseconds(ms).Humanize(minUnit: minUnit, precision: 6); + var actual = TimeSpan.FromMilliseconds(ms).Humanize(minUnit: minUnit, precision: 7, maxUnit: TimeUnit.Year); Assert.Equal(expected, actual); } @@ -170,9 +241,22 @@ public void TimeSpanWithMinTimeUnit(int ms, string expected, TimeUnit minUnit) [InlineData(1299630020, 3, "2 weeks, 1 day, 1 hour")] [InlineData(1299630020, 4, "2 weeks, 1 day, 1 hour, 30 seconds")] [InlineData(1299630020, 5, "2 weeks, 1 day, 1 hour, 30 seconds, 20 milliseconds")] - public void TimeSpanWithPrecision(int milliseconds, int precision, string expected) + [InlineData(2768462500, 6, "1 month, 1 day, 1 hour, 1 minute, 2 seconds, 500 milliseconds")] + [InlineData(2768462500, 5, "1 month, 1 day, 1 hour, 1 minute, 2 seconds")] + [InlineData(2768462500, 4, "1 month, 1 day, 1 hour, 1 minute")] + [InlineData(2768462500, 3, "1 month, 1 day, 1 hour")] + [InlineData(2768462500, 2, "1 month, 1 day")] + [InlineData(2768462500, 1, "1 month")] + [InlineData(34390862500, 7, "1 year, 1 month, 2 days, 1 hour, 1 minute, 2 seconds, 500 milliseconds")] + [InlineData(34390862500, 6, "1 year, 1 month, 2 days, 1 hour, 1 minute, 2 seconds")] + [InlineData(34390862500, 5, "1 year, 1 month, 2 days, 1 hour, 1 minute")] + [InlineData(34390862500, 4, "1 year, 1 month, 2 days, 1 hour")] + [InlineData(34390862500, 3, "1 year, 1 month, 2 days")] + [InlineData(34390862500, 2, "1 year, 1 month")] + [InlineData(34390862500, 1, "1 year")] + public void TimeSpanWithPrecision(long milliseconds, int precision, string expected) { - var actual = TimeSpan.FromMilliseconds(milliseconds).Humanize(precision); + var actual = TimeSpan.FromMilliseconds(milliseconds).Humanize(precision, maxUnit: TimeUnit.Year); Assert.Equal(expected, actual); } diff --git a/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs b/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs index 75d6c7cbd..20fbdeb1f 100644 --- a/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs +++ b/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs @@ -61,15 +61,12 @@ public virtual string TimeSpanHumanize_Zero() /// /// Returns the string representation of the provided TimeSpan /// - /// Must be less than or equal to TimeUnit.Week + /// A time unit to represent. /// /// /// Is thrown when timeUnit is larger than TimeUnit.Week public virtual string TimeSpanHumanize(TimeUnit timeUnit, int unit) { - if (timeUnit > TimeUnit.Week) - throw new ArgumentOutOfRangeException(nameof(timeUnit), "There's no meaningful way to humanize passed timeUnit."); - return GetResourceForTimeSpan(timeUnit, unit); } diff --git a/src/Humanizer/Properties/Resources.af.resx b/src/Humanizer/Properties/Resources.af.resx index 955479a5a..14a4166c2 100644 --- a/src/Humanizer/Properties/Resources.af.resx +++ b/src/Humanizer/Properties/Resources.af.resx @@ -231,4 +231,16 @@ oor 1 jaar + + 1 maand + + + {0} maande + + + {0} jaar + + + 1 jaar + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.ar.resx b/src/Humanizer/Properties/Resources.ar.resx index f70c4b314..ce2935ba0 100644 --- a/src/Humanizer/Properties/Resources.ar.resx +++ b/src/Humanizer/Properties/Resources.ar.resx @@ -401,4 +401,28 @@ الآن now + + {0} أشهر + + + شهرين + + + {0} أشهر + + + {0} سنة + + + سنتين + + + {0} سنة + + + شهر 1 + + + السنة 1 + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.bg.resx b/src/Humanizer/Properties/Resources.bg.resx index 585db32a6..104de5a71 100644 --- a/src/Humanizer/Properties/Resources.bg.resx +++ b/src/Humanizer/Properties/Resources.bg.resx @@ -231,4 +231,16 @@ след година - + + {0} месеца + + + {0} години + + + един месец + + + една година + + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.bn-BD.resx b/src/Humanizer/Properties/Resources.bn-BD.resx index 80c3fd9a2..f36b85ca3 100644 --- a/src/Humanizer/Properties/Resources.bn-BD.resx +++ b/src/Humanizer/Properties/Resources.bn-BD.resx @@ -231,4 +231,16 @@ এক বছর পর + + {0} মাস + + + {0} বছর + + + এক মাসের + + + এক বছর + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.cs.resx b/src/Humanizer/Properties/Resources.cs.resx index 7d53f6432..1b9dbab2a 100644 --- a/src/Humanizer/Properties/Resources.cs.resx +++ b/src/Humanizer/Properties/Resources.cs.resx @@ -285,4 +285,22 @@ {0} týdny + + {0} měsíců + + + {0} měsíce + + + {0} let + + + {0} roky + + + 1 měsíc + + + 1 rok + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.da.resx b/src/Humanizer/Properties/Resources.da.resx index ad88dee52..7466fefb9 100644 --- a/src/Humanizer/Properties/Resources.da.resx +++ b/src/Humanizer/Properties/Resources.da.resx @@ -231,4 +231,16 @@ et år fra nu + + {0} måneder + + + {0} år + + + en måned + + + et år + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.de.resx b/src/Humanizer/Properties/Resources.de.resx index a6f7884d8..87c3e700a 100644 --- a/src/Humanizer/Properties/Resources.de.resx +++ b/src/Humanizer/Properties/Resources.de.resx @@ -234,4 +234,16 @@ nie + + {0} Monate + + + {0} Jahre + + + Ein Monat + + + Ein Jahr + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.es.resx b/src/Humanizer/Properties/Resources.es.resx index b738e9da1..d92340cd5 100644 --- a/src/Humanizer/Properties/Resources.es.resx +++ b/src/Humanizer/Properties/Resources.es.resx @@ -231,4 +231,16 @@ ahora + + {0} meses + + + {0} años + + + un mes + + + un año + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.fa.resx b/src/Humanizer/Properties/Resources.fa.resx index 412163855..ee6d7469a 100644 --- a/src/Humanizer/Properties/Resources.fa.resx +++ b/src/Humanizer/Properties/Resources.fa.resx @@ -231,4 +231,16 @@ یک سال بعد + + {0} ماه + + + {0} سال + + + یک ماه + + + یک سال + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.fr-BE.resx b/src/Humanizer/Properties/Resources.fr-BE.resx index 0a46359ab..50e6f4cf4 100644 --- a/src/Humanizer/Properties/Resources.fr-BE.resx +++ b/src/Humanizer/Properties/Resources.fr-BE.resx @@ -231,4 +231,16 @@ pas de temps + + {0} mois + + + {0} ans + + + 1 mois + + + 1 année + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.fr.resx b/src/Humanizer/Properties/Resources.fr.resx index 1503b4aa7..3ffc118db 100644 --- a/src/Humanizer/Properties/Resources.fr.resx +++ b/src/Humanizer/Properties/Resources.fr.resx @@ -234,4 +234,16 @@ jamais + + {0} mois + + + {0} ans + + + 1 mois + + + 1 année + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.he.resx b/src/Humanizer/Properties/Resources.he.resx index d078438f4..1c9720fb7 100644 --- a/src/Humanizer/Properties/Resources.he.resx +++ b/src/Humanizer/Properties/Resources.he.resx @@ -413,4 +413,28 @@ בעוד שנייה in a second + + {0} חודשים + + + חודשיים + + + {0} חודשים + + + {0} שנים + + + שנתיים + + + {0} שנים + + + חודש + + + שנה + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.hr.resx b/src/Humanizer/Properties/Resources.hr.resx index 436f13840..0c9ff334c 100644 --- a/src/Humanizer/Properties/Resources.hr.resx +++ b/src/Humanizer/Properties/Resources.hr.resx @@ -279,4 +279,22 @@ za godinu dana - + + {0} mjeseci + + + {0} mjeseca + + + {0} godina + + + {0} godine + + + 1 mjesec + + + 1 godina + + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.hu.resx b/src/Humanizer/Properties/Resources.hu.resx index df687010d..b15b707e3 100644 --- a/src/Humanizer/Properties/Resources.hu.resx +++ b/src/Humanizer/Properties/Resources.hu.resx @@ -231,4 +231,16 @@ egy év múlva + + {0} hónap + + + {0} év + + + egy hónap + + + egy év + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.id.resx b/src/Humanizer/Properties/Resources.id.resx index e7c4c6023..88711e17c 100644 --- a/src/Humanizer/Properties/Resources.id.resx +++ b/src/Humanizer/Properties/Resources.id.resx @@ -269,4 +269,16 @@ setahun dari sekarang one year from now + + {0} bulan + + + {0} tahun + + + 1 bulan + + + 1 tahun + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.it.resx b/src/Humanizer/Properties/Resources.it.resx index 2be83b07a..58e5d7d65 100644 --- a/src/Humanizer/Properties/Resources.it.resx +++ b/src/Humanizer/Properties/Resources.it.resx @@ -1,6 +1,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + un secondo fa - + {0} secondi fa - + un minuto fa - + {0} minuti fa - + un'ora fa - + {0} ore fa - + ieri - + {0} giorni fa - + un mese fa - + {0} mesi fa - + un anno fa - + {0} anni fa - + {0} giorni - + {0} ore - + {0} millisecondi - + {0} minuti - + {0} secondi - + 1 giorno - + 1 ora - + 1 millisecondo - + 1 minuto - + 1 secondo - + 0 secondi - + {0} settimane - + 1 settimana - + tra {0} giorni - + tra {0} ore - + tra {0} minuti - + tra {0} mesi - + tra {0} secondi - + tra {0} anni - + adesso - + domani - + tra un'ora - + tra un minuto - + tra un mese - + tra un secondo - + tra un anno + + {0} mesi + + + {0} anni + + + 1 mese + + + 1 anno + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.ja.resx b/src/Humanizer/Properties/Resources.ja.resx index 34b8fe66b..bddb2d20d 100644 --- a/src/Humanizer/Properties/Resources.ja.resx +++ b/src/Humanizer/Properties/Resources.ja.resx @@ -231,4 +231,16 @@ 来年 + + {0} ヶ月 + + + {0} 年 + + + 1 ヶ月 + + + 1 年間の + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.nb-NO.resx b/src/Humanizer/Properties/Resources.nb-NO.resx index 240a6ba25..8a731ca43 100644 --- a/src/Humanizer/Properties/Resources.nb-NO.resx +++ b/src/Humanizer/Properties/Resources.nb-NO.resx @@ -231,4 +231,16 @@ ett år fra nå + + {0} måneder + + + {0} år + + + en måned + + + ett år + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.nb.resx b/src/Humanizer/Properties/Resources.nb.resx index 240a6ba25..8a731ca43 100644 --- a/src/Humanizer/Properties/Resources.nb.resx +++ b/src/Humanizer/Properties/Resources.nb.resx @@ -231,4 +231,16 @@ ett år fra nå + + {0} måneder + + + {0} år + + + en måned + + + ett år + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.nl.resx b/src/Humanizer/Properties/Resources.nl.resx index 9139cf7e3..9c72e6662 100644 --- a/src/Humanizer/Properties/Resources.nl.resx +++ b/src/Humanizer/Properties/Resources.nl.resx @@ -192,43 +192,55 @@ geen tijd - + over {0} dagen - + over {0} uur - + over {0} minuten - + over {0} maanden - + over {0} seconden - + over {0} jaar - + nu - + morgen - + over 1 uur - + over 1 minuut - + over 1 maand - + over 1 seconde - + over 1 jaar + + {0} maanden + + + {0} jaar + + + 1 maand + + + 1 jaar + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.pl.resx b/src/Humanizer/Properties/Resources.pl.resx index 44db8f0cd..214e3bad9 100644 --- a/src/Humanizer/Properties/Resources.pl.resx +++ b/src/Humanizer/Properties/Resources.pl.resx @@ -285,4 +285,22 @@ {0} tygodnie + + {0} miesięcy + + + {0} miesiące + + + {0} lat + + + {0} lata + + + 1 miesiąc + + + 1 rok + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.pt.resx b/src/Humanizer/Properties/Resources.pt.resx index 985e39661..60c15f3dd 100644 --- a/src/Humanizer/Properties/Resources.pt.resx +++ b/src/Humanizer/Properties/Resources.pt.resx @@ -231,4 +231,16 @@ agora + + {0} meses + + + {0} anos + + + 1 mês + + + 1 ano + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.resx b/src/Humanizer/Properties/Resources.resx index 16b94e1fa..a9e82425e 100644 --- a/src/Humanizer/Properties/Resources.resx +++ b/src/Humanizer/Properties/Resources.resx @@ -522,4 +522,34 @@ never + + {0} months + + + {0} months + + + {0} months + + + {0} months + + + {0} months + + + {0} years + + + {0} years + + + {0} years + + + {0} years + + + {0} years + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.ro.resx b/src/Humanizer/Properties/Resources.ro.resx index 8dadb6f11..417d8d94d 100644 --- a/src/Humanizer/Properties/Resources.ro.resx +++ b/src/Humanizer/Properties/Resources.ro.resx @@ -231,4 +231,16 @@ niciun timp + + {0}{1} luni + + + {0}{1} ani + + + 1 luna + + + 1 ani + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.ru.resx b/src/Humanizer/Properties/Resources.ru.resx index d7841691d..c10b26311 100644 --- a/src/Humanizer/Properties/Resources.ru.resx +++ b/src/Humanizer/Properties/Resources.ru.resx @@ -339,4 +339,28 @@ через год + + {0} месяцев + + + {0} месяца + + + {0} месяц + + + {0} лет + + + {0} года + + + {0} год + + + один месяц + + + один год + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.sk.resx b/src/Humanizer/Properties/Resources.sk.resx index acebbfe4f..5bf60d03d 100644 --- a/src/Humanizer/Properties/Resources.sk.resx +++ b/src/Humanizer/Properties/Resources.sk.resx @@ -285,4 +285,22 @@ {0} týždne + + {0} mesiacov + + + {0} mesiace + + + {0} rokov + + + {0} roky + + + 1 mesiac + + + 1 rok + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.sl.resx b/src/Humanizer/Properties/Resources.sl.resx index 77f8c1621..4a5029baf 100644 --- a/src/Humanizer/Properties/Resources.sl.resx +++ b/src/Humanizer/Properties/Resources.sl.resx @@ -342,4 +342,28 @@ nikoli + + {0} mesecev + + + {0} meseca + + + {0} mesece + + + {0} let + + + {0} leti + + + {0} leta + + + 1 mesec + + + 1 leto + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.sr-Latn.resx b/src/Humanizer/Properties/Resources.sr-Latn.resx index 44974d84e..3d596f319 100644 --- a/src/Humanizer/Properties/Resources.sr-Latn.resx +++ b/src/Humanizer/Properties/Resources.sr-Latn.resx @@ -117,172 +117,190 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - -pre sekund - - -pre {0} sekundi - - -pre minut - - -pre {0} minuta - - -pre sat vremena - - -pre {0} sati - - -juče - - -pre {0} dana - - -pre mesec dana - - -pre {0} meseci - - -pre godinu dana - - -pre {0} godina - - -{0} dana - - -{0} sati - - -{0} milisekundi - - -{0} minuta - - -{0} sekundi - - -1 dan - - -1 sat - - -1 milisekunda - - -1 minut - - -1 sekunda - - -bez proteklog vremena - - -{0} nedelja - - -1 nedelja - - -za {0} dana - - -za {0} sati - - -za {0} minuta - - -za {0} meseci - - -za {0} sekundi - - -za {0} godina - - -sada - - -sutra - - -za sat vremena - - -za minut - - -za mesec dana - - -za sekund - - -za godinu dana - - -pre {0} dana - - -za {0} dana - - -pre {0} sata - - -za {0} sata - - -pre {0} minuta - - -za {0} minuta - - -pre {0} meseca - - -za {0} meseca - - -pre {0} sekunde - - -za {0} sekunde - - -pre {0} godine - - -za {0} godine - - -{0} dana - - -{0} sata - - -{0} milisekunde - - -{0} minuta - - -{0} sekunde - - -{0} nedelje - + + pre sekund + + + pre {0} sekundi + + + pre minut + + + pre {0} minuta + + + pre sat vremena + + + pre {0} sati + + + juče + + + pre {0} dana + + + pre mesec dana + + + pre {0} meseci + + + pre godinu dana + + + pre {0} godina + + + {0} dana + + + {0} sati + + + {0} milisekundi + + + {0} minuta + + + {0} sekundi + + + 1 dan + + + 1 sat + + + 1 milisekunda + + + 1 minut + + + 1 sekunda + + + bez proteklog vremena + + + {0} nedelja + + + 1 nedelja + + + za {0} dana + + + za {0} sati + + + za {0} minuta + + + za {0} meseci + + + za {0} sekundi + + + za {0} godina + + + sada + + + sutra + + + za sat vremena + + + za minut + + + za mesec dana + + + za sekund + + + za godinu dana + + + pre {0} dana + + + za {0} dana + + + pre {0} sata + + + za {0} sata + + + pre {0} minuta + + + za {0} minuta + + + pre {0} meseca + + + za {0} meseca + + + pre {0} sekunde + + + za {0} sekunde + + + pre {0} godine + + + za {0} godine + + + {0} dana + + + {0} sata + + + {0} milisekunde + + + {0} minuta + + + {0} sekunde + + + {0} nedelje + + + {0} meseci + + + {0} meseca + + + {0} godina + + + {0} godine + + + 1 mesec + + + 1 godina + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.sr.resx b/src/Humanizer/Properties/Resources.sr.resx index bd9d54e72..1d31059e3 100644 --- a/src/Humanizer/Properties/Resources.sr.resx +++ b/src/Humanizer/Properties/Resources.sr.resx @@ -285,4 +285,22 @@ {0} недеље + + {0} месеци + + + {0} месеца + + + {0} година + + + {0} године + + + 1 месец + + + 1 година + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.sv.resx b/src/Humanizer/Properties/Resources.sv.resx index 5a1fa791c..4a0131672 100644 --- a/src/Humanizer/Properties/Resources.sv.resx +++ b/src/Humanizer/Properties/Resources.sv.resx @@ -231,4 +231,16 @@ om ett år + + {0} månader + + + {0} år + + + en månad + + + ett år + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.tr.resx b/src/Humanizer/Properties/Resources.tr.resx index 0cc608d90..963a18c75 100644 --- a/src/Humanizer/Properties/Resources.tr.resx +++ b/src/Humanizer/Properties/Resources.tr.resx @@ -231,4 +231,16 @@ bir yıl sonra + + {0} ay + + + {0} yıl + + + 1 ay + + + 1 yıl + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.uk.resx b/src/Humanizer/Properties/Resources.uk.resx index dc3481968..1147b8176 100644 --- a/src/Humanizer/Properties/Resources.uk.resx +++ b/src/Humanizer/Properties/Resources.uk.resx @@ -339,4 +339,28 @@ через рік - + + {0} місяців + + + {0} місяці + + + {0} місяць + + + {0} років + + + {0} роки + + + {0} рік + + + один місяць + + + один рік + + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.uz-Cyrl-UZ.resx b/src/Humanizer/Properties/Resources.uz-Cyrl-UZ.resx index f6f910d3d..34ed648f4 100644 --- a/src/Humanizer/Properties/Resources.uz-Cyrl-UZ.resx +++ b/src/Humanizer/Properties/Resources.uz-Cyrl-UZ.resx @@ -204,12 +204,18 @@ {0} минут + + {0} ой + {0} секунд {0} ҳафта + + {0} йил + 1 кун @@ -222,12 +228,18 @@ 1 минут + + 1 ой + 1 секунд 1 ҳафта + + 1 йил + вақт йўқ diff --git a/src/Humanizer/Properties/Resources.uz-Latn-UZ.resx b/src/Humanizer/Properties/Resources.uz-Latn-UZ.resx index 4f9a367bc..00f28f865 100644 --- a/src/Humanizer/Properties/Resources.uz-Latn-UZ.resx +++ b/src/Humanizer/Properties/Resources.uz-Latn-UZ.resx @@ -204,12 +204,18 @@ {0} minut + + {0} oy + {0} sekund {0} hafta + + {0} yil + 1 kun @@ -222,12 +228,18 @@ 1 minut + + 1 oy + 1 sekund 1 hafta + + 1 yil + vaqt yo`q diff --git a/src/Humanizer/Properties/Resources.vi.resx b/src/Humanizer/Properties/Resources.vi.resx index e2e015a60..9a47069d1 100644 --- a/src/Humanizer/Properties/Resources.vi.resx +++ b/src/Humanizer/Properties/Resources.vi.resx @@ -231,4 +231,16 @@ một năm nữa + + {0} tháng + + + {0} năm + + + 1 tháng + + + 1 năm + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.zh-CN.resx b/src/Humanizer/Properties/Resources.zh-CN.resx index d080f8076..d54a24259 100644 --- a/src/Humanizer/Properties/Resources.zh-CN.resx +++ b/src/Humanizer/Properties/Resources.zh-CN.resx @@ -231,4 +231,16 @@ 明年 + + {0} 个月 + + + {0} 年 + + + 1 个月 + + + 1 年 + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.zh-Hans.resx b/src/Humanizer/Properties/Resources.zh-Hans.resx index d080f8076..d54a24259 100644 --- a/src/Humanizer/Properties/Resources.zh-Hans.resx +++ b/src/Humanizer/Properties/Resources.zh-Hans.resx @@ -231,4 +231,16 @@ 明年 + + {0} 个月 + + + {0} 年 + + + 1 个月 + + + 1 年 + \ No newline at end of file diff --git a/src/Humanizer/Properties/Resources.zh-Hant.resx b/src/Humanizer/Properties/Resources.zh-Hant.resx index 3f3823235..c8274e226 100644 --- a/src/Humanizer/Properties/Resources.zh-Hant.resx +++ b/src/Humanizer/Properties/Resources.zh-Hant.resx @@ -231,4 +231,16 @@ 明年 + + {0} 個月 + + + {0} 年 + + + 1 個月 + + + 1 年 + \ No newline at end of file diff --git a/src/Humanizer/TimeSpanHumanizeExtensions.cs b/src/Humanizer/TimeSpanHumanizeExtensions.cs index 522caaef7..e098c6c2f 100644 --- a/src/Humanizer/TimeSpanHumanizeExtensions.cs +++ b/src/Humanizer/TimeSpanHumanizeExtensions.cs @@ -13,8 +13,9 @@ namespace Humanizer /// public static class TimeSpanHumanizeExtensions { - private const int _lastTimeUnitTypeIndexImplemented = (int)TimeUnit.Week; private const int _daysInAWeek = 7; + private const double _daysInAYear = 365.2425; // see https://en.wikipedia.org/wiki/Gregorian_calendar + private const double _daysInAMonth = _daysInAYear / 12; /// /// Turns a TimeSpan into a human readable form. E.g. 1 day. @@ -22,7 +23,7 @@ public static class TimeSpanHumanizeExtensions /// /// The maximum number of time units to return. Defaulted is 1 which means the largest unit is returned /// Culture to use. If null, current thread's UI culture is used. - /// The maximum unit of time to output. + /// The maximum unit of time to output. The default value is . The time units and will give approximations for time spans bigger 30 days by calculating with 365.2425 days a year and 30.4369 days a month. /// The minimum unit of time to output. /// The separator to use when combining humanized time parts. If null, the default collection formatter for the current culture is used. /// @@ -38,7 +39,7 @@ public static string Humanize(this TimeSpan timeSpan, int precision = 1, Culture /// The maximum number of time units to return. /// Controls whether empty time units should be counted towards maximum number of time units. Leading empty time units never count. /// Culture to use. If null, current thread's UI culture is used. - /// The maximum unit of time to output. + /// The maximum unit of time to output. The default value is . The time units and will give approximations for time spans bigger than 30 days by calculating with 365.2425 days a year and 30.4369 days a month. /// The minimum unit of time to output. /// The separator to use when combining humanized time parts. If null, the default collection formatter for the current culture is used. /// @@ -78,14 +79,12 @@ private static IEnumerable CreateTheTimePartsWithUpperAndLowerLimits(Tim private static IEnumerable GetEnumTypesForTimeUnit() { var enumTypeEnumerator = (IEnumerable)Enum.GetValues(typeof(TimeUnit)); - enumTypeEnumerator = enumTypeEnumerator.Take(_lastTimeUnitTypeIndexImplemented + 1); - return enumTypeEnumerator.Reverse(); } private static string GetTimeUnitPart(TimeUnit timeUnitToGet, TimeSpan timespan, CultureInfo culture, TimeUnit maximumTimeUnit, TimeUnit minimumTimeUnit, IFormatter cultureFormatter) { - if(timeUnitToGet <= maximumTimeUnit && timeUnitToGet >= minimumTimeUnit) + if (timeUnitToGet <= maximumTimeUnit && timeUnitToGet >= minimumTimeUnit) { var isTimeUnitToGetTheMaximumTimeUnit = (timeUnitToGet == maximumTimeUnit); var numberOfTimeUnits = GetTimeUnitNumericalValue(timeUnitToGet, timespan, isTimeUnitToGetTheMaximumTimeUnit); @@ -111,21 +110,38 @@ private static int GetTimeUnitNumericalValue(TimeUnit timeUnitToGet, TimeSpan ti case TimeUnit.Week: return GetSpecialCaseWeeksAsInteger(timespan, isTimeUnitToGetTheMaximumTimeUnit); case TimeUnit.Month: - // To be implemented + return GetSpecialCaseMonthAsInteger(timespan, isTimeUnitToGetTheMaximumTimeUnit); case TimeUnit.Year: - // To be implemented + return GetSpecialCaseYearAsInteger(timespan); default: return 0; } } - private static int GetSpecialCaseWeeksAsInteger(TimeSpan timespan, bool isTimeUnitToGetTheMaximumTimeUnit) + private static int GetSpecialCaseMonthAsInteger(TimeSpan timespan, bool isTimeUnitToGetTheMaximumTimeUnit) { if (isTimeUnitToGetTheMaximumTimeUnit) + { + return (int)((double)timespan.Days / _daysInAMonth); + } + else + { + var remainingDays = (double)timespan.Days % _daysInAYear; + return (int)(remainingDays / _daysInAMonth); + } + } + + private static int GetSpecialCaseYearAsInteger(TimeSpan timespan) + { + return (int)((double)timespan.Days / _daysInAYear); + } + + private static int GetSpecialCaseWeeksAsInteger(TimeSpan timespan, bool isTimeUnitToGetTheMaximumTimeUnit) + { + if (isTimeUnitToGetTheMaximumTimeUnit || timespan.Days < _daysInAMonth) { return timespan.Days / _daysInAWeek; } - // To be implemented with the implementation of Month and Year return 0; } @@ -135,7 +151,12 @@ private static int GetSpecialCaseDaysAsInteger(TimeSpan timespan, bool isTimeUni { return timespan.Days; } - return timespan.Days % _daysInAWeek; + if (timespan.Days < _daysInAMonth) + { + var remainingDays = timespan.Days % _daysInAWeek; + return remainingDays; + } + return (int)((double)timespan.Days % _daysInAMonth); } private static int GetNormalCaseTimeAsInteger(int timeNumberOfUnits, double totalTimeNumberOfUnits, bool isTimeUnitToGetTheMaximumTimeUnit)