Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smhg/date-interval-js
Time intervals with algebraic operations
https://github.com/smhg/date-interval-js
Last synced: about 2 months ago
JSON representation
Time intervals with algebraic operations
- Host: GitHub
- URL: https://github.com/smhg/date-interval-js
- Owner: smhg
- License: mit
- Created: 2015-08-02T12:11:25.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-02-29T22:45:53.000Z (almost 5 years ago)
- Last Synced: 2024-11-16T16:17:15.186Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 27.3 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
date-interval [![Build status](https://api.travis-ci.org/smhg/date-interval-js.png)](https://travis-ci.org/smhg/date-interval-js)
======
Algebraic operations for time intervals.## Installation
```bash
$ npm install @smhg/date-interval
```## Usage
```javascript
import Interval from '@smhg/date-interval';// with ISO 8601 string
let interval1 = Interval('2015-08-03T12:00:00Z/2015-08-04T12:00:00Z');// with 2 dates
let interval2 = Interval(new Date('2015-08-03T12:00:00Z'), new Date('2015-08-04T12:00:00Z'));
```## API
### Interval()
#### Interval(String)
Pass an ISO 8601 time interval formatted string to create an interval.#### Interval(Date, Date)
Pass a start and end Date object to create an interval.### interval.toString()
Returns the interval as an ISO 8601 formatted string.### interval.overlaps(Interval)
Returns whether both intervals overlap.### interval.union(Interval)
Returns an array with the result of a merge of both intervals.### interval.diff(Interval)
Returns an array with the difference of both intervals.### interval.intersection(Interval)
Returns the interval that lies at the intersection of both intervals (if any).