- DurationParser
- DurationTranslator
- DurationValidator
Validate duration string without doing a conversion
- TimeConverter
Allow time conversion between units
- TimeGroups
Manage time groups and make some operations on them.
- TimeIdentifiers
Manage time identifiers used in duration string. This class allows to use time identifiers from many languages.
Kind: global class
- DurationParser
- new DurationParser(locale, customTimeIdentifiers)
- .parse(input, targetUnit) ⇒
number
|null
- .compose(time, sourceUnit, groupSeparator) ⇒
string
|null
Param | Type | Default | Description |
---|---|---|---|
locale | string |
"en" |
Locale used for parsing duration |
customTimeIdentifiers | TimeIdentifiers | null |
|
Custom TimeIdentifiers object with added localized identifiers |
Return duration length from input expressed in target units
Kind: instance method of DurationParser
Param | Type | Default | Description |
---|---|---|---|
input | string |
Input duration string expressed in human-like pattern | |
targetUnit | m |
Identifier of target time unit |
Create duration string from time amount
Kind: instance method of DurationParser
Param | Default | Description |
---|---|---|
time | input time amount expressed in source time unit | |
sourceUnit | m |
Source time unit identifier |
groupSeparator | |
Group separator used to join time groups in output duration string |
Kind: global class
Param | Type |
---|---|
timeIdentifiers | TimeIdentifiers | null |
Translate duration string from source to target locale
Kind: instance method of DurationTranslator
Param | Description |
---|---|
duration | Input duration string |
sourceLocale | Source locale name |
targetLocale | Target locale name |
Validate duration string without doing a conversion
Kind: global class
Param | Type | Default |
---|---|---|
timeIdentifiers | TimeIdentifiers | null |
|
Validate if duration string meets all syntactic requirements
Kind: instance method of DurationValidator
Param | Type | Default | Description |
---|---|---|---|
duration | string |
Duration string expressed in human-like format | |
locale | string |
"en" |
Locale name which is used in duration string |
Allow time conversion between units
Convert time number expressed in source unit to number expressed in target unit; both units are basic one (en)
Kind: instance method of TimeConverter
Param | Type | Description |
---|---|---|
time | number |
Input time number |
sourceUnit | string |
Source time unit |
targetUnit | string |
Target time unit |
Manage time groups and make some operations on them.
Kind: global class
- TimeGroups
- new TimeGroups(timeIdentifiers)
- .extractTimeGroups(duration, locale) ⇒
Array.<string>
- .parseTimeGroup(timeGroup, locale) ⇒
Object
|null
- .buildTimeGroup(parsedTime) ⇒
string
- .composeDuration(timeGroups, groupSeparator) ⇒
string
Param | Type | Default |
---|---|---|
timeIdentifiers | TimeIdentifiers | null |
|
Extract array of time groups which are in duration string
Kind: instance method of TimeGroups
Param | Type | Description |
---|---|---|
duration | string |
Whole duration string |
locale | string |
Locale name of time identifiers used in duration string |
Parse single time group to object having information about both unit and number of it
Kind: instance method of TimeGroups
Param | Type | Description |
---|---|---|
timeGroup | string |
Single time group |
locale | string |
Locale name of time unit used in time group |
Build a single time group from object created while parsing a group
Kind: instance method of TimeGroups
Param | Type | Description |
---|---|---|
parsedTime | Object |
Object of parsed time group |
Compose the whole duration string from array of time groups; given separator is used to join all groups
Kind: instance method of TimeGroups
Param | Type | Default | Description |
---|---|---|---|
timeGroups | Array.<string> |
Array of time groups in the same locale as for output | |
groupSeparator | string |
" " |
Separator between every group in output duration string |
Manage time identifiers used in duration string. This class allows to use time identifiers from many languages.
Kind: global class
- TimeIdentifiers
- .add(locale, newIdentifiers) ⇒
TimeIdentifiers
- .get(locale) ⇒
Object
- .getInternalUnit(identifier, locale) ⇒
string
|null
- .add(locale, newIdentifiers) ⇒
timeIdentifiers.add(locale, newIdentifiers) ⇒ TimeIdentifiers
Register new time identifiers for the given locale
Kind: instance method of TimeIdentifiers
Param | Type | Description |
---|---|---|
locale | string |
Name of locale for which time identifiers are registered |
newIdentifiers | New time identifiers |
Return time identifiers for the given locale name; if not registered, return identifiers for 'en' locale
Kind: instance method of TimeIdentifiers
Param | Type | Description |
---|---|---|
locale | string |
Locale name |
Return internal unit (en) for the time unit in the specified locale
Kind: instance method of TimeIdentifiers
Param | Type | Description |
---|---|---|
identifier | string |
Localized time identifier |
locale | string |
Locale name |