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

Bug in updateLocale: resetting doesn't work #4962

Closed
kumarharsh opened this issue Jan 22, 2019 · 2 comments · Fixed by #4966
Closed

Bug in updateLocale: resetting doesn't work #4962

kumarharsh opened this issue Jan 22, 2019 · 2 comments · Fixed by #4966

Comments

@kumarharsh
Copy link
Contributor

kumarharsh commented Jan 22, 2019

Describe the bug
Say moment's locale is updated to have a different week.dow: moment.updateLocale(moment.locale(), { week: { dow: 4 } }). Later, if this locale is reset using moment.updateLocale(moment.locale(), null), then it's observed that the locale is not reset cleanly. I was trying to use this approach in Jest, but it's not working.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/qqjm33km19
  2. See output.

Expected behavior
The second date should have been 2018-12-30 because the default locale is 'en' and default week.dow is 0 (Sunday).

Desktop (please complete the following information):

  • OS: [e.g. iOS] Windows
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] 71

Moment-specific environment

  • The time zone setting of the machine the code is running on: en-IN
  • The time and date at which the code was run: 2019-01-22 19:10
  • Other libraries in use (TypeScript, Immutable.js, etc): React

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)
Tue Jan 22 2019 19:09:50 GMT+0530 (India Standard Time)
1/22/2019, 7:09:50 PM
-330
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
2.24.0
@kumarharsh kumarharsh changed the title Bug in updateLocale: resetting dow doesn't work Bug in updateLocale: resetting doesn't work Jan 22, 2019
ashsearle added a commit to ashsearle/moment that referenced this issue Jan 22, 2019
@ashsearle
Copy link
Contributor

Yep, it's a bug.

moment's resetting the locale OK, but holding onto a global reference.

See the updated codesandbox for how to manually avoid this pending a new release with the bug fix.

@kumarharsh
Copy link
Contributor Author

@ashsearle yeah, I accidentally observed while raising the issue that calling moment.locale('en') did in fact give me the expected result. I was just not sure if that was actually what was flushing the global reference. Thanks for the PR!

GmaMontero added a commit to despegar/moment that referenced this issue Sep 4, 2019
* [misc] release process fixes (moment#4961)

* Fix locale abbreviation in comment

* Update package-lock.json

* [misc] Fix type of WeekSpec (moment#4634)

* Fix "the the" typo in test (moment#4578)

* [locale] Fix moment#4568: Insert punjabi for "next" (moment#4583)

* Fix type of WeekSpec

You can set `dow` without setting `doy`, so the type should reflect that

* [new locale] (oc-lnc) Occitan (moment#4957)

* Add oc-lnc files

* Fix calendar test

* Fix the rest of tests

* Add locale author

* Dont make changes to package-lock

* Add newline at end of file

* [bugfix] Fix moment#4962 updateLocale with null to reset (moment#4966)

* [locale] es: Add es translation for invalidDate (moment#4560)

* Add es translation for invalidDate

* Fix lint

* [locale] improve mk translation (moment#4958)

* Update mk.js

* Update mk.js

* Update mk.js

* Update mk.js

* [locale] improve mk translation

* [tests] Fix various text typos (moment#4976)

* [locale] mr (Marathi) (moment#4990)

* tests according to changes in mr.js

* [locale] mr (Marathi)

We Marathi people follow standards mentioned below, to label timespans.

Label | Time Span 
------------ | -------------
पहाटे (post midnight, pre-sunrise) |    >= 12am to < 6am 
सकाळी (post sunrise, pre-noon) |    >= 6am to < 12pm
दुपारी (afternoon) |    >= 12pm to < 5pm
सायंकाळी (evening) |    >= 5pm to < 8pm
रात्री (night) |    >= 8pm to < 12am

Actually, 12am is confusing in Marathi tradition. In modern clock system, Moment 12am is considered in arriving date as 0am. And in Marathi tradition it is referred to as final moment of the previous date (Sort of, 0:01 is starting minute of the arriving date) . To comply with modern clock system, I propose to refer to 0am as पहाटे , so that it is considered as moment in the arriving date. Hope this discription itself is not confusing :)

Another point is about range of पहाटे, ie. >= 0am to < 6am. Though conventionally, upto 2 am, we refer to the time as रात्री or पहाटे, both alternatively, I want to specifically call पहाटे for early times in the arriving date and रात्री for late times in the departing date, to make it more specific and well-defined, avoiding confusion about date of the time.

* [locale] correct translation of locale for Vietnam (moment#4874)

* correct translation of locale for Vietnam

* correct translation of locale for Vietnam (edit proper src files)

* Update author comment line

* [locale] (en-sg) Rename locale en-SG to en-sg (moment#5025)

* [locale] typos in Irish locale for months (moment#5127)

Fixed some typos in the Irish locale regarding months.

* [locale] (br) Breton move from 12-hour to 24-hour notation (moment#4975)

* Breton : move from 12-hour to 24-hour notation moment#4974 moment#4974

* Replace [e] by :

* [locale] bn: Improve translation as per Bangla Academy (moment#5055)

* Delete unused locales

* Remove unused locales

* Update test and build

* Add untracked locale
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

Successfully merging a pull request may close this issue.

2 participants