镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@jbgomez

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.

Activity

  1. and-who commented on Jan 11, 2023

    @and-who

    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
  2. e3dio commented on Jan 23, 2023

    @e3dio

    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

  3. andersk commented on Feb 9, 2023

    @andersk
  4. jd1378 commented on Jun 13, 2023

    @jd1378

    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

  5. richardlau commented on Jun 13, 2023

    @richardlau
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions