By default, months and years are not supported, since these aren't
likely to be useful in the majority of cases and they introduce
ambiguity due to leap years and length differences between months.
By default, months and years are not supported, since these aren't
likely to be useful in the majority of cases and they introduce
ambiguity due to leap years and length differences between months.
By default, months and years are not supported, since these aren't
likely to be useful in the majority of cases and they introduce
ambiguity due to leap years and length differences between months.
By default, months and years are not supported, since these aren't
likely to be useful in the majority of cases and they introduce
ambiguity due to leap years and length differences between months.
By default, months and years are not supported, since these aren't
likely to be useful in the majority of cases and they introduce
ambiguity due to leap years and length differences between months.
You can use parseDuration instead for a light wrapper that
doesn't require the new keyword.
See
parseDuration
parseDuration
for more information.
@version ― 12.6.0
DurationParser()
constparser:DurationParser<never, never>
parser.
QuantityParser<"week"|"day"|"hour"|"minute"|"second"|"millisecond", "w"|"d"|"h"|"m"|"s"|"ms">.parse(quantity: QuantityString<"week"|"day"|"hour"|"minute"|"second"|"millisecond", "w"|"d"|"h"|"m"|"s"|"ms">): number
Parse a quantity string into its numeric value
@throws ― {Error} If the quantity string is invalid or contains an unknown unit
parse('1 hour') // => 3_600_000
constparser:DurationParser<never, never>
parser.
QuantityParser<"week"|"day"|"hour"|"minute"|"second"|"millisecond", "w"|"d"|"h"|"m"|"s"|"ms">.parse(quantity: QuantityString<"week"|"day"|"hour"|"minute"|"second"|"millisecond", "w"|"d"|"h"|"m"|"s"|"ms">): number
Parse a quantity string into its numeric value
@throws ― {Error} If the quantity string is invalid or contains an unknown unit
parse('1ms') // => 1
constparser:DurationParser<never, never>
parser.
QuantityParser<"week"|"day"|"hour"|"minute"|"second"|"millisecond", "w"|"d"|"h"|"m"|"s"|"ms">.parse(quantity: QuantityString<"week"|"day"|"hour"|"minute"|"second"|"millisecond", "w"|"d"|"h"|"m"|"s"|"ms">): number
Parse a quantity string into its numeric value
@throws ― {Error} If the quantity string is invalid or contains an unknown unit
parse('1.5 hours') // => 5_400_000
The units supported by default are:
millisecond (alias: ms)
second (alias: s)
minute (alias: m)
hour (alias: h)
day (alias: d)
week (alias: w)
Years and months are not supported by default, because both vary in length (e.g. leap years, not all months have 30 days). See the next section for how to add custom units.
Custom units
You may pass additional units to the parseDuration function.
By default, months and years are not supported, since these aren't
likely to be useful in the majority of cases and they introduce
ambiguity due to leap years and length differences between months.