New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
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

Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
134
11.67%
Maintainers
1
Weekly downloads
 
Created
Source

date-period Build status Coverage Status

Time period iterator.

A time period in this context is an iterable collection 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

date-period requires babel-polyfill.

$ npm install date-period babel-polyfill --save

Usage

1.x API note: a period instance is now an ES6 iterable (iterate with for ... of). In ES5 use-cases, you'll have to call toArray, on which you can then use the regular array-methods.

Period({start: Date, duration: String, end: Date})

Period({start: Date, duration: String, recurrence: Number})

Period({iso: String})

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 = Period({start, duration, end});

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

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

// in any case, period is an iterable object:
for (let date of period) {
	/**
	 * will go over these dates:
	 * 2014-01-01T00:00:00Z
	 * 2014-01-02T00:00:00Z
	 * 2014-01-03T00:00:00Z
	 * 2014-01-04T00:00:00Z
	 */
}

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

Keywords

time

FAQs

Package last updated on 26 Dec 2016

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