Computed Twig on Date/ Time with Conditions results in php error

Created on 1 December 2023, about 1 year ago
Updated 29 January 2024, about 1 year ago

Problem/Motivation

Calculating the time difference using the Date/ Time elements with any conditions applied to the Computed Twig element results in the php error "TypeError: strtotime(): Argument #1 ($datetime) must be of type string, array given in strtotime()"

Steps to reproduce

Add 2 Date/ Time elements, in my case "Start Date and Time" and "End Date and Time".
Add a Computed Twig element (Computed Time Worked).
Code in "Computed value/markup":

{# calculate the difference (in days) between two date elements #}
{% set startDate = webform_token('[webform_submission:values:start_date_and_time:raw:clear]', webform_submission) ?: 0 |date('d.m.Y H:i:s') %}
{% set endDate = webform_token('[webform_submission:values:end_date_and_time:raw:clear]', webform_submission) ?: 0 |date('d.m.Y H:i:s') %}
{% set difference = endDate|date('U') - startDate|date('U') %}
{% set differenceDays = (difference / 60 / 60 )%}
{{ differenceDays }}

Set Visible or Enabled condition to any value.

Save elements and fill out the webform. The browser returns:

The website encountered an unexpected error. Please try again later.

Drupal logs the following:

TypeError: strtotime(): Argument #1 ($datetime) must be of type string, array given in strtotime() (line 188 of (redacted)/web/modules/contrib/webform/src/Plugin/WebformElement/DateBase.php)

Removing the condition from the Computed Twig element allows it to function properly.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Closed: outdated

Version

6.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States spivey

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024