Problem/Motivation

I encountered an issue where the date value changes when using the Flatdate Picker widget on the edit page, but it displays correctly when view node.

Steps to reproduce

1. Select any content type.
2. Add a new field with the data type Date.
3. On the manage form display, change the widget to Flatdate Picker and add a custom format m-d-Y.
4. Go to Content > Add content and choose your content type. Add a random date to it.
5. Now, view the node, and the date will display correctly as the date you input.
6. However, when you click the "Edit" button and then view the date again, it has been automatically changed.

Proposed resolution

The date value should remain the same when editing and viewing the date, as entered by the user.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

thakurnishant_06 created an issue. See original summary.

Aditi Saraf made their first commit to this issue’s fork.

aditi saraf’s picture

Assigned: Unassigned » aditi saraf

I will work on this

aditi saraf’s picture

Assigned: aditi saraf » Unassigned
Status: Active » Needs review

I got this issue fixed by changing the user ( who will create the content ) time Zone to the country standard time Zone .

Suppose A user who is creating content has time Zone UTC then time will not change on edit content page .

thakurnishant_06’s picture

Hello @aditi Saraf ,
Thankyou for the response ,
I attempted to change the time zone, but it didn't work for me. Have you added the custom format m-d-Y to the date picker widget? Could you please explain the steps you followed?

thakurnishant_06’s picture

Status: Needs review » Active
thakurnishant_06’s picture

Status: Active » Needs work

NO UPDATES ON THIS?

thakurnishant_06’s picture

Priority: Normal » Major
nagy.balint’s picture

StatusFileSize
new54.58 KB

Hi!

Try to keep the date format at the default.

To change the date format displayed to the user, the Alternative Format should be used. (See image)

thakurnishant_06’s picture

Thanks for the response , is there any way if we can change the default format to our own format to pick date.
when i do so all the days are set to be disabled.

nagy.balint’s picture

Can you try the latest version? There was an issue with saving the widget.

thakurnishant_06’s picture

Yes, I tried the latest version. Whenever I change the input date format, it automatically sets all the days to disabled, which prevents me from picking a date when creating content.

nagy.balint’s picture

Are you absolutely sure that you are using the latest 2.0.9 version and cleared the drupal cache?

adityarawat_ln’s picture

StatusFileSize
new1.98 KB

Hi
Please try the above patch

kishan@kk’s picture

Status: Needs work » Needs review
peter pulsifer’s picture

I seem to have the same issue. When I set a non-default date format, then when I edit the node the date changes to what seems like a random value. For example, (using the format "m/d/Y H:i K") a date of 18 December 2023 appears on the edit form as 03 August 2024 - time 00:00. If I save the edited form, the incorrect date is saved, which can be a real problem because it's unexpected. If I edit the date using the widget, the correct date (the one I selected) is saved. So the problem is where the widget is receiving the saved value, not where it sets the selected value.

With a little experimenting, it seems that it works with the Y format code in the first position. Trying the code "F j, Y H:i K" the date becomes "2023-12-18 18:30:00 America/New_York" which of course makes no sense.

It's good that it seems to work with the default format, but it would be great to be able to use a different format.

adityarawat_ln’s picture

StatusFileSize
new2.07 KB
new1.98 KB

Hi @Peter Pulsifer,

can you please try above patch once.

Thank you

peter pulsifer’s picture

Hi, @adityarawat_ln,

That worked for me! Thanks for your assistance.

nagy.balint’s picture

Version: 2.0.7 » 3.0.x-dev
Status: Needs review » Postponed (maintainer needs more info)

As I cannot reproduce the issue when the alternative input format is used.
So with settings:
Alternative input format: F j, Y H:i K
Date format: Y-m-d H:i

I will have to set the issue to postponed.

Feel free to reopen the issue if someone can reproduce the issue with the recommended settings.

vensires’s picture

Priority: Major » Normal
Status: Postponed (maintainer needs more info) » Active

I am tempted to change the status to "Outdated" as it really seems fixed in version 3.0 but under specific conditions.

If an alternative input format is used, the issue still occurs. If you also set the Date format to "Y-m-d", then the issue is fixed.
I guessed that much from your last comment and tried it and it worked.

So, do we require a code change or should we just add it to the documentation?

nagy.balint’s picture

I think it is just that the default Date format should only be changed in rare circumstances because it is linked to data storage.
For most users only the alternative input is needed.

Maybe what we could do is to hide the Date Format option by default.

vensires’s picture

In my case the date format for the storage is Y-m-d (default date field) and we only required d/m/Y for display when editing the node.
If we only use "Alternative input format", the issue exists. If I also set "Date format" to "Y-m-d" the issue is fixed.
So, hiding the "Date format" by itself is not the solution; unless we also set the value behind the date format as "Y-m-d" by default.

nagy.balint’s picture

I see what is wrong.

The default Date Format is Y-m-d H:i, but when the site's timezone is not set to UTC, then that format can cause issues when saving the date, and so it saves an earlier time.

However Y-m-d works fine, which is a good workaround in that case.

Then indeed there is an issue here.

nagy.balint’s picture

However this seems to only be an issue when the field is a date field, and works fine when date and time is selected.

So likely what we need to do in the code is to detect when it is a date only field, and ignore any time related parts.

nagy.balint’s picture

Status: Active » Needs review
StatusFileSize
new3.98 KB

I improved the kernel tests, and fixed the issue at the storage.

  • nagy.balint committed 1ac8f5f0 on 3.0.x
    Issue #3385264 by adityarawat_ln, nagy.balint, Aditi Saraf,...
nagy.balint’s picture

Status: Needs review » Fixed

Let me know if this works better.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.