XeroAPI / xero-php-oauth2

Xero PHP SDK for oAuth 2 generated from Xero API OpenAPI Spec 3.0
MIT License
90 stars 64 forks source link

Invoice getFullyPaidOnDateAsDate returns incorrect date for timezones west of UTC #294

Open IanSimpson opened 1 year ago

IanSimpson commented 1 year ago

SDK you're using (please complete the following information):

Describe the bug The Xero API returns a MSDateTimeFormat for the payment date. This works out to midnight on the local date for that company. I.e., for an invoice paid on July 27 at any time, it returns a value of /Date(1658880000000+0000)/.

Converting that to a unix timestamp (1658880000) and then a human-friendly date, we get Wednesday, 27 July 2022 00:00:00 GMT.

If I call the ->getFullyPaidOnDateAsDate() function from a server whose timezone is located in the USA, my output looks like this:

DateTime Object
(
    [date] => 2022-07-26 00:00:00.000000
    [timezone_type] => 3
    [timezone] => America/Chicago
)

Note July 26.

Cross-checking against Xero confirms that the payment was made on the 27th.

image

To Reproduce Steps to reproduce the behavior:

  1. Record payment on an invoice in a US-based company
  2. Fetch the invoice from the API, and output $invoice->getFullyPaidOnDateAsDate()->format('Y-m-d');, on a server set to a timezone in the US
  3. Observe the that the payment date is wrong by a day

Expected behavior I'd expect that the getFullyPaidOnDateAsDate() function returns the date that the invoice was fully paid, instead of another adjacent date