Skip to main content
Version: 3.0.10 (latest)

Humanizer.DefaultFormatter

DefaultFormatter Class

Default implementation of IFormatter interface.

public class DefaultFormatter : Humanizer.IFormatter

Inheritance System.Object → DefaultFormatter

Implements IFormatter

Constructors

DefaultFormatter(string) Constructor

public DefaultFormatter(string localeCode);

Parameters

localeCode System.String

DefaultFormatter(CultureInfo) Constructor

Default implementation of IFormatter interface.

public DefaultFormatter(System.Globalization.CultureInfo culture);

Parameters

culture System.Globalization.CultureInfo

Properties

DefaultFormatter.Culture Property

protected System.Globalization.CultureInfo Culture { protected get; }

Property Value

System.Globalization.CultureInfo

Methods

DefaultFormatter.DataUnitHumanize(DataUnit, double, bool) Method

Returns the string representation of the provided DataUnit, either as a symbol or full word

public virtual string DataUnitHumanize(Humanizer.DataUnit dataUnit, double count, bool toSymbol=true);

Parameters

dataUnit DataUnit

Data unit

count System.Double

Number of said units, to adjust for singular/plural forms

toSymbol System.Boolean

Indicates whether the data unit should be expressed as symbol or full word

Implements DataUnitHumanize(DataUnit, double, bool)

Returns

System.String
String representation of the provided DataUnit

DefaultFormatter.DateHumanize(TimeUnit, Tense, int) Method

Returns the string representation of the provided DateTime

public virtual string DateHumanize(Humanizer.TimeUnit timeUnit, Humanizer.Tense timeUnitTense, int unit);

Parameters

timeUnit TimeUnit

timeUnitTense Tense

unit System.Int32

Implements DateHumanize(TimeUnit, Tense, int)

Returns

System.String

DefaultFormatter.DateHumanize_Never() Method

public virtual string DateHumanize_Never();

Implements DateHumanize_Never()

Returns

System.String

DefaultFormatter.DateHumanize_Now() Method

public virtual string DateHumanize_Now();

Implements DateHumanize_Now()

Returns

System.String

DefaultFormatter.Format(TimeUnit, string, int, bool) Method

Formats the specified resource key.

protected virtual string Format(Humanizer.TimeUnit unit, string resourceKey, int number, bool toWords=false);

Parameters

unit TimeUnit

resourceKey System.String

The resource key.

number System.Int32

The number.

toWords System.Boolean

Returns

System.String

Exceptions

System.ArgumentException
If the resource not exists on the specified culture.

DefaultFormatter.Format(string) Method

Formats the specified resource key.

protected virtual string Format(string resourceKey);

Parameters

resourceKey System.String

The resource key.

Returns

System.String

Exceptions

System.ArgumentException
If the resource not exists on the specified culture.

DefaultFormatter.GetResourceKey(string) Method

protected virtual string GetResourceKey(string resourceKey);

Parameters

resourceKey System.String

Returns

System.String

DefaultFormatter.GetResourceKey(string, int) Method

Override this method if your locale has complex rules around multiple units; e.g. Arabic, Russian

protected virtual string GetResourceKey(string resourceKey, int number);

Parameters

resourceKey System.String

The resource key that's being in formatting

number System.Int32

The number of the units being used in formatting

Returns

System.String

DefaultFormatter.NumberToWords(TimeUnit, int, CultureInfo) Method

protected virtual string NumberToWords(Humanizer.TimeUnit unit, int number, System.Globalization.CultureInfo culture);

Parameters

unit TimeUnit

number System.Int32

culture System.Globalization.CultureInfo

Returns

System.String

DefaultFormatter.TimeSpanHumanize(TimeUnit, int, bool) Method

Returns the string representation of the provided TimeSpan

public virtual string TimeSpanHumanize(Humanizer.TimeUnit timeUnit, int unit, bool toWords=false);

Parameters

timeUnit TimeUnit

A time unit to represent.

unit System.Int32

toWords System.Boolean

Implements TimeSpanHumanize(TimeUnit, int, bool)

Returns

System.String

Exceptions

System.ArgumentOutOfRangeException
Is thrown when timeUnit is larger than TimeUnit.Week

DefaultFormatter.TimeSpanHumanize_Age() Method

Returns the age format that converts a humanized TimeSpan string to an age expression. For instance, in English that format adds the " old" suffix, so that "40 years" becomes "40 years old".

public virtual string TimeSpanHumanize_Age();

Implements TimeSpanHumanize_Age()

Returns

System.String
Age format

DefaultFormatter.TimeSpanHumanize_Zero() Method

0 seconds

public virtual string TimeSpanHumanize_Zero();

Implements TimeSpanHumanize_Zero()

Returns

System.String
Returns 0 seconds as the string representation of Zero TimeSpan

DefaultFormatter.TimeUnitHumanize(TimeUnit) Method

Returns the symbol for the given TimeUnit

public virtual string TimeUnitHumanize(Humanizer.TimeUnit timeUnit);

Parameters

timeUnit TimeUnit

Time unit

Implements TimeUnitHumanize(TimeUnit)

Returns

System.String
String representation of the provided TimeUnit