-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Calling tz() overrides locale #2398
Comments
I think this issue(#2248) should be checked. |
I'm encountering this issue as well. For me, it seems that the locale Example: const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const timezone = require('dayjs/plugin/timezone');
dayjs.extend(utc);
dayjs.extend(timezone);
const now = '08/22/2023';
const withLocality = dayjs(now).locale({
name: 'locale_only',
weekStart: 3,
});
const withLocalityAndTimezone = dayjs(now).tz('America/New_York').locale({
name: 'locale_and_tz',
weekStart: 3,
});
const timezoneOnly = dayjs(now).tz('America/New_York');
const a = withLocality.startOf('w'); // returns the expected value of 2023-08-16
const b = withLocalityAndTimezone.startOf('w'); // returns the unexpected value of 2023-08-20
const c = timezoneOnly.startOf('w'); // returns the expected value of 2023-08-20 I believe that the line described above with target is actually OK - when that target is passed to I created a PR here with what I think may help fix this (unless this is intended behavior). |
dayjs/src/plugin/timezone/index.js Line 100 in a9d7d03
The .tz method creates a new dayjs object but does not inherit previous properties, causing the language setting to be lost. |
🎉 This issue has been resolved in version 1.11.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Running
dayjs('2020-01-08T15:14:59.741774+00:00') .locale('es') .tz('America/New_York') .format('LLL')
gives
January 8, 2020 10:14 AM
instead of8 de enero de 2020 10:14
.However, switching the order of
locale
andtz
, e.g.dayjs('2020-01-08T15:14:59.741774+00:00') .tz('America/New_York') .locale('es') .format('LLL')
gives the correct result of
8 de enero de 2020 10:14
.I believe this is the result of the following line of code, which overrides the current locale:
dayjs/src/plugin/timezone/index.js
Line 98 in a9d7d03
This is the intended behavior or is it something to be fixed to support the provided locale?
The text was updated successfully, but these errors were encountered: