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

toLocaleDateString() with option { hour: '2-digit' } returns single digit hour #30369

Closed
ameerahm opened this issue Nov 12, 2019 · 3 comments
Closed
Labels
i18n-api Issues and PRs related to the i18n implementation.

Comments

@ameerahm
Copy link

ameerahm commented Nov 12, 2019

  • Version: v10.16.0
  • Platform: MacOS v 10.15 Darwin Kernel Version 19.0.0 RELEASE_X86_64 x86_64
  • Subsystem: date?

If the passed in hour is single digit, i.e
1am -> 9am
1pm -> 9pm

The formatted hour is single digit, even though the hour option is set to a '2-digit' format.

formatDate("11/11/2019 09:01:00");
formatDate("11/11/2019 18:05:00");

function formatDate(dateString) {
    console.log("Date string:\t", dateString);
    const options = {
        weekday: 'long',
        year: 'numeric',
        month: 'long',
        day: 'numeric',
        hour: '2-digit',
        minute: '2-digit'
    };
    const fdate = new Date(dateString);
    const fdateString = fdate.toLocaleDateString("en-US", options)
    console.log("Formatted:\t", fdateString, "\n")
}

The above code prints:

Date string: 11/11/2019 09:01:00
Formatted: Monday, November 11, 2019, 9:01 AM

Date string: 11/11/2019 18:05:00
Formatted: Monday, November 11, 2019, 6:05 PM

The formatting should return a '2-digit' hour:

Formatted: Monday, November 11, 2019, 09:01 AM
Formatted: Monday, November 11, 2019, 06:05 PM

Happy to help out, if you point me in the right direction. Thanks

@lundibundi
Copy link
Member

Looks like it was fixed https://chromium-review.googlesource.com/c/v8/v8/+/1529260 but only Node.js 12+ have the fix. Not sure how do we go about backporting these but it should be pretty easy to fix that I think.

@targos targos self-assigned this Nov 12, 2019
@targos targos added i18n-api Issues and PRs related to the i18n implementation. v10.x labels Nov 12, 2019
targos added a commit to targos/node that referenced this issue Nov 12, 2019
Original commit message:

    [Intl] Fix output of hour:'2-digit', hour12: true

    Bug: chromium:527926
    Change-Id: I783ba59c6e4b117163e058032fb04283e1f43c46
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1529260
    Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
    Commit-Queue: Frank Tang <ftang@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60379}

Refs: v8/v8@fb63e5c

Fixes: nodejs#30369
@targos
Copy link
Member

targos commented Nov 12, 2019

@lundibundi good find!

Backport PR: #30372

@targos targos removed their assignment Nov 12, 2019
BethGriggs pushed a commit that referenced this issue Dec 3, 2019
Original commit message:

    [Intl] Fix output of hour:'2-digit', hour12: true

    Bug: chromium:527926
    Change-Id: I783ba59c6e4b117163e058032fb04283e1f43c46
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1529260
    Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
    Commit-Queue: Frank Tang <ftang@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60379}

Refs: v8/v8@fb63e5c

Fixes: #30369

Backport-PR-URL: #30372
MylesBorins pushed a commit that referenced this issue Dec 17, 2019
Original commit message:

    [Intl] Fix output of hour:'2-digit', hour12: true

    Bug: chromium:527926
    Change-Id: I783ba59c6e4b117163e058032fb04283e1f43c46
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1529260
    Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
    Commit-Queue: Frank Tang <ftang@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60379}

Refs: v8/v8@fb63e5c

Fixes: #30369

Backport-PR-URL: #30372
@BethGriggs
Copy link
Member

This was fixed in Node.js v10.18.1 (#31248) by #30372.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n-api Issues and PRs related to the i18n implementation.
Projects
None yet
Development

No branches or pull requests

4 participants