Humanizer.DefaultFormatter
DefaultFormatter Class
Provides the standard formatter implementation for Humanizer locales.
public class DefaultFormatter : Humanizer.IGrammaticalCaseTimeSpanFormatter, Humanizer.IFormatter
Inheritance System.Object → DefaultFormatter
Implements IGrammaticalCaseTimeSpanFormatter, IFormatter
Constructors
DefaultFormatter(string) Constructor
Initializes a new formatter for the specified locale code.
public DefaultFormatter(string localeCode);
Parameters
localeCode System.String
The locale code used to construct the formatter culture.
DefaultFormatter(CultureInfo) Constructor
Initializes a new formatter for the specified culture.
public DefaultFormatter(System.Globalization.CultureInfo culture);
Parameters
culture System.Globalization.CultureInfo
The culture used to resolve resources and localized number words.
Properties
DefaultFormatter.Culture Property
Gets the culture used to resolve resources and localized number words.
protected System.Globalization.CultureInfo Culture { protected get; }
Property Value
System.Globalization.CultureInfo
Methods
DefaultFormatter.DataUnitHumanize(DataUnit, double, bool) Method
Returns the localized representation of a data unit, either as a symbol or a full word.
public virtual string DataUnitHumanize(Humanizer.DataUnit dataUnit, double count, bool toSymbol=true);
Parameters
dataUnit DataUnit
The data unit to format.
count System.Double
The number of units being described.
toSymbol System.Boolean
Whether the unit should be rendered as a symbol.
Implements DataUnitHumanize(DataUnit, double, bool)
Returns
System.String
The localized data-unit representation.
Exceptions
System.ArgumentOutOfRangeException
If dataUnit is unsupported.
DefaultFormatter.DateHumanize(TimeUnit, Tense, int) Method
Returns the localized representation of a relative date phrase.
public virtual string DateHumanize(Humanizer.TimeUnit timeUnit, Humanizer.Tense timeUnitTense, int unit);
Parameters
timeUnit TimeUnit
The unit being described.
timeUnitTense Tense
Whether the reference is in the past or the future.
unit System.Int32
The number of units being described.
Implements DateHumanize(TimeUnit, Tense, int)
Returns
System.String
The localized relative date phrase.
Exceptions
System.ArgumentOutOfRangeException
If timeUnit is unsupported or unit is negative.
DefaultFormatter.DateHumanize_Never() Method
Returns the localized text used when a date never occurs.
public virtual string DateHumanize_Never();
Implements DateHumanize_Never()
Returns
DefaultFormatter.DateHumanize_Now() Method
Returns the localized text for the current moment.
public virtual string DateHumanize_Now();
Implements DateHumanize_Now()
Returns
DefaultFormatter.NumberToWords(TimeUnit, int, CultureInfo) Method
Converts a number to words for the current culture.
protected virtual string NumberToWords(Humanizer.TimeUnit unit, int number, System.Globalization.CultureInfo culture);
Parameters
unit TimeUnit
The unit being formatted.
number System.Int32
The numeric value to convert.
culture System.Globalization.CultureInfo
The culture to use when generating the words.
Returns
System.String
The number rendered as words for the configured culture.
DefaultFormatter.TimeSpanHumanize(TimeUnit, int, bool) Method
Returns the localized representation of a duration.
public virtual string TimeSpanHumanize(Humanizer.TimeUnit timeUnit, int unit, bool toWords=false);
Parameters
timeUnit TimeUnit
The unit being described.
unit System.Int32
The number of units being described.
toWords System.Boolean
Whether the number should be rendered as words.
Implements TimeSpanHumanize(TimeUnit, int, bool)
Returns
System.String
The localized duration phrase.
Exceptions
System.ArgumentOutOfRangeException
If timeUnit is unsupported or unit is negative.
DefaultFormatter.TimeSpanHumanizeWithFractionalSeconds(decimal, bool) Method
Returns the localized representation of a non-negative seconds value.
public virtual string TimeSpanHumanizeWithFractionalSeconds(decimal seconds, bool toSymbols);
Parameters
seconds System.Decimal
The non-negative seconds value to format.
toSymbols System.Boolean
Whether the seconds unit is rendered as a symbol.
Returns
System.String
The localized seconds value.
DefaultFormatter.TimeSpanHumanize_Age() Method
Returns the localized age suffix format for a humanized duration.
public virtual string TimeSpanHumanize_Age();
Implements TimeSpanHumanize_Age()
Returns
System.String
The localized age suffix format.
DefaultFormatter.TimeSpanHumanize_Zero() Method
Returns the localized representation of a zero-length duration.
public virtual string TimeSpanHumanize_Zero();
Implements TimeSpanHumanize_Zero()
Returns
System.String
The localized zero-duration phrase.
DefaultFormatter.TimeUnitHumanize(TimeUnit) Method
Returns the localized symbol for the given TimeUnit.
public virtual string TimeUnitHumanize(Humanizer.TimeUnit timeUnit);
Parameters
timeUnit TimeUnit
The time unit to format.
Implements TimeUnitHumanize(TimeUnit)
Returns
System.String
The localized symbol for timeUnit.
Exceptions
System.ArgumentOutOfRangeException
If timeUnit is unsupported.
Explicit Interface Implementations
Humanizer.IGrammaticalCaseTimeSpanFormatter.TimeSpanHumanize(TimeUnit, int, GrammaticalCase) Method
string Humanizer.IGrammaticalCaseTimeSpanFormatter.TimeSpanHumanize(Humanizer.TimeUnit timeUnit, int unit, Humanizer.GrammaticalCase grammaticalCase);
Parameters
timeUnit TimeUnit
unit System.Int32
grammaticalCase GrammaticalCase