Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Unicode space character in return value from Date.prototype.toLocaleTimeString #4068

Closed
jbgomez opened this issue Jan 6, 2023 · 5 comments

Comments

@jbgomez
Copy link

jbgomez commented Jan 6, 2023

Details

The space character immediately preceding "AM"/"PM" in the return value is a Unicode "NARROW NO-BREAK SPACE" (8239) character, instead of the correct "SPACE" (32) character.

Affects Date.prototype.toLocaleTimeString and Date.prototype.toLocaleString.

Node.js version

v18.13.0

Example code

let localeString = new Date().toLocaleString(); // e.g., "1/6/2023, 2:10:22 PM"
let lastThreeChars = localeString.slice(-3); // e.g., " PM"
lastThreeChars.charCodeAt(0); // 8239 (but should be 32)

Operating system

macOS 12.5.1 (21G83)

Scope

Runtime

Module and version

Not applicable.

@and-who
Copy link

and-who commented Jan 11, 2023

I think in this Case the "NARROW NO-BREAK SPACE" (Char 8239) is more likely to be the "correct" space character.
Because you don't want to LineBreak between the Time and "AM/PM".

If you have trouble with your Snapshot Tests (I had some) be sure to keep your lokal and CI node Version in sync.
My Problem was, that I used 18.12.1 local and on the Test Server I just configured a Node:18 Docker Image (which resolved to 18.13.0).

So there are two Options:

  1. Upgrade your lokal Setup to 18.13.0
  2. use a more specific Docker Image in the CI Pipeline, e.g. node:18.12.1

@e3dio
Copy link

e3dio commented Jan 23, 2023

Ok who put CharCode 8239 into the toLocaleTimeString() function ?? You broke my terminal output:

image

Web Browser Chrome does not do this, it uses standard space char 32

Update: I changed my terminal font from Courier New to different font and it displays space correctly, but I don't like these other fonts, and other fonts also have error. Ended up slicing and modifying the string :P

@andersk
Copy link

andersk commented Feb 9, 2023

This seems to have been a deliberate change in

See also

@jd1378
Copy link

jd1378 commented Jun 13, 2023

Well this is causing quite a lot of trouble for a lot of people, by causing hydration mismatch in frameworks that hydrate on client side

@richardlau
Copy link
Member

This was fixed in Node.js 18.15.0 by nodejs/node@492fc95bdf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants