diff --git a/generator/objects/Property.php b/generator/objects/Property.php index 6444da56..62d5806e 100644 --- a/generator/objects/Property.php +++ b/generator/objects/Property.php @@ -176,6 +176,7 @@ public function getPHPType($with_ns = false) { return 'string'; case Object::PROPERTY_TYPE_DATE: + case Object::PROPERTY_TYPE_TIMESTAMP: return '\DateTime'; case Object::PROPERTY_TYPE_OBJECT: @@ -195,6 +196,7 @@ public function isHintable(){ switch($this->getType()){ case Object::PROPERTY_TYPE_DATE: + case Object::PROPERTY_TYPE_TIMESTAMP: case Object::PROPERTY_TYPE_OBJECT: return true; default: @@ -215,6 +217,10 @@ private function parseType(){ if(preg_match('/^((a\s)?bool|true\b|booelan)/i', $this->description)) $type = Object::PROPERTY_TYPE_BOOLEAN; + //Spelling errors in the docs + if(preg_match('/UTC$/', $this->getName())) + $type = Object::PROPERTY_TYPE_TIMESTAMP; + if(preg_match('/^Has[A-Z]\w+/', $this->getName())) $type = Object::PROPERTY_TYPE_BOOLEAN; @@ -231,7 +237,7 @@ private function parseType(){ if(preg_match('/(^int(eger)?\b)/i', $this->description)) $type = Object::PROPERTY_TYPE_INT; - if(preg_match('/(UTC|timestamp|\bdate\b)/i', $this->description)) + if(preg_match('/(\bdate\b)/i', $this->description)) $type = Object::PROPERTY_TYPE_DATE; if(preg_match('/Xero (generated )?(unique )?identifier/i', $this->description)) diff --git a/src/XeroPHP/Models/Accounting/Contact.php b/src/XeroPHP/Models/Accounting/Contact.php index c180a6a2..c987b2c0 100644 --- a/src/XeroPHP/Models/Accounting/Contact.php +++ b/src/XeroPHP/Models/Accounting/Contact.php @@ -313,7 +313,7 @@ public static function getProperties() { 'PurchasesDefaultAccountCode' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'SalesTrackingCategories' => array (false, self::PROPERTY_TYPE_OBJECT, 'Accounting\\TrackingCategory', true, false), 'PurchasesTrackingCategories' => array (false, self::PROPERTY_TYPE_OBJECT, 'Accounting\\TrackingCategory', true, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'ContactGroups' => array (false, self::PROPERTY_TYPE_OBJECT, 'Accounting\\ContactGroup', true, false), 'Website' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'BrandingTheme' => array (false, self::PROPERTY_TYPE_OBJECT, 'Accounting\\BrandingTheme', false, false), diff --git a/src/XeroPHP/Models/Accounting/CreditNote.php b/src/XeroPHP/Models/Accounting/CreditNote.php index 4cfd905c..24c390a7 100644 --- a/src/XeroPHP/Models/Accounting/CreditNote.php +++ b/src/XeroPHP/Models/Accounting/CreditNote.php @@ -220,7 +220,7 @@ public static function getProperties() { 'SubTotal' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), 'TotalTax' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), 'Total' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'CurrencyCode' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'FullyPaidOnDate' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), 'CreditNoteID' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), diff --git a/src/XeroPHP/Models/Accounting/Item/Purchase.php b/src/XeroPHP/Models/Accounting/Item/Purchase.php index e5bb4aae..d1ce1db7 100644 --- a/src/XeroPHP/Models/Accounting/Item/Purchase.php +++ b/src/XeroPHP/Models/Accounting/Item/Purchase.php @@ -29,7 +29,7 @@ class Purchase extends Remote\Object { /** * This property has been removed from the Xero API * - * @property string UpdatedDateUTC + * @property \DateTime UpdatedDateUTC * @deprecated */ @@ -99,7 +99,7 @@ public static function getProperties() { 'UnitPrice' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'AccountCode' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'TaxType' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_STRING, null, false, false) + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false) ); } @@ -159,7 +159,7 @@ public function setTaxType($value) { } /** - * @return string + * @return \DateTime * @deprecated */ public function getUpdatedDateUTC() { @@ -167,11 +167,11 @@ public function getUpdatedDateUTC() { } /** - * @param string $value + * @param \DateTime $value * @return Purchase * @deprecated */ - public function setUpdatedDateUTC($value) { + public function setUpdatedDateUTC(\DateTime $value) { $this->propertyUpdated('UpdatedDateUTC', $value); $this->_data['UpdatedDateUTC'] = $value; return $this; diff --git a/src/XeroPHP/Models/Accounting/Item/Sale.php b/src/XeroPHP/Models/Accounting/Item/Sale.php index e02645b0..b4177686 100644 --- a/src/XeroPHP/Models/Accounting/Item/Sale.php +++ b/src/XeroPHP/Models/Accounting/Item/Sale.php @@ -29,7 +29,7 @@ class Sale extends Remote\Object { /** * This property has been removed from the Xero API * - * @property string UpdatedDateUTC + * @property \DateTime UpdatedDateUTC * @deprecated */ @@ -99,7 +99,7 @@ public static function getProperties() { 'UnitPrice' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'AccountCode' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'TaxType' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_STRING, null, false, false) + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false) ); } @@ -159,7 +159,7 @@ public function setTaxType($value) { } /** - * @return string + * @return \DateTime * @deprecated */ public function getUpdatedDateUTC() { @@ -167,11 +167,11 @@ public function getUpdatedDateUTC() { } /** - * @param string $value + * @param \DateTime $value * @return Sale * @deprecated */ - public function setUpdatedDateUTC($value) { + public function setUpdatedDateUTC(\DateTime $value) { $this->propertyUpdated('UpdatedDateUTC', $value); $this->_data['UpdatedDateUTC'] = $value; return $this; diff --git a/src/XeroPHP/Models/Accounting/Organisation.php b/src/XeroPHP/Models/Accounting/Organisation.php index 8dadd768..92452eb4 100644 --- a/src/XeroPHP/Models/Accounting/Organisation.php +++ b/src/XeroPHP/Models/Accounting/Organisation.php @@ -268,7 +268,7 @@ public static function getProperties() { 'SalesTaxPeriod' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false), 'PeriodLockDate' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'EndOfYearLockDate' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), - 'CreatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), + 'CreatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'OrganisationEntityType' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false), 'Timezone' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'ShortCode' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), diff --git a/src/XeroPHP/Models/Accounting/Overpayment.php b/src/XeroPHP/Models/Accounting/Overpayment.php index b92130e2..3978ff40 100644 --- a/src/XeroPHP/Models/Accounting/Overpayment.php +++ b/src/XeroPHP/Models/Accounting/Overpayment.php @@ -205,7 +205,7 @@ public static function getProperties() { 'SubTotal' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), 'TotalTax' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), 'Total' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'CurrencyCode' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'FullyPaidOnDate' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), 'OverpaymentID' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), diff --git a/src/XeroPHP/Models/Accounting/Payment.php b/src/XeroPHP/Models/Accounting/Payment.php index d4e05c9b..78d400e7 100644 --- a/src/XeroPHP/Models/Accounting/Payment.php +++ b/src/XeroPHP/Models/Accounting/Payment.php @@ -189,7 +189,7 @@ public static function getProperties() { 'IsReconciled' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'Status' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false), 'PaymentType' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'PaymentID' => array (false, self::PROPERTY_TYPE_STRING, null, false, false) ); } diff --git a/src/XeroPHP/Models/Accounting/Prepayment.php b/src/XeroPHP/Models/Accounting/Prepayment.php index 0ae6dce1..d3f6a96b 100644 --- a/src/XeroPHP/Models/Accounting/Prepayment.php +++ b/src/XeroPHP/Models/Accounting/Prepayment.php @@ -205,7 +205,7 @@ public static function getProperties() { 'SubTotal' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), 'TotalTax' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), 'Total' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'CurrencyCode' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'FullyPaidOnDate' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), 'PrepaymentID' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), diff --git a/src/XeroPHP/Models/Accounting/User.php b/src/XeroPHP/Models/Accounting/User.php index 4e03901c..5c96cbca 100644 --- a/src/XeroPHP/Models/Accounting/User.php +++ b/src/XeroPHP/Models/Accounting/User.php @@ -117,7 +117,7 @@ public static function getProperties() { 'EmailAddress' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'FirstName' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'LastName' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'IsSubscriber' => array (false, self::PROPERTY_TYPE_BOOLEAN, null, false, false), 'OrganisationRole' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false) ); diff --git a/src/XeroPHP/Models/Files/File.php b/src/XeroPHP/Models/Files/File.php index 2c2b7964..e5fae1db 100644 --- a/src/XeroPHP/Models/Files/File.php +++ b/src/XeroPHP/Models/Files/File.php @@ -127,7 +127,7 @@ public static function getProperties() { 'FolderId' => array (false, self::PROPERTY_TYPE_OBJECT, 'Files\\Folder', false, false), 'MimeType' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'Size' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), - 'CreatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), + 'CreatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), 'User' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'Id' => array (false, self::PROPERTY_TYPE_GUID, null, false, false) diff --git a/src/XeroPHP/Models/PayrollAU/Employee.php b/src/XeroPHP/Models/PayrollAU/Employee.php index 4494ba34..54df77b3 100644 --- a/src/XeroPHP/Models/PayrollAU/Employee.php +++ b/src/XeroPHP/Models/PayrollAU/Employee.php @@ -274,7 +274,7 @@ public static function getProperties() { 'TerminationDate' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false), 'EmployeeID' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'Status' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false) + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false) ); } diff --git a/src/XeroPHP/Models/PayrollUS/Employee.php b/src/XeroPHP/Models/PayrollUS/Employee.php index 636a47b2..7c8b0693 100644 --- a/src/XeroPHP/Models/PayrollUS/Employee.php +++ b/src/XeroPHP/Models/PayrollUS/Employee.php @@ -275,7 +275,7 @@ public static function getProperties() { 'OpeningBalances' => array (false, self::PROPERTY_TYPE_OBJECT, 'PayrollUS\\Employee\\OpeningBalance', true, false), 'EmployeeID' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), 'Status' => array (false, self::PROPERTY_TYPE_ENUM, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_DATE, '\\DateTime', false, false) + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false) ); } diff --git a/src/XeroPHP/Models/PayrollUS/Paystub.php b/src/XeroPHP/Models/PayrollUS/Paystub.php index a18e479f..c830c3eb 100644 --- a/src/XeroPHP/Models/PayrollUS/Paystub.php +++ b/src/XeroPHP/Models/PayrollUS/Paystub.php @@ -83,7 +83,7 @@ class Paystub extends Remote\Object { /** * * - * @property string UpdatedDateUTC + * @property \DateTime UpdatedDateUTC */ /** @@ -204,7 +204,7 @@ public static function getProperties() { 'Tax' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), 'Reimbursements' => array (false, self::PROPERTY_TYPE_FLOAT, null, true, false), 'NetPay' => array (false, self::PROPERTY_TYPE_FLOAT, null, false, false), - 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_STRING, null, false, false), + 'UpdatedDateUTC' => array (false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTime', false, false), 'EarningsLines' => array (false, self::PROPERTY_TYPE_OBJECT, 'PayrollUS\\Paystub\\EarningsLine', true, false), 'LeaveEarningsLines' => array (false, self::PROPERTY_TYPE_OBJECT, 'PayrollUS\\Paystub\\LeaveEarningsLine', true, false), 'TimesheetEarningsLines' => array (false, self::PROPERTY_TYPE_OBJECT, 'PayrollUS\\Paystub\\TimesheetEarningsLine', true, false), @@ -410,17 +410,17 @@ public function setNetPay($value) { } /** - * @return string + * @return \DateTime */ public function getUpdatedDateUTC() { return $this->_data['UpdatedDateUTC']; } /** - * @param string $value + * @param \DateTime $value * @return Paystub */ - public function setUpdatedDateUTC($value) { + public function setUpdatedDateUTC(\DateTime $value) { $this->propertyUpdated('UpdatedDateUTC', $value); $this->_data['UpdatedDateUTC'] = $value; return $this; diff --git a/src/XeroPHP/Remote/Object.php b/src/XeroPHP/Remote/Object.php index dc8eab07..7f09b700 100644 --- a/src/XeroPHP/Remote/Object.php +++ b/src/XeroPHP/Remote/Object.php @@ -26,14 +26,15 @@ abstract class Object implements ObjectInterface, \JsonSerializable, \ArrayAcces /** * */ - const PROPERTY_TYPE_STRING = 'string'; - const PROPERTY_TYPE_INT = 'int'; - const PROPERTY_TYPE_FLOAT = 'float'; - const PROPERTY_TYPE_BOOLEAN = 'bool'; - const PROPERTY_TYPE_ENUM = 'enum'; - const PROPERTY_TYPE_GUID = 'guid'; - const PROPERTY_TYPE_DATE = 'date'; - const PROPERTY_TYPE_OBJECT = 'object'; + const PROPERTY_TYPE_STRING = 'string'; + const PROPERTY_TYPE_INT = 'int'; + const PROPERTY_TYPE_FLOAT = 'float'; + const PROPERTY_TYPE_BOOLEAN = 'bool'; + const PROPERTY_TYPE_ENUM = 'enum'; + const PROPERTY_TYPE_GUID = 'guid'; + const PROPERTY_TYPE_DATE = 'date'; + const PROPERTY_TYPE_TIMESTAMP = 'timestamp'; + const PROPERTY_TYPE_OBJECT = 'object'; /** * Container to the actual properties of the object @@ -238,6 +239,7 @@ public static function castToString($type, $value) { return $value ? 'true' : 'false'; case self::PROPERTY_TYPE_DATE: + case self::PROPERTY_TYPE_TIMESTAMP: /** @var \DateTime $value */ return $value->format('c'); @@ -260,6 +262,9 @@ public static function castToString($type, $value) { */ public static function castFromString($type, $value, $php_type) { + //Here should maybe handle locale specific tz overrides in the future. + $timezone = null; + switch($type) { case self::PROPERTY_TYPE_INT: @@ -271,10 +276,12 @@ public static function castFromString($type, $value, $php_type) { case self::PROPERTY_TYPE_BOOLEAN: return in_array(strtolower($value), array('true', '1', 'yes')); + case self::PROPERTY_TYPE_TIMESTAMP: + $timezone = new \DateTimeZone('UTC'); case self::PROPERTY_TYPE_DATE: if(preg_match('/Date\((?[0-9\+\.]+)\)/', $value, $matches)) //to catch stupid .net date serialisation $value = $matches['timestamp']; - return new \DateTime($value); + return new \DateTime($value, $timezone); case self::PROPERTY_TYPE_OBJECT: $php_type = sprintf('\\XeroPHP\\Models\\%s', $php_type);