Skip to content

Function: parseDuration() ​

parseDuration(duration): number

Parse a duration into milliseconds, as @Schedule reads its intervals.

Parameters ​

duration ​

string | number

A number of milliseconds, or a text of numbers with their units (ms, s, m, h, d), summed and case-insensitive: 500ms, 30s, 1.5h, 1h 30m, 1d.

Returns ​

number

The duration in milliseconds.

Throws ​

When the duration is not positive (or not finite), or the text has an unknown part.

Example ​

typescript
import {parseDuration} from 'lakutata/com/entrypoint'

console.log(parseDuration('1h30m')) //5400000
console.log(parseDuration('500ms')) //500
console.log(parseDuration(2000)) //2000

Released under the MIT License.