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 millisecond, second, or microsecond time within a specified range from the current date.

  • 2.0.1
  • 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 millisecond, second, or microsecond time within a specified range from the current date.

Milliseconds, seconds, or microseconds may be excluded as possibilities for range matching.

Useful for:

  • Parsing timestampted data from external APIs.
  • Integrating collections containing mixed timestamp formats.

MIGRATION NOTICE:

  • ranged-date 2.0.0: back and forward ranges are now mandatory (were 0.5 each by default in 1.x.x).
  • ranged-date 2.0.0: Date Objects with values outside of the specified range will return false (would return Date Object in 1.x.x).

Getting Started

Prerequisites

Node.JS version 6.0.0 or above.

Installing

npm i ranged-date

Testing

The following commands will test the package for errors.

cd /path/to/node_modules/ranged-date
npm test

Documentation

Table of Contents

ranged-date

index.js:142-167

Converts a given string, number, or Date object to the number of milliseconds since the Unix epoch, provided that it can be recognized as millisecond, second, or microsecond time within a specified range from the current date.

Parameters
  • data (Date | number | string) Data to attempt to recognize as valid date.
  • yrBack number Years before current date as lower bound.
  • yrFwd number Years after current date as upper bound.
  • exclusions Object Specifies interpretation exclusions, if any.
    • exclusions.us boolean Exclude microseconds interpretation.
    • exclusions.ms boolean Exclude milliseconds interpretation.
    • exclusions.s boolean Exclude seconds interpretation.
Examples
// All return current time in ms
rangedDate(new Date(), 1, 1)
rangedDate(Date.now(), 1, 1)
rangedDate(new Date().toString(), 1, 1)
rangedDate(String(Date.now()), 1, 1)

// All return false
rangedDate(Date.now() - 10000000, 0.0000001, 0.0000001)
rangedDate(Date.now(), 1, 1, {ms: true})

// All throw cert-is TypeAssertionErrors
rangedDate()
rangedDate(new Date())
rangedDate({})
rangedDate(328385)

// Throws cert-is RangeAssertionError
rangedDate(Date.now(), -1, -1)
  • Throws (cert-is.TypeAssertionError | cert-is.RangeAssertionError) Throws an assertion error if parameter requirements are not met.

Returns (number | boolean) Converted time in ms or false if outside range.

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 13 Jun 2019

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