laravel / nova-issues

554 stars 35 forks source link

The date field subtracts one day from the stored one on editing #4524

Closed ricardov03 closed 2 years ago

ricardov03 commented 2 years ago

Description:

Create a Resource with a Date field. After storing the resource, if you tried to edit the saved resource, the Date field shows a wrong date, specifically a day less from the stored one.

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

  1. Create a Random Model (Include a Date field).
  2. Create the Resource and choose a Date field (Not Datetime), enabling edit.
  3. Store a record and try to edit it. The presented date should show one day less than the stored one.
crynobone commented 2 years ago

There's not enough information such as:

Also, we already have the tests covered via https://github.com/laravel/nova-dusk-suite/blob/master/tests/Browser/DateFieldTest.php without the bug reported above.


p/s: You can grant access to me but I would think above requirements are critical info to debug the issue.

ricardov03 commented 2 years ago

I am working on this later today. Thanks, @crynobone, for taking the time to check this.

ricardov03 commented 2 years ago

Here's the requested information:

<?php
...
        Nova::userTimezone(function (Request $request) {
            return 'America/Santo_Domingo';
        });
crynobone commented 2 years ago

Added America/Santo_Domingo to the test suite and unable to reproduce the issue:

https://github.com/laravel/nova-dusk-suite/blob/master/tests/Browser/DateFieldTest.php

ricardov03 commented 2 years ago

Let me try to replicate the issue in a clean Laravel + Nova installation. Thanks so much for the effort.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

dacastro4 commented 2 years ago

@ricardov03 this is happening to me too. Did you find a way to fix this?

Did you migrate from v3 to v4?

ricardov03 commented 2 years ago

Hello @dacastro4. I'm still facing this issue, but I haven't the time to replicate the problem for @crynobone . I'm not migrating, my project started from a clean Laravel installation with a clean Nova 4.

dacastro4 commented 2 years ago

Thank you @ricardov03. I thought it was going to be some issues during upgrade migration but apparently it is just an issue with the conversion (?) logic of the Date field. We had our app since Nova 3 and we never had that issue before migrating.

@crynobone What I'm testing right now is a date column (not a timestamp, it has to have 00:00:00 as the time) and the app.timezone is UTC as well

baszach commented 2 years ago

I have the same issue. The date of birth attribute is 1968-11-21 but displays 1968-11-20 in Nova frontend. This happens when I use the Date field without any other method. image Timezone is configured as Europe/Berlin.

Using displayUsing with $dateOfBirth?->format('Y-m-d') gives me the correct date.

baszach commented 2 years ago

How is the Date field value attribute in the Vue component derived? I used displayUsing as stated above (formatting Y-m-d) and the Vue data looks like that: image Then without the displayUsing Vue data looks as follow: image

dacastro4 commented 2 years ago

Just so you know, I made a custom Date field as a patch for now. The issue is definitely the frontend so i'm still trying to figure out what it is

crynobone commented 2 years ago

Closing this as stale at the moment, feel free to create a new issue with a full reproducing repository for us to debug the issue.