1

I got this strange JavaScript bug that I can seem to work arround or fix.

I am using some code to make 2 JavaScript dates, to insert events into a calendar component. The dates are built the following way:

var endDate = new Date();
var startDate = new Date();

startDate.setDate(startDateDay);
startDate.setMonth(startDateMonth);
startDate.setFullYear(startDateYear);
startDate.setHours(2, 0, 0, 0);

endDate.setDate(endDateDay);
endDate.setMonth(endDateMonth);
endDate.setFullYear(endDateYear);
endDate.setHours(2, 0, 0, 0);

So, the dates are built using integers. These integers are determined by input, and using the debugger I can see 100% positive they are coming in correctly. Now, ill describe 3 walkthroughs, 2 where it goes correctly and 1 where it goes wrong.


Using the following input:

endDateDay = 20
endDateMonth = 9
endDateYear = 2014

Gives the following date object as result:

Tue Oct 20 2014 02:00:00 GMT+0200 (W. Europe Daylight Time)

Using this input:

endDateDay = 13
endDateMonth = 9
endDateYear = 2014

Gives the following date object as result:

Tue Oct 13 2014 02:00:00 GMT+0200 (W. Europe Daylight Time)

Now, using this input:

endDateDay = 27
endDateMonth = 9
endDateYear = 2014

Gives the following date object as result:

Mon Oct 27 2014 02:00:00 **GMT+0100** (W. Europe Standard Time)

As you can see, for some strange reason the TimeZone is off. This gives errors in my application, and I need to find a way to get it fixed. Though, I cannot find any solution to it, let alone understand why it is actually happening.

PS: I am using Google Chrome

2
  • 1
    In what way is it off? The clocks in Western Europe go back to standard time on October 26th... what did you expect, and why? Commented Oct 8, 2014 at 11:54
  • Look at the tiemzones, one is Daylight time, the other is Standard time (though the timezone names may be different to what you're used to). Commented Oct 8, 2014 at 12:20

1 Answer 1

2

The answer was indeed the difference in the daylight savings time, which I completly oversaw. Thanks to finding this out I also found a solution to my problem.

I used this link to further assist me, might it help someone in the future: http://javascript.about.com/library/bldst.htm

Cheers!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.