Skip to content

Conversation

@LouisAuneau
Copy link

@LouisAuneau LouisAuneau commented Dec 5, 2025

Issue

I noticed when converting an ISO 8601 date with a valid timezone, the timezone component is replaced by UTC, which corrupts the actual timestamp.

Reproduction:

from jsonata import Jsonata

expr = Jsonata('$fromMillis($toMillis("2025-01-01T01:00:00+01:00"))')
print(expr.evaluate({}))

You get: 2025-01-01T01:00:00.000Z
While the expected value should be: 2025-01-01T00:00:00.000Z

Proposed solution

Just adding a check to see if the extracted date is timezone aware before using dt.replace(tzinfo=datetime.timezone.utc).

Do not hesitate if you have question or suggestions for some changes. Thank you in advance!


PS: Note none of the tests in jsonata base repository use another timezone than UTC, hence tests couldn't catch this case. I think it would be worth contributing to those tests as well. However the JS implementation does handle timezone changes correctly.

@rayokota
Copy link
Owner

rayokota commented Dec 8, 2025

Thanks @LouisAuneau , I've fixed the issue in an alternate PR #27

@rayokota rayokota closed this Dec 8, 2025
@LouisAuneau
Copy link
Author

Thanks for you quick response @rayokota. However:

  1. Converting the timezone aware datetimes to UTC is inefficient as .timestamp() handles all timezones correctly. I personally use jsonata-python to process thousands of entries, so any extra CPU-loop can have an impact.
  2. Copying contributed code into your own PR is not really in the spirit of the open-source community...

@rayokota rayokota reopened this Dec 8, 2025
@rayokota rayokota merged commit 5b5d482 into rayokota:master Dec 8, 2025
15 checks passed
@rayokota
Copy link
Owner

rayokota commented Dec 8, 2025

Thanks for you quick response @rayokota. However:

  1. Converting the timezone aware datetimes to UTC is inefficient as .timestamp() handles all timezones correctly. I personally use jsonata-python to process thousands of entries, so any extra CPU-loop can have an impact.
  2. Copying contributed code into your own PR is not really in the spirit of the open-source community...

Apologies, I made the changes before you fixed your PR. In any case, you're right about the unnecessary code, so I've merged your PR.

@LouisAuneau
Copy link
Author

Thanks a lot, much appreciated, and thanks for this library, it helps a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants