Sha256: 73457661712ce0c67b032e3cf5acb4d78dd426a124d63e198330cb41387cb204

Contents?: true

Size: 1.18 KB

Versions: 66

Compression:

Stored size: 1.18 KB

Contents

/**
* Modifier
* (c) 2013 Bill, BunKat LLC.
*
* Example of creating a custom modifier. See
* http://bunkat.github.io/later/modifiers.html#custom for more details.
*
* Later is freely distributable under the MIT license.
* For all details and documentation:
*     http://github.com/bunkat/later
*/

var later = require('../index');

// create the new modifier
later.modifier.month = later.modifier.m = function(period, values) {
  if(period.name !== 'month') {
    throw new Error('Month modifier only works with months!');
  }

  return {
    name:     'reIndexed ' + period.name,
    range:    period.range,
    val:      function(d) { return period.val(d) - 1; },
    isValid:  function(d, val) { return period.isValid(d, val+1); },
    extent:   function(d) { return [0, 11]; },
    start:    period.start,
    end:      period.end,
    next:     function(d, val) { return period.next(d, val+1); },
    prev:     function(d, val) { return period.prev(d, val+1); }
  };
};

// use our new modifier in a schedule
var sched = later.parse.recur().customModifier('m', 2).month(),
    next = later.schedule(sched).next(1, new Date(2013, 3, 21));

console.log(next.toUTCString());
// Sat, 01 Mar 2014 00:00:00 GMT

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
j1-template-2023.4.0 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.3.3 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.3.2 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.3.1 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.3.0 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.2.7 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.2.6 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.2.5 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.2.4 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.2.3 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.2.2 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.2.1 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.2.0 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.1.0 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.0.17 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.0.16 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.0.15 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.0.14 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.0.13 assets/themes/j1/modules/later/docs/example/modifier.js
j1-template-2023.0.12 assets/themes/j1/modules/later/docs/example/modifier.js