javascript - date loop increment and growing variable ( mootools ) -
can please take @ fresh eyes.
var start_date = date.parse('2013-07-01'); var i_date = date.parse('2013-07-5'); console.log(start_date + '---before loop '); (var n = start_date; n < i_date; n.increment()) { console.log(start_date + '---inside loop '); } console.log(start_date + '---after loop ');
this code produces this:
mon jul 01 2013 00:00:00 gmt+0200 (w. europe daylight time)---before loop mon jul 01 2013 00:00:00 gmt+0200 (w. europe daylight time)---inside loop tue jul 02 2013 00:00:00 gmt+0200 (w. europe daylight time)---inside loop wed jul 03 2013 00:00:00 gmt+0200 (w. europe daylight time)---inside loop thu jul 04 2013 00:00:00 gmt+0200 (w. europe daylight time)---inside loop fri jul 05 2013 00:00:00 gmt+0200 (w. europe daylight time)---after loop
why start_date variable grow?
(fiddle here if needed)
the problem n
, start_date
pointing same object. need clone date creating new date
object, example:
n = new date(start_date);
example:
> = new date() sun jul 07 2013 19:51:09 gmt+0600 (ekaterinburg standard time) > b = sun jul 07 2013 19:51:09 gmt+0600 (ekaterinburg standard time) > c = new date(a) sun jul 07 2013 19:51:09 gmt+0600 (ekaterinburg standard time) // stuff "a" > sat jun 29 2013 19:51:09 gmt+0600 (ekaterinburg standard time) > b sat jun 29 2013 19:51:09 gmt+0600 (ekaterinburg standard time) > c sun jul 07 2013 19:51:09 gmt+0600 (ekaterinburg standard time)
Comments
Post a Comment