-
Notifications
You must be signed in to change notification settings - Fork 970
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1106 from hangy/timeunit-humanize
- Loading branch information
Showing
11 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Humanizer.Tests.Shared/Localisation/de/TimeUnitToSymbolTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
using Humanizer.Localisation; | ||
|
||
using Xunit; | ||
|
||
namespace Humanizer.Tests.Localisation.de | ||
{ | ||
[UseCulture("de-DE")] | ||
public class TimeUnitToSymbolTests | ||
{ | ||
[Theory] | ||
[Trait("Translation", "Native speaker")] | ||
[InlineData(TimeUnit.Millisecond, "ms")] | ||
[InlineData(TimeUnit.Second, "s")] | ||
[InlineData(TimeUnit.Minute, "min")] | ||
[InlineData(TimeUnit.Hour, "h")] | ||
[InlineData(TimeUnit.Day, "d")] | ||
[InlineData(TimeUnit.Week, "Woche")] | ||
[InlineData(TimeUnit.Month, "M")] | ||
[InlineData(TimeUnit.Year, "a")] | ||
public void ToSymbol(TimeUnit unit, string expected) | ||
{ | ||
Assert.Equal(expected, unit.ToSymbol()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Humanizer.Localisation; | ||
|
||
using Xunit; | ||
|
||
namespace Humanizer.Tests | ||
{ | ||
[UseCulture("en-US")] | ||
public class TimeUnitToSymbolTests | ||
{ | ||
[Theory] | ||
[InlineData(TimeUnit.Millisecond, "ms")] | ||
[InlineData(TimeUnit.Second, "s")] | ||
[InlineData(TimeUnit.Minute, "min")] | ||
[InlineData(TimeUnit.Hour, "h")] | ||
[InlineData(TimeUnit.Day, "d")] | ||
[InlineData(TimeUnit.Week, "week")] | ||
[InlineData(TimeUnit.Month, "mo")] | ||
[InlineData(TimeUnit.Year, "y")] | ||
public void ToSymbol(TimeUnit unit, string expected) | ||
{ | ||
Assert.Equal(expected, unit.ToSymbol()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Humanizer.Localisation | ||
{ | ||
public partial class ResourceKeys | ||
{ | ||
/// <summary> | ||
/// Encapsulates the logic required to get the resource keys for TimeUnit.ToSymbol | ||
/// </summary> | ||
public static class TimeUnitSymbol | ||
{ | ||
/// <summary> | ||
/// Examples: TimeUnit_Minute, TimeUnit_Hour. | ||
/// </summary> | ||
private const string TimeUnitFormat = "TimeUnit_{0}"; | ||
|
||
/// <summary> | ||
/// Generates Resource Keys according to convention. | ||
/// </summary> | ||
/// <param name="unit">Time unit, <see cref="TimeUnit"/>.</param> | ||
/// <param name="count">Number of units, default is One.</param> | ||
/// <param name="toWords">Result to words, default is false.</param> | ||
/// <returns>Resource key, like TimeSpanHumanize_SingleMinute</returns> | ||
public static string GetResourceKey(TimeUnit unit) | ||
{ | ||
return TimeUnitFormat.FormatWith(unit); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Globalization; | ||
|
||
using Humanizer.Localisation; | ||
using Humanizer.Configuration; | ||
|
||
namespace Humanizer | ||
{ | ||
/// <summary> | ||
/// Transform a time unit into a symbol; e.g. <see cref="TimeUnit.Year"/> => "a" | ||
/// </summary> | ||
public static class TimeUnitToSymbolExtensions | ||
{ | ||
/// <summary> | ||
/// TimeUnit.Day.ToSymbol() -> "d" | ||
/// </summary> | ||
/// <param name="unit">Unit of time to be turned to a symbol</param> | ||
/// <param name="culture">Culture to use. If null, current thread's UI culture is used.</param> | ||
/// <returns></returns> | ||
public static string ToSymbol(this TimeUnit unit, CultureInfo culture = null) | ||
{ | ||
return Configurator.GetFormatter(culture).TimeUnitHumanize(unit); | ||
} | ||
} | ||
} |