ranged-date
Converts a given string, number, or date to the number of milliseconds since the Unix epoch, provided that it can be recognized as seconds, milliseconds, or microseconds within a specified range in years from the current date.
Useful for parsing timestampted data from external APIs.

Getting Started
Prerequisites
Node.JS version 6.0.0 or above.
Installing
npm i ranged-date
Testing
The following command will test the package for errors.
npm test
Deployment
const rangedDate = require('ranged-date')
Usage
const time = ~~(Date.now() / 1000)
const past = time - 31536000
const future = time + 31536000
console.log(rangedDate(time))
console.log(rangedDate(time * 1000))
console.log(rangedDate(time * 1000 * 1000))
console.log(rangedDate(String(time)))
console.log(rangedDate(past))
console.log(rangedDate(past, 2))
console.log(rangedDate(future))
console.log(rangedDate(future, null, 2))
Documentation
rangedDate ⇒ number
| boolean
Returns: number
| boolean
- Converted ms or false if outside range.
Param | Type | Attributes | Default | Description |
---|
data | Date | number | string | | | Data to attempt to match. |
low | number | <optional> | 0.5 | Years before current date as lower bound. |
up | number | <optional> | 0.5 | Years after current date as upper bound. |
Source:
Documentation:
Versioning
Versioning using SemVer. For available versions, see the tags on this repository.
Author
License
This project is licensed under the ISC License - see the LICENSE.md file for details