?
Referenced as Related to: # 4480
avatar purplebeanie
purplebeanie
8 Oct 2014

The DHTML calendar picker currently used defines a method setFullYear(year) that overrides the default JS setFullYear(year,month,day). http://www.w3schools.com/jsref/jsref_setfullyear.asp. Any scripts that use setFullYear on a page where calendar.js is being loaded and are expecting month and day parameters to be set will misbehave as only the year will be set and not the other fields.

This is defined on line 1793 of the uncompressed version (ie. calendar-uncompressed.js)

Steps to reproduce the issue

I've only tried this on J3.3.6.

  1. Make sure calendar.js is being loaded. Probably the easiest way is to add JHtml::_('behavior.calendar'); to your template index file.

  2. Open your site in a browser and then open Chrome developer tools. Go to the console and type:

date = new Date();

  1. Then change use the date.setFullYear function to change the date. Today is October the 8th so I decided to change it to Christmas day. ie.

date = new Date.setFullYear(2014,11,25); //month is 0 indexed so needs to be 11

  1. Then still at the console just find out what the current date is now set to either just type date or console.log(date) will do the trick.

The expected result would be:

Thu Dec 25 2014 10:26:15 GMT+1000 (EST)

The actual result is:

Wed Oct 08 2014 10:26:15 GMT+1000 (EST)

Only the year is actually being set.

Additional comments

If someone can verify this is a genuine bug I will work patch later this week or on the weekend.

Cheers,
Eric.

avatar purplebeanie purplebeanie - open - 8 Oct 2014
avatar Fedik
Fedik - comment - 8 Oct 2014

I can confirm it.

But your code for demonstration a bit wrong :smile:
date = new Date.setFullYear(2014,11,25); is not valid call...

Here is more simple (I hope :smile:), run next in the browser console (copy whole code -> paste -> push Enter):

// define date var:
var date = new Date();
// check the date:
console.log(date.toLocaleDateString());
// try change the date
date.setFullYear(2014,11,25);
// check result
console.log(date.toLocaleDateString());

Result:

08.10.2014 
08.10.2014 

Expected result:

08.10.2014 
25.12.2014 
avatar purplebeanie
purplebeanie - comment - 8 Oct 2014

@Fedik sorry yes you are correct...... that's what happens when I re-type instead of cut and paste!!!

Thanks for picking that up.

avatar Fedik
Fedik - comment - 8 Oct 2014

@purplebeanie the patch is welcome :wink:

avatar purplebeanie
purplebeanie - comment - 8 Oct 2014

@Fedik yep. will get a PR done tonight or tomorrow.

avatar Bakual
Bakual - comment - 8 Oct 2014

Closing this issue as we have a PR now. Please use #4480 for further comments.

avatar Bakual Bakual - close - 8 Oct 2014
avatar zero-24 zero-24 - close - 8 Oct 2014
avatar Bakual Bakual - change - 8 Oct 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-10-08 09:20:11
avatar zero-24 zero-24 - change - 7 Jul 2015
Labels Added: ?

Add a Comment

Login with GitHub to post a comment