DateTime data processor assumes that a DateTime field always returns a UNIX timestamp

Created on 24 July 2025, 24 days ago

Problem/Motivation

There is already a comment in the code that indicates that indicates that a date time field might not always retun a UNIX timestamp.

see:

// @todo Check that given value from such properties is always timestamp.

https://git.drupalcode.org/project/external_entities/-/blob/3.0.x/src/Pl...

This is not the case. It can also be an ISO 8601 string. If the source data is an iso string it will be set to null on update of the external data. (REST update in my case)

Steps to reproduce

Use some external document storage and try to save a JSON object with an ISO string.

e.g.:

  "updatedAt": "2025-07-21T20:15:13.512Z"

Proposed resolution

Replace:

      if ($typed_data instanceof DateTimeInterface) {
        // @todo Check that given value from such properties is always timestamp.
        if (is_numeric($datetime_data)) {
          $timestamp = $datetime_data;
        }
        else {
          $timestamp = NULL;
        }
      }

with

      if ($typed_data instanceof DateTimeInterface) {
        if (is_numeric($datetime_data)) {
          $timestamp = (int) $datetime_data;
        }
        elseif (is_string($datetime_data)) {
          $timestamp = strtotime($datetime_data) ?: NULL;
        }
        else {
          $timestamp = NULL;
        }
      }

at
https://git.drupalcode.org/project/external_entities/-/blob/3.0.x/src/Pl...

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany marcusx

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024