Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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 string, number, or Date object 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.

  • 1.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-81.82%
Maintainers
1
Weekly downloads
 
Created
Source

ranged-date

NPM

Converts a given string, number, or Date object 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.
  • Integrating databases with mixed date formats.

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 recognize as valid date.
lownumber<optional>0.5Years before current date as lower bound.
upnumber<optional>0.5Years after current date as upper bound.
Source:
Documentation:

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

FAQs

Package last updated on 10 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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc