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.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

ranged-date

NPM

NPM NPM NPM NPM NPM NPM

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).

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.

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

API

Table of Contents

ranged-date

index.js:150-178

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. (optional, default false)
    • exclusions.ms boolean Exclude milliseconds interpretation. (optional, default false)
    • exclusions.s boolean Exclude seconds interpretation. (optional, default false)
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)

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

module:cert-is.TypeAssertionError

index.js:150-178

Thrown by cert-is in response to a type assertion error.

Type: Error

module:cert-is.RangeAssertionError

index.js:150-178

Thrown by cert-is in response to a range assertion error.

Type: Error

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 15 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