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');
          }

Issue fork xero-3539323

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kensae created an issue. See original summary.

kensae’s picture

Status: Active » Needs review

mradcliffe made their first commit to this issue’s fork.

  • mradcliffe committed 30eee5a5 on 3.1.x authored by kensae
    Issue #3539323 by kensae: preg_match subject must be a string in...
mradcliffe’s picture

Status: Needs review » Fixed

Thank you for providing the merge request. This makes sense to me.

I think the incoming array may be due to some data type / definition inconsistency. Do you know what the data type and property name that caused the issue?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.