Needs work
Project:
Drupal core
Version:
main
Component:
datetime.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
1 Dec 2020 at 08:06 UTC
Updated:
9 Mar 2026 at 21:35 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
japerryRerolled for Drupal 9.1.0.. However, tests need to be updated to remove deprecated calls.
Comment #3
douggreen commentedAttempted preroll, previous patch didn't apply.
Comment #5
isaacrc commentedI was getting this error with patch in #3:
I took a look and only the import of the ConfigFactory class was missing:
use Drupal\Core\Config\ConfigFactoryInterface;I attach the patch for 9.2.x with this small change. Thanks for the previous ones!
Comment #6
pakmanlhComment #7
ranjith_kumar_k_u commentedFixed CS errors
Comment #11
baysaa commentedRerolled patch for 9.3.0
Comment #12
baysaa commentedCleaned up the *.orig and *.rej files that got included in the patch.
Comment #13
daffie commentedThe patch needs to land in D9.4, not D9.3. It is too late to land in D9.3.
Comment #14
kasey_mk commentedThank you Baysaa! Patch in #12 seems to be working for us on 9.3.2
Comment #15
rajab natshahTested 3185750-timezone-field-9.3.0-12.patch with Drupal 9.3.x
Thank you Baysaa
Comment #16
yogeshmpawarResolved CSpell errors & reroll the patch against 9.4.x with a reroll-diff attached.
Comment #18
yogeshmpawarUpdated patch will fix test failures.
Comment #21
jksloan2974 commentedPatch is broken on Drupal 9.4.2
Comment #22
ravi.shankar commentedFixing failed tests of patch #18.
Comment #24
socialnicheguru commentedI get this when I try to update:
The following updates are pending:
datetime module :
8001 - Add the 'timezone' field to all datetime field tables.
datetime_range module :
8001 - Add the 'timezone' field to all daterange field tables.
Do you wish to run all pending updates? (y/n): y
Cannot add field [error]
'user_revision__field_last_password_reset.field_last_password_reset_timezone': table
doesn't exist.
Performing datetime_update_8001 [ok]
Performing datetime_range_update_8001 [ok]
Failed: Cannot add field [error]
'user_revision__field_last_password_reset.field_last_password_reset_timezone': table
doesn't exist.
Comment #25
kasey_mk commentedHas this been fixed? I don't see any issues marked "Fixed" nor do I see anything about timezones in the 9.4.8 release notes, but when I updated to 9.4.8, patch #18 wouldn't apply... but it looks like my date fields still have timezones?
I git cloned 9.4.x and it looks like at least some of what the patch did is already there, but not all of it (or at least, not in the same way).
UPDATE: nevermind, when I deployed to a new environment my timezones went away. I must have skipped a step locally. I'll try to work on a new version of the patch to bring 'em back.
Comment #27
kasey_mk commentedHere's a version of Patch #18 (#22 wouldn't install for me) updated for 9.4.8.
Comment #28
kasey_mk commentedOops; search-and-replace error on some pluses, fixed here. I never could get patch #22 to install, so here's patch #18 updated for Drupal 9.4.8.
Comment #29
awolfey commentedWorking for me. Thank you.
Comment #30
kasey_mk commentedRe-roll for Drupal 9.5
Comment #31
daffie commented@Kasey_MK: This issue needs to land first in D10.1. Also there are some style guide violations:
Comment #32
kasey_mk commentedThanks for the style notes, @daffie - I think this fixes them (plus one other error I found in the process).
I think work for 10.1 is happening on/from [META] Add timezone support to core date fields, and this thread is just to keep those of us using the work-in-progress from a previously at-least-mostly-working patch limping along until that meta issue is resolved.
Comment #33
_utsavsharma commentedComment #34
_utsavsharma commentedFixed CCF for #32 for 9.5.x.
Please review.
Comment #36
liquidcms commentedComment #37
liquidcms commentedNOTE: this is with patch #28 as only one that would apply to 9.4.
I have tested applying this patch on a site running both D9.4.8 and D9.4.10. The patch applies cleanly once i removed this patch #2827055: Add option to show only start or end date in the DateTime Range custom formatter.
Running "drush updb" seems to mostly do its thing by adding TZ column to tables with date columns except i get this error for 1 instance it is trying to update:
this is from the Sitewide Alert module. I suspect this is due to their odd column name for their date property: scheduled_date__value and scheduled_date__end_value. For some reason they have a double underscore. I guess I could raise a bug on that module but not sure Drupal has a requirement for naming of this. More likely this update script should be more encompassing. That being said, the tz field is still added; but only for the start date.
After the patch (and updb) I can now see the UI option for the field settings to "Store a timezone"; but there is no timezone selector added to the widget.
Comment #38
liquidcms commentedHmm, interesting.
I have added new date and daterange fields to an existing bundle (node) and in widget settings i now see the "Preferred time zone for each date" option. Which when selected, does give me a TZ selector on my node form.
My report above was based on setting an existing field (which also happened to be on a paragraph). It does have the TZ options (user/site/fixed) for the widget; but does not have the "Preferred time zone for each date" option.
Comment #39
liquidcms commentedIt seems as though this only works for new fields (fields with no content). For existing fields there is this message as might be expected: "There is data for this field in the database. The field settings can no longer be changed." and the checkbox to set to "Store a time zone" is disabled, initially. But once the form finishes loading; the disabled attr is gone and i can set the value (which i had done for my test above); but when i go back to edit storage settings i see the checkbox did not get set (which is why the option is not available for the widget).
I suspect a core bug here as well in that it allows me to save the field storage form and tells me it was successful; even though it was not.
UI bugs aside, is this expected operation here? Should this change in storage be disabled due to existing content? The tz field tables were modified regardless; so not sure i see harm in allowing new entries to set tz. And somewhat related; not sure why the tz property is added to date fields but not populated with the default site TZ. Is there a reason we wouldnt populate these? Of course if these fields dont use time then no reason; but the tz field is added to the table regardless of the time setting (I guess thinking is maybe they have no content yet so they could be modified to include time?).
I think the update as it is now: add tz field in all tables and dont prepopulate existing entries with tz is valid. But i think this should also allow changing existing fields (with content) but on that action go in and populate all the existing content with site's default tz.
Comment #40
liquidcms commenteddeleted.
Comment #42
natemow commentedReroll for 10.1.
Comment #43
balagan commentedReroll off patch #42
Comment #44
kasey_mk commented#42 applied and seems to be working for me on Drupal 10.1.4 with MySQL 10.4.
#43 threw this error:
PHP Fatal error: Trait "Drupal\datetime\Plugin\Field\ConfigurableTimezoneTrait" not found in /app/web/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php on line 22Thanks to all keeping this alive!
Comment #45
joseph.olstadComment #46
joseph.olstadbased on feedback in #44
Comment #47
balagan commentedApplying patch in #42 gives me the following error
I suppose I also got the error in #44, because now I see that I was actually using a local file 3185750-44.patch for patching. I suppose I have forgotten to get back to the issue and attach it. I have renamed it to 3185750-47.patch and will upload it here.
Comment #48
balagan commentedI have rerolled patch #47 against 10.2.x
No conflicts were shown when rebasing.
Comment #49
socialnicheguru commentedThe patch for 10.2 causes this error:
Site/admin/structure/types/manage/event/fields/node.event.field_date_recur|site/admin/structure/types/manage/event/fields|1||TypeError: Unsupported operand types: string * int in Drupal\datetime\Plugin\Field\FieldType\DateTimeItem->storageSettingsForm() (line 116 of drupal10.2/html/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php).
Comment #50
borutpiletic commentedI can confirm the same issue as reported in comment #49, after applying patch for branch 10.2.
This can be reproduced if you try to use the Date field storage settings form.
There is a additional plus character at line 726 which breaks form element in the storageSettingForm.
Uploading corrected patch 3185750-48 from balagan.
Comment #51
borutpiletic commentedprevious patch had index removed, uploading corrected for 10.2.
Comment #52
kasey_mk commentedRe-roll of patch in #51 for 10.3 / 11
Comment #53
kasey_mk commentedComment #54
kasey_mk commentedOops; I'd introduced an error on /core/modules/datetime_range/src/DateTimeRangeTrait.php and /core/modules/datetime_range/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php - I think this fixes it.
Comment #55
veronicaseveryn commentedPatch #54 didn't quite work for me.
Timezone was still not applicable on the front-end (if selected "Use time zones from individual dates").
After debugging I found the missing piece to it.
I have added a $timezone param to renderStartEndWithIsoAttribute(...) function, so it can accept the value from inside viewElements() function call.
Attached a fix based on #54 , which is also re-rolled for 10.3.x branch.
Comment #56
andrtroe commentedThere is a bug if field is added to a paragraph and user uses collapse/expand operations time changes every time.
Added a fix for this based on patch from #55.
Comment #58
kasey_mk commentedWhen I updated to PHP 8.4 I started getting some errors like this:
Deprecated function: Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeFormatterBase::__construct(): Implicitly marking parameter $config_factory as nullable is deprecated, the explicit nullable type must be used instead in include() (line 576 of /app/vendor/composer/ClassLoader.php).This is pretty easily solvable by adding a "?" to all the instances of "ConfigFactoryInterface $config_factory = NULL" in this patch as follows:
?ConfigFactoryInterface $config_factory = NULLSo that's what's changed in this version of the patch from #56 (for all four instances of that bit of code).
Comment #59
natemow commentedReroll for 11.3.5.
Comment #60
natemow commentedReroll for 11.3.5, this time accounting for now-obsolete `system_time_zones()`.