Socket
Book a DemoInstallSign in
Socket

ranged-date

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ranged-date

Converts a given input to the number of milliseconds since the Unix epoch, provided that it can be parsed and recognized as seconds, milliseconds, or microseconds within a specified range in years from the current date.

1.0.4
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

ranged-date

Converts a given input to the number of milliseconds since the Unix epoch, provided that it can be parsed and 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) // Test unixtime in seconds
const past   = time - 31536000       // One year prior
const future = time + 31536000       // One year after

console.log(rangedDate(time))               // converted time in ms
console.log(rangedDate(time * 1000))        // converted time in ms
console.log(rangedDate(time * 1000 * 1000)) // converted time in ms
console.log(rangedDate(String(time)))       // converted time in ms
console.log(rangedDate(past))               // false
console.log(rangedDate(past, 2))            // converted time in ms
console.log(rangedDate(future))             // false
console.log(rangedDate(future, null, 2))    // converted time in ms

Documentation

rangedDate ⇒ number | boolean

Returns: number | boolean - Converted ms or false if outside range.

ParamTypeAttributesDefaultDescription
dataDate | number | stringData to attempt to match.
lownumber<optional>0.5Years before current date as lower bound.
upnumber<optional>0.5Years after current date as upper bound.

Please refer to the API docs for more detailed usage examples. Global functions are documented here.

Versioning

Versioning using SemVer. For available versions, see the tags on this repository.

Author

  • Justin Collier - jpcx

License

This project is licensed under the ISC License - see the LICENSE.md file for details

Keywords

date

FAQs

Package last updated on 05 Apr 2018

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.