Hi,
In a multilingual website FireBug spits "monthNames[month] is undefined" in clock.js at line 219 when visiting a page in a language other then english.
Doing further debugging I found that date.getMonth() was assigning NaN as a value for var month on line 215 as well as for all instances of object date, so that the why monthNames[month] gets undefined.
The culprit for all this lives at line 18 where the object date is created. The problem is that Drupal.settings['time'] assigns a translated string of current date into "new Date()" when the current language is not english. So, for instance, instead of December 15, 2010 it assigns Dezembro 15, 2010.
Any suggestion on how to get Drupal.settings['time'] in english even when the current language is not english?

Ah, by the way, this issue prevents the "Use JavaScript to continuously update the clock" functionality to work on any language but english.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

FranciscoLuz’s picture

Solution I came up with:

In clock.module file at line 275 change $format = 'F j, Y H:i:s' with $format = 'Y n j H:i:s' . In that way December 15, 2010 2:45:10 will became 2010 12 15 2:45:10 and no more translated string will be passed into clock.js

tstoeckler’s picture

Thanks very much for the bug report. It's actually a bug I had often come across, but never been able to reproduce, because my development boxes are always English....

I hope I have time to look into this the next days.

gionnibgud’s picture

This fix is not working in Safari.
The reason is explained here: http://stackoverflow.com/questions/4310953/invalid-date-in-safari

My solution was to change the $format variable in $format = 'n/j/Y H:i:s' (standard American 12/18/2010) and now it's working in all browsers.

cheers

FranciscoLuz’s picture

@gionnibgud
Weird!!! my Safari v5.0.3 on XP doesn't seems to be complaining about the format variable I am using ($format = 'Y n j H:i:s'), although the variable suggestion you've made works just fine as well. Thank you for the heads up anyway.

Cheers mate!

tstoeckler’s picture

The chosen format ("F j, Y H:i:s") is the format JavaScript likes to have its dates in (as far as I know). I guess we could change that to a different format and it might still work, but I think the correct fix is to generate the format in English.
date_format_date() luckily has the $langcode parameter, which allows that.
I've attached patches to all three branches, which should fix the issue (they did for me).
Please try them out and report if they fix it for you.
Thanks!

Status: Needs review » Needs work

The last submitted patch, months[month]_undefined-6.x-1.x.patch, failed testing.

gionnibgud’s picture

@tstoeckler

Format ("F j, Y H:i:s") is not working for me on OSX.
It fails with Safari 5.0.3, Firefox 3.6.13 and Chrome 8.something.
Format ('n/j/Y H:i:s') is still the one working all right.

FranciscoLuz’s picture

@tstoeckler #5
I wasn't aware of the $langcode parameter, well done, it worked as a charm for me on IE, Safari, FF and Chrome.
Cheers mate!

tstoeckler’s picture

@gionnibgud-#7: It's not clear to me, whether you applied the patch or not? Could you explain in detail whether it didn't work for you and what did?

tstoeckler’s picture

Status: Needs work » Needs review

http://drupal.org/cvs?commit=475830
http://drupal.org/cvs?commit=475832
http://drupal.org/cvs?commit=475834

I committed #5 to all branches. Since we haven't heard from gionnibgud yet, if this fixes it for him, I'm leaving this at needs review.

@gionnibgud: If you wait 12 hours, you can just check out the development snapshot and see whether the problem is fixed.

gionnibgud’s picture

Sorry I couldn't get back to you on this issue before.
Just want to let you know that I updated to the latest dev and everything seems to be working fine.
thanks

tstoeckler’s picture

Status: Needs review » Fixed

Great!

Will tag a new release then. Don't know, when I'll get back to that, though, because I'm currently only sporadically on the net.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.