Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

date-period

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-period

Time period iterator

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

date-period ci

Time period iterator.

A time period in this context is an array of Date objects, recurring at regular intervals, over a given period. Based on ISO 8601's duration and repeating interval format.

Mimics PHP's excellent DatePeriod class.

Installation

$ npm install date-period --save

Use

API

Start, duration and end date:

createPeriod({ start: Date, duration: String, end: Date }) ⇒ Array<Date>

Start, duration, and number of recurrences:

createPeriod({ start: Date, duration: String, recurrence: Number }) ⇒ Array<Date>

ISO 8601 Repeating time intervals:

createPeriod({ iso: String }) ⇒ Array<Date>

Note: the date and duration parameters above can be objects which have, respectively, toDate and toString methods. This way moment objects are supported.

Example

Require the module

const createPeriod = require('date-period');
Define a period
let start = new Date('2014-01-01T00:00:00Z'),
	duration = 'P1D',
	end = new Date('2014-01-05T00:00:00Z'), // not included in result
	period;

period = createPeriod({ start, duration, end });

// or, with the number of recurrences instead of an end date:
period = createPeriod({ start, duration, recurrence: 3 });

// or, with a string formatted as an ISO 8601 repeating interval:
period = createPeriod({ iso: 'R3/2014-01-01T00:00:00Z/P1D' });

Keywords

FAQs

Package last updated on 22 Sep 2021

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