Defined time-periods constants for Javascript, in milliseconds. Exposed as functions to make mis-typing fail noisily, rather than manifesting as NaN
s in your data.
var periods = require("periods");
var twentyFourHoursLater = Date.now() + periods.day();
var week = periods.week;
var durations = [1,2,3];
var weekDurations = durations.map(week);
Works in browser too.
Each method has a plural defined. e.g seconds()
, monthsRough()
n * 1000
n * 60 * second
n * 60 * minute
n * 24 * hour
n * 7 * day
n * 4.3 * week
n * 365.25 * day