Skip to content

Commit

Permalink
Merge pull request #1097 from hangy/register-ms
Browse files Browse the repository at this point in the history
Register Malaysian formatter
  • Loading branch information
clairernovotny committed Jul 3, 2021
2 parents ef87a53 + d651b88 commit c4d9914
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
Expand Up @@ -114,6 +114,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ko-KR\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ku\NumberToWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ku\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\ms-MY\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\mt\DateHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\mt\NumberToWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\mt\TimeSpanHumanizeTests.cs" />
Expand Down
@@ -0,0 +1,98 @@
using System;
using Xunit;

namespace Humanizer.Tests.Localisation.msMY
{
[UseCulture("ms-MY")]
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]
[Trait("Translation", "Google")]
[InlineData(7, "1 minggu")]
[InlineData(14, "2 minggu")]
public void Weeks(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}

[Theory]
[Trait("Translation", "Google")]
[InlineData(1, "1 hari")]
[InlineData(2, "2 hari")]
public void Days(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}

[Theory]
[Trait("Translation", "Google")]
[InlineData(1, "1 jam")]
[InlineData(2, "2 jam")]
public void Hours(int hours, string expected)
{
Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize());
}

[Theory]
[Trait("Translation", "Google")]
[InlineData(1, "1 minit")]
[InlineData(2, "2 minit")]
public void Minutes(int minutes, string expected)
{
Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize());
}

[Theory]
[Trait("Translation", "Google")]
[InlineData(1, "1 saat")]
[InlineData(2, "2 saat")]
public void Seconds(int seconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize());
}

[Theory]
[Trait("Translation", "Google")]
[InlineData(1, "1 milisaat")]
[InlineData(2, "2 milisaat")]
public void Milliseconds(int milliseconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize());
}

[Fact]
[Trait("Translation", "Google")]
public void NoTime()
{
Assert.Equal("0 milisaat", TimeSpan.Zero.Humanize());
}

[Fact]
public void NoTimeToWords()
{
Assert.Equal("tiada masa", TimeSpan.Zero.Humanize(toWords: true));
}
}
}
3 changes: 2 additions & 1 deletion src/Humanizer/Configuration/FormatterRegistry.cs
Expand Up @@ -43,6 +43,7 @@ public FormatterRegistry() : base(new DefaultFormatter("en-US"))
RegisterDefaultFormatter("ja");
RegisterDefaultFormatter("ko-KR");
Register("mt", new MalteseFormatter("mt"));
RegisterDefaultFormatter("ms-MY");
RegisterDefaultFormatter("nb");
RegisterDefaultFormatter("nb-NO");
RegisterDefaultFormatter("nl");
Expand All @@ -66,7 +67,7 @@ private void RegisterDefaultFormatter(string localeCode)
catch (CultureNotFoundException)
{
// Some OS's may not support the particular culture. Not much we can do for those.
}
}
}

private void RegisterCzechSlovakPolishFormatter(string localeCode)
Expand Down

0 comments on commit c4d9914

Please sign in to comment.