xero-python icon indicating copy to clipboard operation
xero-python copied to clipboard

Periods in Budgets are show with incorrect dates

Open jonhopper-dataengineers opened this issue 9 months ago • 2 comments

For a budget period of "2025-05" its coming through as "2025-04-30" when in the New Zealand Timezone.

It appears that when usin DATE_WITH_NO_DAY_RE (https://github.com/XeroAPI/xero-python/blob/master/xero_python/api_client/deserializer.py) it adds a "-01" onto the date so appears as "2025-05-01" but when it returns the date is converted to UTC and therefore incorrectly gives the UTC date as "2025-04-30" when you are in a timezone which is forward of UTC

@deserialize.register("date[ms-format]")
def deserialize_date_ms(data_type, data, model_finder):
    """Deserializes data into a python date
       Expected input value in format /Date(timestamp_in_milliseconds)/

       Raise ValueError if the input is well formatted but not a valid date.
       Return None if the input isn't well formatted.

    :param data_type: class literal for deserialized object, or string of class name
    :param data: data to be parsed
    :param model_finder: ModelFinder instance to find class for data_type class literal

    :return: deserialized datetime.date

    """
    ms_datetime = deserialize_datetime_ms(data_type, data, model_finder)
    # shift datetime to utc timezone to make sure utc date used
    return ms_datetime.astimezone(tz=tz.UTC).date()

jonhopper-dataengineers avatar Apr 04 '25 00:04 jonhopper-dataengineers