bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
http://bunkat.github.io/later/
MIT License
2.42k stars 244 forks source link

later.recur.except() broken when setting local time zone #172

Open TimNZ opened 8 years ago

TimNZ commented 8 years ago

Generated schedule is correct if later.date.localTime() commented out I'm in NZST timezone

var later = require('later')
// later.date.UTC();
later.date.localTime();  // <-- except() below ignored if applied
var d = new Date();
var dY = later.dayOfYear.val(d) + 2; // June 21
var l =  later.parse.recur().on(8).hour().onWeekday()
            .except()
                .on(dY).dayOfYear()
console.log(later.schedule(l).next(10))

Working - commented out localTime()

[ Mon Jun 20 2016 20:00:00 GMT+1200 (NZST),
  Wed Jun 22 2016 20:00:00 GMT+1200 (NZST),
  Thu Jun 23 2016 20:00:00 GMT+1200 (NZST),
  Fri Jun 24 2016 20:00:00 GMT+1200 (NZST),
  Mon Jun 27 2016 20:00:00 GMT+1200 (NZST),
  Tue Jun 28 2016 20:00:00 GMT+1200 (NZST),
  Wed Jun 29 2016 20:00:00 GMT+1200 (NZST),
  Thu Jun 30 2016 20:00:00 GMT+1200 (NZST),
  Fri Jul 01 2016 20:00:00 GMT+1200 (NZST),
  Mon Jul 04 2016 20:00:00 GMT+1200 (NZST) ]

localTime() applied

[ Mon Jun 20 2016 08:00:00 GMT+1200 (NZST),
  Tue Jun 21 2016 08:00:00 GMT+1200 (NZST),
  Wed Jun 22 2016 08:00:00 GMT+1200 (NZST),
  Thu Jun 23 2016 08:00:00 GMT+1200 (NZST),
  Fri Jun 24 2016 08:00:00 GMT+1200 (NZST),
  Mon Jun 27 2016 08:00:00 GMT+1200 (NZST),
  Tue Jun 28 2016 08:00:00 GMT+1200 (NZST),
  Wed Jun 29 2016 08:00:00 GMT+1200 (NZST),
  Thu Jun 30 2016 08:00:00 GMT+1200 (NZST),
  Fri Jul 01 2016 08:00:00 GMT+1200 (NZST) ]
TimNZ commented 8 years ago

On further testing thankfully it is only an issue with dy/day of year constraint being applied when using localTime.

I've forked later to see if I can resolve it, but if you work on this again before I get a chance please fix.

Great library, thanks!