date-frequency

Temporal frequency library

npm install date-frequency
20 downloads in the last week
25 downloads in the last month

browser support

frequency Build status

Temporal frequency library

Example

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
  */

Methods

Frequency()

Constructor takes a string notation (also see toString()).

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). The optional 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

.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

  • 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

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.

npm loves you