🚀 DAY 2 OF LAUNCH WEEK: Unify Your Security Stack with Socket Basics.Learn more →
Socket
Book a DemoInstallSign in
Socket

temporal-constants

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

temporal-constants

Constants to compute with time units without magic numbers.

latest
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

Temporal Constants

Constants to compute with time units without magic numbers.

Why?

How often do you have to do some calculations to convert seconds to milliseconds, hours to days, or any number of others? Does everyone looking at your code understand why you are multipling a number of days by 86400?

We use these constant values in computations all the time in code, yet we also know that magic numbers are to be avoided:

Unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants -- Wikipedia

This tiny library defines those constants for you, so now instead of:

Math.round(ms / 60000), you can write Math.round(ms / MillisecondsInMinute)

Or in place of: setTimer(() => runMyFunction(), 24*60*60*1000)

you get the clearer (and faster): setTimer(() => runMyFunction(), MillisecondsInDay).

Compatibility

Compatible with Javascript ES2015/ES6 and newer, as well as Typescript.

FAQ

Q: Why should I introduce another dependency for a few constants that I can define myself?

A: Have you defined them? Did you make any mistakes computing them?

If you don't want a dependency, feel free to copy the lines into your own source. In this case, the times they are not a-changin'.

See also....

  • temporal-types - Typescript types for time units
  • js-joda - Complete library for date and time representation and manipulation

Keywords

time

FAQs

Package last updated on 14 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts