Closed (fixed)
Project:
Xero API
Version:
3.1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
1 Aug 2025 at 15:18 UTC
Updated:
29 Aug 2025 at 13:44 UTC
Jump to comment: Most recent
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');
}
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
Comment #3
kensae commentedComment #6
mradcliffeThank 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?