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

Date.toLocaleString('en-CA') shows different result in SSR #9629

Closed
hyunbinseo opened this issue Apr 10, 2023 · 3 comments
Closed

Date.toLocaleString('en-CA') shows different result in SSR #9629

hyunbinseo opened this issue Apr 10, 2023 · 3 comments

Comments

@hyunbinseo
Copy link
Contributor

Describe the bug

new Date().toLocaleDateString('en-CA'); returns M/DD/YYYY in SSR, instead of YYYY-MM-DD.

Reproduction

<script>
  import { onMount } from 'svelte';

  let dateString = new Date().toLocaleDateString('en-CA');

  $: console.log(dateString);

  onMount(() => console.log(dateString));
</script>
# server
4/10/2023
# browser
2023-04-10
2023-04-10

Logs

No response

System Info

System:
  OS: macOS 13.3
  CPU: (8) arm64 Apple M1
  Memory: 53.28 MB / 8.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 18.14.1 - ~/.nvm/versions/node/v18.14.1/bin/node
  npm: 9.3.1 - ~/.nvm/versions/node/v18.14.1/bin/npm
Browsers:
  Chrome: 112.0.5615.49
  Firefox: 110.0.1
  Safari: 16.4
npmPackages:
  @sveltejs/adapter-auto: ^2.0.0 => 2.0.0 
  @sveltejs/kit: ^1.5.0 => 1.15.2 
  svelte: ^3.54.0 => 3.58.0 
  vite: ^4.2.0 => 4.2.1

Severity

serious, but I can work around it

Additional Information

No response

@Conduitry
Copy link
Member

This is up to Node, and is going to depend on which locales they ship by default. If you run new Date().toLocaleDateString('en-CA') in the Node REPL, you'll see the same results. I'm not sure how one loads new locales at runtime (as opposed to needing to recompile Node with additional locales built in), but this is unrelated to SvelteKit.

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2023
@hyunbinseo hyunbinseo changed the title Date.toLocaleString() not working in SSR Date.toLocaleString('en-CA') shows different result in SSR Apr 10, 2023
@hyunbinseo
Copy link
Contributor Author

Node.js returns different result in .toLocaleDateString('en-CA').

v16: yyyy-MM-dd
v18: M/d/yyyy

nodejs/node#46277
nodejs/node#45945

@srl295
Copy link

srl295 commented Apr 26, 2023

Ideally you should not be depending on the date format outputting a certain format. If you really need a fixed format, toLocale… is not for you.

The locale formats can and do change. That said, this particular change was reverted.

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

3 participants