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
day.js default timezone problem #1227
Comments
dayjs.tz.setDefault only affect dayjs.tz at present |
So, does that mean that there's no way to create an object with the default timezone in the standard way (with dayjs() constructor)? |
Well, as for now, NO. We can only set default tz in dayjs.tz. Feel free to open a PR if you need this. |
Can we atleast add this to the docs to clarify this? Spent quite searching for a weak bug that turns out to be caused by this. |
Also went looking for this, found the doc entry after quite a while under https://day.js.org/docs/en/timezone/set-default-timezone. Still +1 for this. |
Would love to have this as well |
The notice here is really unclear: const value1 = dayjs("2021-05-18T14:44:00.000Z");
dayjs.tz.setDefault("Etc/UCT");
const value2 = dayjs("2021-05-18T14:44:00.000Z");
// value1 is an "existing dayjs object" so I would not expect it have the timezone.
const result = value1.format("DD/MM/YYYY HH:mm") === value2.format("DD/MM/YYYY HH:mm");
// would expect result to be false but actually true |
@hisuwh Even I found this notice very unclear. Hoping for a cleaner description |
+1, What does |
facing the same issue with dayjs. In my current project I want to display all the date as per the login user time zone. So for that I am passing the user timezone in backend with header value and inside the backend I am setting default time zone with user time zone. Then after inside my code I used |
At preset, e.g.
But I'm thinking, seems it's better to make Just wondering if anyone is interested to make a PR to fix this? |
Is there any progress? |
I ended up doing this
and replacing all my imports |
@cmcnamara87 This works, but after doing this I am unable to see the autosuggestion for dayjs apis like |
Any news here? |
any updates on this? |
Update or still nothing ? |
For what it's worth:
|
I also encountered this. Switching to day.js from moment.js, I expected that As others mentioned, the documentation doesn't clearly explain the difference. Time to find all |
this works for me. with this code also you can use autoseffestion for daujs apis : and then use |
globals...🤢 |
I like how
Also, another really great convenience that others have pointed out (@marnixhoh comment) would be to also automatically apply the default timezone so it's not necessary to call |
You can create a service like this
And change your import from |
Hi, default timezone is needed on the dayjs |
The underlying problem here is that there's no way for the plug-in to update the constructor called by the main If plug-ins could each |
Another issue with Day.js's timezone functionality is that when a date without a timestamp is passed, Day.js will calculate a default timestamp and then apply the timezone to it, which can cause the date to advance by a day if the timezone is positive. dayjs.tz.setDefault("Africa/Addis_Ababa") const aDate = "2023-02-06" const dayjsDate = dayjs(aDate).tz().format("MMM DD, YYYY") dayjsDate eq to "Feb 27, 2023" |
Could you at least make a setting that somehow makes it unable to create dayjs objects? or a setting that requires the local for all dayjs objects? I was about to switch to dayjs but I know me - even if there is a service and I do always use my custom dayjs service - there will be the day in a few years where I or others in my team will most certainly forget it and import the normal dayjs function and no-one will notice it - since everything works for us. using |
And |
I'm running into an issue where only GMT+0 (London) doesn't work, but every other timezone works fine... I think it's related to this issue in dayjs as I have no specific code for that case. |
INCORRECT time:
CORRECT time: This bug is only present if the timezone is 'Etc/GMT' (or 'Europe/London') and works fine in 'Etc/GMT+1' and 'Etc/GMT-1' with locale set. |
My solution:
|
I experience the same issue |
We ran into this issue recently due to not spotting the warning in the docs and assumed it would default the tz for all new dayjs objects. We fixed it by doing the below in case it helps anyone with this issue -
|
Hi there. I am having trouble in the following scenario:
When I set the default timezone, using dayjs.tz.setDefault("America/New_York") and then create new object using
the dayjs() constructor, the newly created object does not have the timezone set. The only way to have timezone on the object is
by using the dayjs.tz() constructor, but in this case the expected arguments are completely different.
So, is there a way to set default timezone and be able to create objects with the standart constructor with the default timezone
set?
Code example:
dayjs.tz.setDefault("America/New_York");
dayjs("20/11/2020","DD/MM/YYYY"); // This object does not have the default timezone set
dayjs.tz(); //Here, we have the default timezone set to America/New_York
The text was updated successfully, but these errors were encountered: