Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement TimeUnitToSymbolExtensions.ToSymbol method
- Loading branch information
Showing
7 changed files
with
124 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
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); | ||
} | ||
} | ||
} |