Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niksy/parse-human-date-range
Parse human-readable date to range of dates.
https://github.com/niksy/parse-human-date-range
Last synced: 7 days ago
JSON representation
Parse human-readable date to range of dates.
- Host: GitHub
- URL: https://github.com/niksy/parse-human-date-range
- Owner: niksy
- License: mit
- Created: 2016-10-17T10:39:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-17T10:43:58.000Z (about 8 years ago)
- Last Synced: 2024-10-27T03:46:18.120Z (19 days ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# parse-human-date-range
[![Build Status][ci-img]][ci]
Parse human-readable date to range of dates.
## Install
```sh
npm install parse-human-date-range --save
```## Usage
```js
var parse = require('human-date-range');parse('last 2 days');
/* [
Sat Oct 15 2016 14:00:00 GMT+0200 (CEST),
Sun Oct 16 2016 14:00:00 GMT+0200 (CEST)
] */parse('next 2 weeks');
/* [
Tue Oct 18 2016 14:00:00 GMT+0200 (CEST),
Wed Oct 19 2016 14:00:00 GMT+0200 (CEST),
Thu Oct 20 2016 14:00:00 GMT+0200 (CEST),
Fri Oct 21 2016 14:00:00 GMT+0200 (CEST),
Sat Oct 22 2016 14:00:00 GMT+0200 (CEST),
Sun Oct 23 2016 14:00:00 GMT+0200 (CEST),
Mon Oct 24 2016 14:00:00 GMT+0200 (CEST),
...
] */parse('last 2 tuesdays'):
/* [
Tue Oct 04 2016 14:00:00 GMT+0200 (CEST),
Tue Oct 11 2016 14:00:00 GMT+0200 (CEST)
] */```
More usage examples can be found in [tests](test/index.js).
## API
### parse(str, [offset])
Returns: `Date[]`
Parses human-readable date into range of dates. Unparseable string will return array with `offset` date.
#### str
Type: `String`
Human-readable date.
#### offset
Type: `Date`
Default: `new Date()`Date offset which will be used as starting point for calculation.
## License
MIT © [Ivan Nikolić](http://ivannikolic.com)
[ci]: https://travis-ci.org/niksy/parse-human-date-range
[ci-img]: https://img.shields.io/travis/niksy/parse-human-date-range.svg