Invoice getFullyPaidOnDateAsDate returns incorrect date for timezones west of UTC
IanSimpson opened this issue · 0 comments
SDK you're using (please complete the following information):
- Version 2.9.0 (still seems to exist in 2.14.1)
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.
To Reproduce
Steps to reproduce the behavior:
- Record payment on an invoice in a US-based company
- Fetch the invoice from the API, and output
$invoice->getFullyPaidOnDateAsDate()->format('Y-m-d');
, on a server set to a timezone in the US - 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