Temporal frequency library
npm install date-frequency
|12||downloads in the last week|
|18||downloads in the last month|
|Version||0.3.1 last updated 4 days ago|
|Keywords||frequency, date, time, temporal, cron|
|Dependencies (11)||lodash.foreach, lodash.keys, lodash.indexof, lodash.first, lodash.last, lodash.rest, lodash.difference, lodash.union, lodash.reduce, lodash.pick, lodash.values|
Temporal frequency library
var frequency = new Frequency(); frequency.on('hour', 10) .on('minute', 30) .between(new Date(2013, 8, 2), new Date(2013, 8, 8, 23, 59)); /* returns an array with these dates: 2013-09-02 10:30:00 2013-09-03 10:30:00 2013-09-04 10:30:00 2013-09-05 10:30:00 2013-09-06 10:30:00 2013-09-07 10:30:00 2013-09-08 10:30:00 */
Constructor takes a string notation (also see
var frequency = Frequency('F3D/WT10H30M'); // every 3rd day of the week (Wednesday) at 10:30:00
.on(unit, fix, [of])
Add frequency rules by specifying a unit and a value to fix it to.
All units below the specified unit get fixed to the default (their value at the Unix epoch, 1970-01-01 00:00:00).
of parameter allows you to change the scope of the unit. By default each unit's scope is the unit above it in a regular date.
frequency.on('hour', 10); // sets the frequency to each day at 10:00:00 frequency.on('day', 6).on('hour', 10).on('minute', 30); // sets the frequency to the 6th day of each month at 12:30:00 frequency.on('day', 7, 'week'); // sets the frequency to Sundays at 00:00:00
Returns the next occurence of the frequency after the specified date.
Returns all occurences of the frequency between (and including) the specified start and end date.
Returns a string notation of the frequency (useful for storage).
- Add filters
- odd/even (compared to reference date, e.g. Unix epoch)
- nth ocurrence within scope (e.g. 2nd Thursday of the month)
- Remove dependencies
- Install latest node.js version.
git clone https://github.com/smhg/date-frequency-js.gitto fetch source.
npm installto install dependencies.
npm testto run tests.
The MIT License (MIT)
Copyright (c) Sam Hauglustaine
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.