Skip to content

updateLocale also sets locale #5410

@pachewise

Description

@pachewise

Describe the bug
calling updateLocale also sets the locale globally. I would expect this operation to not change moment state, other than updating the locale we are working with. In particular, the order in which we called updateLocale would determine which was the "default" locale.

To Reproduce
Steps to reproduce the behavior:

  1. set a locale: moment.locale('en');
  2. call moment.defineLocale('your-locale', {});
  3. Locale will now be 'your-locale'

Expected behavior
Locale would remain 'en'.

Screenshots
N/A

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Moment-specific environment
N/A

Please run the following code in your environment and include the output:

console.log((new Date()).toString())
console.log((new Date()).toLocaleString())
console.log((new Date()).getTimezoneOffset())
console.log(navigator.userAgent)
console.log(moment.version)
Thu Mar 12 2020 15:00:21 GMT-0700 (Pacific Daylight Time)
3/12/2020, 3:00:21 PM
420
Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/15.2.1
2.24.0

Additional context
Found issue running jest+enzyme snapshot tests on our code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions