Intl.DateTimeFormat wrong locale

I’m using github actions to run jest tests. But the action isnt’ recognizing that I’m setting Intl.DateTimeFormat to es-MX instead of en-US.

I see that there might be the case that the github actions container has less locales available. Is there a way to use es-MX?

@vasco3 ,

What runner did you use? GitHub-hosted runner or your self-hosted runner?

On GitHub-hosted runner, you can try the following commands to see if the system local can be changed:

  • On Linux

    # View information of current System Locale
    locale
    
    # Set LANG to es-MX.UTF-8
    sudo update-locale LANG=LANG=es-MX.UTF-8 LANGUAGE
    
    # Configure the locale parameter LC_TIME
    sudo update-locale LC_TIME=es-MX.UTF-8
    
  • On Windows

    Set-WinSystemLocale -SystemLocale es-MX
    
  • On macOS, using the “sudo languagesetup” command.


On the self-hosted runner, you can try to set the system local of the runner machine as Spanish (Mexico), also known as es-MX.

this is my setup and it is a Github-hosted runner

name: Unit Tests

on:
  push:
    branches:
      - master
  pull_request:
    branches: [master]

jobs:
  Jest:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.8]

    steps:
      - uses: actions/checkout@v1
      - name: Run Tests
        run: |
          npm install 
          npm test

npm test runs well in my local, the problem is when it runs as a Github action.

not sure how could I run the update-locale command in yaml

@vasco3 ,

I have created an issue ticket (actions/virtual-environments#1650) to help you report the problem to the appropriate engineering team for further investigation and evaluation.
You can follow this issue ticket and add your comments to it.

1 Like

thank you, I will follow up on there

Hello, @vasco3
I can reproduce the issue with Node 12 which one set up by default. The official distribution of Node 14 includes ‘full icu’: the locale database. Without that data Node only supports ‘en-US’ and will throw for other languages, and silently fall back to ‘en-US’ for English with other countries.

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/setup-node@v2-beta
        with:
          node-version: '14'
      - name: node
        run: |
          cat <<EOF > test.js
          const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); 
          console.log(new Intl.DateTimeFormat('es-MX').format(date));  
          console.log(new Date(date).toLocaleString('es-MX', {weekday:'long'}))
          EOF
          node test.js

image

1 Like

Thank you @al-cheb this is helpful. I’ll use this instead