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 date format returned with Date.toLocaleDateString() #3731

Open
steverivers opened this issue May 3, 2024 · 1 comment
Open

Incorrect date format returned with Date.toLocaleDateString() #3731

steverivers opened this issue May 3, 2024 · 1 comment
Assignees

Comments

@steverivers
Copy link

Brief summary

The js function Date().toLocaleDateString() always returns MM/DD/YYYY regardless of localization string.

k6 version

V0.50 and v0.49

OS

Windows 10 Pro Version 22H2 OS build 19045.4291

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Run the following

export default function () {
    const date = new Date(Date.UTC(2012, 11, 31, 3, 0, 0));
    console.log(`Date().toLocaleDateString('en-US') Expect 12/30/2012 : Actual ${date.toLocaleDateString('en-US')}`);
    console.log(`Date().toLocaleDateString('en-CA') Expect 2012-12-30 : Actual ${date.toLocaleDateString('en-CA')}`);
    console.log(`Date().toLocaleDateString('en-GB') Expect 30/12/2012 : Actual ${date.toLocaleDateString('en-GB')}`);
    console.log(`Date().toLocaleDateString('de-DE') Expect 30.12.2012 : Actual ${date.toLocaleDateString('de-DE')}`);
}

Expected behaviour

The js was executed on the mdn playground https://developer.mozilla.org/en-US/play

Date().toLocaleDateString('en-US') Expect 12/30/2012 : Actual 12/30/2012
Date().toLocaleDateString('en-CA') Expect 2012-12-30 : Actual 2012-12-30
Date().toLocaleDateString('en-GB') Expect 30/12/2012 : Actual 30/12/2012
Date().toLocaleDateString('de-DE') Expect 30.12.2012 : Actual 30.12.2012

Actual behaviour

output from test


          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

     execution: local
        script: .\test.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Date().toLocaleDateString('en-US') Expect 12/30/2012 : Actual 12/30/2012  source=console
INFO[0000] Date().toLocaleDateString('en-CA') Expect 2012-12-30 : Actual 12/30/2012  source=console
INFO[0000] Date().toLocaleDateString('en-GB') Expect 30/12/2012 : Actual 12/30/2012  source=console
INFO[0000] Date().toLocaleDateString('de-DE') Expect 30.12.2012 : Actual 12/30/2012  source=console

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=10.07ms min=10.07ms med=10.07ms max=10.07ms p(90)=10.07ms p(95)=10.07ms
     iterations...........: 1   99.288104/s


running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU
@olegbespalov
Copy link
Collaborator

Hi @steverivers

Thanks for reporting!

I briefly looked into the issue, and I believe the root cause is that in goja, the library we do use as ECMAScript 5.1(+) implementation in Go, currently hardcoded en_GB datetime layout

I'll look closer into this later and open an issue or PR in goja.

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

No branches or pull requests

2 participants