I am having a hard time finding documentation on this. I have a Date and Time field (field_start_time) in a Drupal 10 ECK Entity (wo_time_clock). I found that it is saving the date and time in ISO format without the timezone (2024-01-16T20:58:00). This field is a standard Date field with the 'Date and Time' option picked.

I have a Rule that is activated once a different Entity is flagged, that I am trying to get to create the wo_time_clock Entity and set this wo_time_clock field to the current time. The Rule works fine other that the time is 7 hours off. For the life of me, I can't figure out how to adjust it.

So far to get it to work to this point I have done the following:

I had to set up a special Date Format in Configuration > Region and language > Date and time formats

I set the Name to 'Rules Format' and the Format String to 'Y-m-d\TH:m:s'

In the Rules Actions, 'Add action' of 'Set a Data Value'

I used the Data selector to pick your Entity and add a period '.' to get the field to show. Example: wo_time_clock_created.field_start_time

In the Value field I had to take the 'data selection' option and add twig brackets to it. Then within that I added the " | format_date('rules_format')" Like this:

{{@rules.current_date_context:current_date | format_date('rules_format')}}

This works and doesn't throw an error when the Entity is flagged. BUT, it saves the time in GMT and not Mountain Time.

If I try to format the date within it, it throws an error that the result is to long.


{{@rules.current_date_context:current_date | format_date('custom', 'Y-m-d\TH:m:s-0700')}}


{{@rules.current_date_context:current_date | format_date('custom', 'Y-m-d\TH:m:sO')}}

Gives a WSOD with this:

The website encountered an unexpected error. Try again later.

Drupal\Core\Entity\EntityStorageException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_start_time_value' at row 1: INSERT INTO "wo_time_clock__field_start_time" ("entity_id", "revision_id", "bundle", "delta", "langcode", "field_start_time_value") 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); Array ( [:db_insert_placeholder_0] => 36 [:db_insert_placeholder_1] => 36 [:db_insert_placeholder_2] => entry [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => en [:db_insert_placeholder_5] => 2024-01-20T13:01:10-0700 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Drupal\Core\Database\StatementWrapperIterator->execute() (Line: 44)
Drupal\mysql\Driver\Database\mysql\Insert->execute() (Line: 1400)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->saveToDedicatedTables() (Line: 971)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->doSaveFieldItems() (Line: 718)
Drupal\Core\Entity\ContentEntityStorageBase->doSave() (Line: 486)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 352)
Drupal\Core\Entity\EntityBase->save() (Line: 201)
Drupal\rules\Context\ExecutionState->autoSave() (Line: 168)
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 32)
call_user_func_array() (Line: 409)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 416)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 215)
Drupal\Core\Entity\EntityStorageBase->invokeHook() (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook() (Line: 564)
Drupal\Core\Entity\EntityStorageBase->doPostSave() (Line: 781)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave() (Line: 144)
Drupal\flag\Entity\Storage\FlaggingStorage->doPostSave() (Line: 489)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 352)
Drupal\Core\Entity\EntityBase->save() (Line: 313)
Drupal\flag\FlagService->flag() (Line: 84)
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Am I missing something?

My site is all set to work off of Mountain Time. Even the PHP of the hosting is set to Mountain Time. This was so much easier in Drupal 7.

  • I am really beginning to think there may be a bug in the @rules.current_date_context:current_date is pulled. It doesn't look like it is adjusting for the timezone of the site or the user. I am at a loss where to go from here. Any help would be appreciated.
    – tawellman
    Commented Jan 20 at 23:20

1 Answer 1


Ok, I think I may have finally figured it out. The Rules CurrentDateContext.php is saving the DateTime in your current timezone and not in a UTC without applying the Mountain Time (or any other specific timezone) adjustment.

I ended up hacking the code. That code can be seen...


I am not up on how to creating patches and/or knowing if this is the proper way to get it done. If someone sees this and wants to improve on it and create a patch for it I would be grateful!

  • Thank you for providing an answer! It might be better to include some of the code changes here as well. Otherwise the answer may seem like a "Link only answer" to someone else and get deleted later.
    – mradcliffe
    Commented Jan 23 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.