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

Date field is getting timezoned #5734

Closed
satoved opened this issue Jul 17, 2023 · 4 comments
Closed

Date field is getting timezoned #5734

satoved opened this issue Jul 17, 2023 · 4 comments
Assignees
Labels
bug Verified bug by the Nova team

Comments

@satoved
Copy link

satoved commented Jul 17, 2023

  • Laravel Version: 10.15
  • Nova Version: 4.26.5
  • PHP Version: 8.1

Description:

When I look at a date field on the details and edit page from a computer in the US, it shifts the actual date to the previous date.

E.g. I have '2023-07-18' in the database under the field with DATE type.

It will show me "07/17/2023" on the details page.

image

I will also populate "07/17/2023" if I edit the model.

image

I guess what happens is, Details/DateField.vue takes the date, converts it to datetime, and then localizes it to the string, and then 2023-07-18 00:00:00 UTC becomes something like 2023-07-17 16:00:00 Pacific Time. So it then shows 2023-07-17.

image image

Similar thing happens with in Form/DateField.vue with luxon:
image

I don't think Date field should localized the date at all, because a date is a date.

Detailed steps to reproduce the issue on a fresh Nova installation:

  1. Add a date field to a model with a mysql DATE field in it.
  2. Set the date to 2023-07-18 in the database.
  3. Open the details page for the model and see 2023-07-17 instead.
  4. Try to edit the entry, and see 2023-07-17 in the date input.
@satoved
Copy link
Author

satoved commented Jul 17, 2023

As a workaround, I'm adding some hacks to the field:

  • dispalyUsing() (which is somewhat OK) which avoids the javascript datetime localization
  • resolveUsing() (which is not OK) to shift the hours so the days doesn't go to the previous one for my timezone
image

@crynobone
Copy link
Member

We completely remove the concept of timezone for Date in https://nova.laravel.com/releases/4.26.0 and back with multiple dusk tests.

I definitely need a working example with server, user and browser timezone.

@crynobone crynobone added the needs more info More information is required label Jul 18, 2023
@crynobone crynobone self-assigned this Jul 20, 2023
@crynobone crynobone added pending Issues that are pending triage bug Verified bug by the Nova team and removed needs more info More information is required pending Issues that are pending triage labels Jul 23, 2023
@EPGDigital-MW
Copy link

EPGDigital-MW commented Jul 28, 2023

I have this issue just reported to me, depending where the user is in the world and time of day they see a different date when editing.

If I load my edit page:

My current timezone is Europe/London date shows 22/07/2023 (22nd July 2023)

User in Pacific/Pago_Pago who are now on the next day at time of this message, see 21/07/2023

They should see 22/07/2023 as that's the date thats stored in the database there shouldn't be any timezone conversion happening with dates.

I think like DateTime field we need to set the timezone when setting the Date in Date field

So if we create the value in the Vue component with the timezone that nova is set to, Pacific/Pago_Pago user now sees 22/07/2023 in edit page

this.value = DateTime.fromISO(this.currentField.value || this.value, {
    zone: Nova.config('timezone'),
}).toISODate()

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team
Projects
None yet
Development

No branches or pull requests

3 participants