4.0.0 • Published 3 years ago

date-period v4.0.0

Weekly downloads
120
License
MIT
Repository
github
Last release
3 years ago

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' });
4.0.0

3 years ago

3.0.0

4 years ago

2.5.1

4 years ago

2.5.0

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.0

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.1

6 years ago

2.2.0

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

0.3.2

7 years ago

2.0.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

9 years ago

0.5.0

9 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago