Issue 45469 in chromium: Date.localeFormat doesn't return a value

21 views
Skip to first unread message

chro...@googlecode.com

unread,
May 31, 2010, 5:26:47 AM5/31/10
to chromi...@chromium.org
Status: Unconfirmed
Owner: ----
Labels: Type-Bug Pri-2 Area-Undefined

New issue 45469 by bart.peremans: Date.localeFormat doesn't return a value
http://code.google.com/p/chromium/issues/detail?id=45469

Chrome Version : 5.0.375.55
URLs (if applicable) : -
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
Safari 4: OK
Firefox 3.x: OK
IE 7: OK
IE 8: OK

What steps will reproduce the problem?
1. javascript doesn't returns the wanted result when gettings local
formatted string from date


What is the expected result?
(new Date("6/1/2010")).localeFormat("MMMM")
returns "June"
(new Date("1/1/2010")).localeFormat("MMMM")
returns "January"
(new Date("2/1/2010")).localeFormat("MMMM")
returns "February"
(new Date("3/1/2010")).localeFormat("MMMM")
returns "March"
(new Date("4/1/2010")).localeFormat("MMMM")
returns "April"
(new Date("5/1/2010")).localeFormat("MMMM")
returns "May"
(new Date("6/1/2010")).localeFormat("MMMM")
returns "June"
(new Date("7/1/2010")).localeFormat("MMMM")
returns "July"
(new Date("8/1/2010")).localeFormat("MMMM")
returns "August"
(new Date("9/1/2010")).localeFormat("MMMM")
returns "September"
(new Date("10/1/2010")).localeFormat("MMMM")
returns "October"
(new Date("11/1/2010")).localeFormat("MMMM")
returns "November"
(new Date("12/1/2010")).localeFormat("MMMM")
returns "December"

Same issues with day names !

What happens instead?

(new Date("6/1/2010")).localeFormat("MMMM")
returns ""
(new Date("1/1/2010")).localeFormat("MMMM")
returns "January"
(new Date("2/1/2010")).localeFormat("MMMM")
returns ""
(new Date("3/1/2010")).localeFormat("MMMM")
returns ""
(new Date("4/1/2010")).localeFormat("MMMM")
returns ""
(new Date("5/1/2010")).localeFormat("MMMM")
returns ""
(new Date("6/1/2010")).localeFormat("MMMM")
returns ""
(new Date("7/1/2010")).localeFormat("MMMM")
returns ""
(new Date("8/1/2010")).localeFormat("MMMM")
returns ""
(new Date("9/1/2010")).localeFormat("MMMM")
returns ""
(new Date("10/1/2010")).localeFormat("MMMM")
returns ""
(new Date("11/1/2010")).localeFormat("MMMM")
returns ""
(new Date("12/1/2010")).localeFormat("MMMM")
returns ""

Please provide any additional information below. Attach a screenshot if
possible.


chro...@googlecode.com

unread,
May 31, 2010, 6:20:24 AM5/31/10
to chromi...@chromium.org

Comment #1 on issue 45469 by bart.peremans: Date.localeFormat doesn't

searched more in depth, seems if you put a regexp in a var and you want to
execute
this an unwanted result is returned, the regex isn't reset.

example FF:
var tokenRegExp =
/dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|
zzz|zz|z/g
tokenRegExp.exec("MMMM") => ["MMMM"]
tokenRegExp.exec("MMMM") => null
tokenRegExp.exec("MMMM") => ["MMMM"]
...

in Chrome:

var tokenRegExp =
/dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|
zzz|zz|z/g
tokenRegExp.exec("MMMM") => null
tokenRegExp.exec("MMMM") => ["MMMM"]
tokenRegExp.exec("MMMM") => null
tokenRegExp.exec("MMMM") => null
tokenRegExp.exec("MMMM") => null
...

it stays null until we change the exec parameter: ex:
...
tokenRegExp.exec("MMMM") => null
tokenRegExp.exec("MMM") => null
tokenRegExp.exec("MMMM") => ["MMMM"]
tokenRegExp.exec("MMMM") => null
tokenRegExp.exec("MMMM") => null
...

It is unable to change modify this line of code because it is auto
generated by ASP
in a ScriptResource.axd file when using Ajax

Regards,

Bart

chro...@googlecode.com

unread,
May 31, 2010, 6:51:41 AM5/31/10
to chromi...@chromium.org

Comment #2 on issue 45469 by bart.peremans: Date.localeFormat doesn't

My solution:

Replace all methods like new Date().format("") or new
Date().localFormat("") to
getLocalFormattedDate(new Date(), "")

function getLocalFormattedDate(date, format) {
var i = 0;
var fmt = date.localeFormat(format);
/* Google Chrome bug 5.0.375.55 */
while (fmt == "") {
date.localeFormat("yyyy/MM/dd hh:mm:ss:ffff");
fmt = date.localeFormat(format);
i = i + 1;
if (i > 5) { throw("Error retrieving date, restart your
browser!"); }
}

return fmt;
};

chro...@googlecode.com

unread,
Jun 11, 2010, 10:42:04 AM6/11/10
to chromi...@chromium.org

Comment #3 on issue 45469 by atleticn: Date.localeFormat doesn't return a
value
http://code.google.com/p/chromium/issues/detail?id=45469

The following code will cause exec to return null after 4th iteration,
while in all other browsers will return "a". The code is extracted from MS
ASP.NET AJAX framework and this behavior of RegEx object in Chrome cause
any client-side new Date call after second time to return empty string as
result.

for (var i = 0; i < 5; i++)
{
alert(/a/g.exec("a"));
}

OR

var regEx = new RegExp(/a/g);
for (var i = 0; i < 5; i++)
{
alert(regEx.exec("a"));
}

The issue in RegEx cause the following ASP.NET AJAX code to fail:
var value = new Date(1230876000000); //-- value returned from service/for
example/
alert(String.localeFormat("{0:d}", value)); //-- 1/2/2009
alert(String.localeFormat("{0:d}", value)); //-- 1/2/2009
alert(String.localeFormat("{0:d}", value)); //-- return empty string

@bart.peremans - I guess you can override _getTokenRegExp of Date object to
overcome this temporary - at least it works for me:
Date._getTokenRegExp = function Date$_getTokenRegExp()
{
return new RegExp(/dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|
s|tt|t|fff|ff|f|zzz|zz|z/g);
}


chro...@googlecode.com

unread,
Jun 24, 2010, 1:07:13 PM6/24/10
to chromi...@chromium.org
Updates:
Status: Assigned
Owner: LasseReichsteinHolstNielsen
Cc: sandh...@chromium.org erik.corry

Comment #6 on issue 45469 by ag...@chromium.org: Date.localeFormat doesn't

This is indeed a bad regression. We will find the cause and get a patch
ready tomorrow. Thanks for the report!

chro...@googlecode.com

unread,
Jun 25, 2010, 5:01:51 AM6/25/10
to chromi...@chromium.org

Comment #7 on issue 45469 by LasseRei...@gmail.com: Date.localeFormat

Fixed on v8 bleeding edge and on 2.1 branch.

chro...@googlecode.com

unread,
Jun 29, 2010, 2:21:07 AM6/29/10
to chromi...@chromium.org
Updates:
Status: Fixed

Comment #9 on issue 45469 by ag...@chromium.org: Date.localeFormat doesn't

Yes, this is fixed.

Reply all
Reply to author
Forward
0 new messages