Skip to content

DurationFormatter

Type class

DurationFormatter class. Formats numbers as durations.

1000 as 16:40

More info: Formatting Duration Tutorial on duration formatting

Sources

DurationFormatter can be used (imported) via one of the following packages.

/**
* Import from: "core.ts"
* Use like: am4core.DurationFormatter
*/
import * as am4core from "@amcharts/amcharts4/core";

Inheritance

DurationFormatter extends BaseObject.

DurationFormatter is not extended by any other symbol.

Properties

baseUnit

Type TimeUnitDefault "s"

Base unit the values are in.

A base unit will be used to recalculate the numeric value to millisecond timestamps.

Available options:

  • "millisecond"

  • "second"

  • "minute"

  • "hour"

  • "day"

  • "week"

  • "month"

  • "year"

durationFormat

Type string

If set, this format will be used instead of the one determined dynamically based on the basedUnit and range of values.

More info: Formatting Duration Available fomatting codes

durationFormats

Type Partial <Record <TimeUnit, Partial <Record <TimeUnit, string>>>>

Duration formats for various combination of base units.

language

Type $type.Optional <Language>

Holds reference to Language object.

sprite

Type $type.Optional <Sprite>

Holds reference to parent Sprite object.

4 inherited items
clonedFrom

Type $type.Optional <this>Inherited from BaseObject

Reference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed.

config

Type objectInherited from BaseObject

Use this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc.

Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations.

id

Type $type.Optional <string>Inherited from BaseObject

Sets the user-defined id of the element.

uid

Type stringInherited from BaseObject

Returns object's internal unique ID.

Methods

constructor()

Returns DurationFormatter

Constructor

format(value: number | string,
format?: string,
base?: TimeUnit
)

Returns string

Formats the number according as duration.

For example 1000 (base unit seconds) would be converted to 16:40 as in 16 minutes and 40 seconds.

More info: Formatting Duration Tutorial on duration formatting

getFormat(value: number,
maxValue?: number,
baseUnit?: TimeUnit
)

Returns string

Returns appropriate default format for the value.

If maxValue is sepcified, it will use that value to determine the time unit for the format.

For example if your baseUnit is "second" and you pass in 10, you will get "10".

However, you might want it to be formatted in the context of bigger scale, say 10 minutes (600 seconds). If you pass in 600 as maxValue, all values, including small ones will use format with minutes, e.g.:

00:10, 00:50, 12: 30, etc.

getMilliseconds(value: number,
baseUnit?: TimeUnit
)

Returns number

Converts value to milliseconds according to baseUnit.

getValueUnit(value: number,
baseUnit?: TimeUnit
)

Returns TimeUnit

Returns value's closest denominator time unit, e.g 100 seconds is "minute", while 59 seconds would still be second.

toTimeStamp(value: number,
baseUnit: TimeUnit
)

Returns number

Converts numeric value to timestamp in milliseconds.

5 inherited items
clone(cloneId?: string)

Returns thisInherited from BaseObject

Makes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them.

copyFrom(object: this)

Returns voidInherited from BaseObject

Copies all properties and related data from different element.

dispose()

Returns voidInherited from BaseObject

Destroys this object and all related data.

getCurrentThemes()

Returns ITheme[]Inherited from BaseObject

Returns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide.

isDisposed()

Returns booleanInherited from BaseObject

Returns if this object has been already been disposed.

Events

DurationFormatter does not have any events.