1.0.1 • Published 7 years ago

cache-datetime v1.0.1

Weekly downloads
3
License
Apache 2.0
Repository
github
Last release
7 years ago

cache-datetime

A datetime factory that works well with cached API and Web requests, by rounding to a minutes value.

Install

npm install --save cache-datetime

or

yarn add cache-datetime

Example

const cacheDatetime = require('cache-datetime');

// current epoch rounded down to the last five minutes (default)
const myDatetime5 = cacheDatetime();

// specified epoch rounded down to the last ten minutes
const myDatetime10 = cacheDatetime({ minutes: 10, date: 1496754264 });

// current epoch rounded up to the nearest 10 minutes
const myDatetimeUp10 = cacheDatetime({ minutes: 10, round: Math.ceil });

// current Date object rounded down to the nearest 5 minutes 
const myDateObject = cacheDatetime({ epoch: false });

Constructor

const cacheDatetime = require('cache-datetime');

// defaults shown
new cacheDatetime({
  minutes: 5, // number of minutes rounded
  round: Math.floor, // function to round epoch 
  epoch: true, // return as epoch value or Date object (false)
  date: Date.now() // the date to round
})
1.0.1

7 years ago

1.0.0

7 years ago