frequency
Temporal frequency library
Example
var frequency = new Frequency();
frequency.on('hour', 10)
.on('minute', 30)
.on('second', 0)
.between(new Date(2013, 8, 2), new Date(2013, 8, 8, 23, 59));
Methods
Frequency()
Constructor takes a string notation (also see toString()
).
var frequency = Frequency('F3D/WT10H30M0S');
.on(unit, fix, scope)
Add frequency rules by specifying a unit and a value to fix it to and an optional scope.
The fix
parameter can also be an object containing 3 properties: fix
, scope
and fn
.
frequency.on('hour', 10).on('minute', 0).on('second', 0);
frequency.on('day', 6).on('m', 30).on('s', 0);
frequency.on('d', 7, 'week').on('h', 0).on('m', 0).on('s', 0);
Frequency.fn.even = require('number-kind').even;
frequency.on('week', {fn: 'even', scope: 'epoch'}).on('h', 0).on('m', 0).on('s', 0);
.next(date)
Returns the next occurence of the frequency after the specified date.
.between(start, end)
Returns all occurences of the frequency between (and including) the specified start and end date.
.toString()
Returns a string notation of the frequency (useful for storage).
Todo
- Enable filters (?) like n th ocurrence within scope (e.g. 2nd Thursday of month).
- Remove dependencies.
- Spend less time in loops.
Development
- Install latest node.js version.
git clone https://github.com/smhg/date-frequency-js.git
to fetch source.npm install
to install dependencies.npm test
to run tests.
License
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.