Skip to content

Investigate if Temporal could replace ms #274

@styfle

Description

@styfle

Now that Temporal ships in most browsers and will likely ship in a future version of Node.js, we should see if it could replace ms.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal#browser_compatibility

A few examples:

Temporal.Duration.from({ seconds: 5 }).total({ unit: 'milliseconds' });  // 5000
Temporal.Duration.from({ minutes: 3 }).total({ unit: 'milliseconds' });  // 180000
Temporal.Duration.from({ hours: 2 }).total({ unit: 'milliseconds' }); // 7200000
Temporal.Duration.from({ days: 1 }).total({ unit: 'milliseconds' }); // 86400000

There is even short hand string syntax (ISO 8601) such as:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#iso_8601_duration_format

Temporal.Duration.from('PT5S').total({ unit: 'milliseconds' });  // 5000
Temporal.Duration.from('PT3M').total({ unit: 'milliseconds' });  // 180000
Temporal.Duration.from('PT2H').total({ unit: 'milliseconds' }); // 7200000
Temporal.Duration.from('P1D').total({ unit: 'milliseconds' }); // 86400000

There are still other features to consider and it only makes sense if we can make ms smaller than it already is.

In an ideal world, you wouldn't need to install ms at all 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions