preg_match subject must be a string in XeroNormalizer

Created on 1 August 2025, about 1 month ago

The following code throws an error when the value form $data[$prop] is an array

         $value = $data[$prop];

          // Detect Xero datetime format and convert to ISO8601.
          if (!is_array($value) && preg_match('#^/Date\(([-]?[0-9]+)([0-9]{3})([+-][0-9]{4})?\)/$#', $value, $dateParts)) {
            // Xero API DateTime format examples:
            // "\/Date(1436961673000)\/" - unix timestamp (milliseconds).
            // "\/Date(1436961673000+0100)\/" - with timezone.
            // "\/Date(-1436961673000-0530)\/" - before the epoch.
            // Regex matches for "\/Date(1436961673090+0100)\/":
            // [1] = ([-]?[0-9]+)    "1436961673" epoch seconds.
            // [2] = ([0-9]{3})      "090"        milliseconds.
            // [3] = ([+-][0-9]{4})? "+0100"/""   optional timezone.
            $datetime = DrupalDateTime::createFromFormat('U.u', $dateParts[1] . '.' . $dateParts[2] . '000')
              ->setTimezone(new \DateTimeZone($dateParts[3] ?? '+0000'));
            $value = $datetime->format('c');
          }
πŸ› Bug report
Status

Active

Version

3.1

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium kensae

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