IE11 javascript Date.toLocaleTimeString().length incorrect - by ScareCrow900

Status : 

 


ID 863366 Comments
Status Active Workarounds
Type Bug Repros 2
Opened 4/29/2014 3:00:16 AM
Access Restriction Public

Description

When using the Date.toLocaleTimeString() method the length property returns a value larger than the visible chars.  See attached sample html page
Sign in to post a comment.
Posted by Microsoft on 5/6/2014 at 8:39 AM
Thank you for your feedback. We will be investigating this issue further.

Best regards,

The Internet Explorer Team
Posted by EricLaw [ex-MSFT] on 4/29/2014 at 12:33 PM
(Not sure where my later comment went.)

After further thought, I suspect this is by-design: since toLocalTimeString() is meant for display to the user, injection of the left-to-right override character at each component ensures that this use-case is met even when the user's locale conflicts with the direction of the page (e.g. English user visiting Arabic or Hebrew page).

If programmatic parsing of date/time values is needed, the invariant-culture string API should probably be used instead.
Posted by EricLaw [ex-MSFT] on 4/29/2014 at 11:55 AM
Weird. If you enumerate the characters of the string, the problem is obvious:

charAt(0) - '‎' ==> (8206)
charAt(1) - '1' ==> (49)
charAt(2) - '0' ==> (48)
charAt(3) - '‎' ==> (8206)
charAt(4) - ':' ==> (58)
charAt(5) - '‎' ==> (8206)
charAt(6) - '4' ==> (52)
charAt(7) - '5' ==> (53)
charAt(8) - '‎' ==> (8206)
charAt(9) - ':' ==> (58)
charAt(10) - '‎' ==> (8206)
charAt(11) - '2' ==> (50)
charAt(12) - '7' ==> (55)
charAt(13) - '‎' ==> (8206)
charAt(14) - ' ' ==> (32)
charAt(15) - '‎' ==> (8206)
charAt(16) - 'A' ==> (65)
charAt(17) - 'M' ==> (77)

Unicode 8206 is the Left-to-Right marker. So this problem would seem to be a failure to properly marshal a Unicode string into JavaScript's representation of Unicode.