Problem with timezone handling (caused by date_get_timezone_db returning only UTC)

Created on 14 December 2010, almost 14 years ago
Updated 18 January 2023, almost 2 years ago

Problem/Motivation

There is indeed a difference in the storage of dates with the setting "Date's Timezone" between 2.7 and 2.8: in 2.7, the dates were converted to UTC, while in 2.8, they are not anymore. This is quite worrying given that this means someone who was using 2.7 or earlier will suddenly get different storage behavior with 2.8.

  1. In date < 7.x-2.8 (or date 7.x-2.8 with patch in #22), dates were converted to UTC before being saved in the database
  2. In date 7.x-2.8, dates are now converted to whatever the site or user timezone is set before being saved to the database

Proposed resolution

  1. The correct behavior for SAVING these fields, as indicated in https://www.drupal.org/node/1455578 β†’ , is NOT to convert dates (before they are saved in the database)
  2. The correct behavior for DISPLAYING these fields, again as indicated in https://www.drupal.org/node/1455578 β†’ is to convert dates to whatever the user or site timezone is set to

Remaining tasks

  • Document what the "date" timezone option means.
  • Improve the UI around field timezone options, make the implications of each option more clear.
  • Test coverage for additional scenarios.
  • - Won't do due to the complexities associated with automatic database changes.
  • Drush command to update data from UTC to the correct timezone.
  • Test coverage for the Drush command.
  • UI tool for updating data from UTC to the correct timezone.
  • Test coverage for the UI tool.

User interface changes

n/a

API changes

n/a

Original report by @brenk28 β†’

I create a field of type date. I set the time zone handling to site's time zone and the granularity down to the minute. I create a node and the date is off. For instance, if I set the date to 10:00 a.m. in the node form, it is getting saved to the database as 15:45.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States brenk28

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • @fjgarlin opened merge request.
  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    I created a MR with the patch from #145 (#153 was against a tagged release). I'll try to get familiar with the issue and see where or how I can help.

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦
  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    OK, all of the above brought the patch from #145 to a newer version that applies against the latest and also fixed some of the tests errors reported in the πŸ’¬ DateFieldTestBase::setup() fail setting up user/permission Fixed issue.

    We're in a position now to keep on working on the remaining items.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Rerolled after #3251102 was committed.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I swear I've done this before ;-)

  • The last submitted patch, 161: date-n998076-161.patch, failed testing. View results β†’
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    The above fail can be fixed with this: https://git.drupalcode.org/project/date/-/merge_requests/16/diffs#7d300a...

    I can work on it further tomorrow.

    Are we still aiming to get all the remaining tasks in this issue? I’m happy to help to the best of my ability.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I've already committed the dependencies fix from the other issue. The test failure comes from a new test in DateUpdatesTestCase, one of the pages doesn't load as expected for some reason, though it is still returning a 200 HTTP status.

    I think the todo list is reasonable?

  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    Yup, sounds sensible. I’ll try to fix the test and work on some of the tasks.

    Might ping you again if I need help or guidance.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    @DamienMcKenna - I fixed the test that was failing, rebased the branch with the latest changes from 7.x-2.x, and also addressed, I think, the first two remaining tasks:

    * Document what the "date" timezone option actually means.
    * Improve the UI around field timezone options, make the implications of each option more clear.

    I've done everything via the MR instead of patches. If you want to see a patch version of it just see this: https://git.drupalcode.org/project/date/-/merge_requests/16.diff

    You might want to review the wording as I'm fully familiar with the module's inner details so I may have missed something.

    I've also got a question about the remaining tasks, namely the drush command and the UI tool for updating data. Isn't this what the update hook does? If that's the case, do we really need the command and the UI tool? Once somebody applies this update, then all the dates should be "correct", right?

    Let me know your thoughts.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    From slack conversation on March 6th 2023 (summarized):
    - Fran: ...I have a question about the test that was created called DateUpdatesTestCase. It assumes that the module is still at the previous version, before applying the update hook, but that is not the case. At the time of loading/running the test, the update 7201 is already applied, so we cannot test the before and after, because there is no before in this case.
    - Damien McKenna: Yeah, I realized that would be an issue when I wrote the test, which is why I ignored the schema version and manually executed the update script. That said, the update script (and the test) needs to be removed and replaced with a Drush command and/or admin page to manually process the fields.

  • πŸ‡ΊπŸ‡ΈUnited States hestenet Portland, OR πŸ‡ΊπŸ‡Έ

    Just chiming in that I will need to pull @fjgarlin away for some initiative related work for a little while, so if someone wants to attempt to resolve the items in #174 (or if there is a simpler solution to make it testable) that would be really helpful.

  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    Note that the latest changes are in the MR: https://git.drupalcode.org/project/date/-/merge_requests/16
    Attaching a patch matching the current state of the MR too.

    Also see #171 as the tests that are run in the MR are a smaller set than the ones run in the patch.

  • πŸ‡¬πŸ‡§United Kingdom em-fast1

    Is this the same issue (in 2.14): when trying to add a node - I get both a node and a php error (using 7.4.33) - the same error, which I have perhaps misakenly posted in the core (field) issue queue. Does this issue belong here instead?:

    PDOException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'autocreate' for column `uslowestprices_0`.`field_data_field_tags`.`field_tags_tid` at row 1: INSERT INTO {field_data_field_tags} (entity_type, entity_id, revision_id, bundle, delta, language, field_tags_tid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 77 [:db_insert_placeholder_2] => 77 [:db_insert_placeholder_3] => page [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => autocreate ) in field_sql_storage_field_storage_write() (line 622 of /data/disk/fast1/static/d771/modules/field/modules/field_sql_storage/field_sql_storage.module).

  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    Is it worth considering removing the update hook and drush command altogether into a follow-up? Ie:

    1. Without the update dates entered before 7.27 would be no worse off
    2. Events created that are that old probably exact time matters little by now
    3. Workarounds would then exist because of the new options available

    It would make the merge easier right?

Production build 0.71.5 2024