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 245 forks source link

`val(date)` modifies passed date instance #221

Open vfonic opened 6 years ago

vfonic commented 6 years ago

Hi,

I've just experienced this issue:

var time = date.toTimeString().split(' ')[0]; // get hour and minute (there are better ways to do this)
var sched = later.parse.recur().on(time).time();
var dayOfWeek = later.dayOfWeek.val(date); // NOTE this line might mess up your `date` instance

console.log(dayOfWeek); // 3
console.log(date); // { 2017-12-19T20:00:00.000Z dw: 3 }

The date instance got modified. Is this expected behavior? I continued using date below this code point and received errors. I expected that call to val() won't change my date instance.

It's because this line of code: https://github.com/bunkat/later/blob/5d38cc3779ad0ee42d61675c8209c1e47c07ca93/src/constraint/dayofweek.js#L29-L31