grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
23.66k stars 1.19k forks source link

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

Open steverivers opened 4 weeks ago

steverivers commented 4 weeks ago

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 commented 2 weeks ago

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.