Skip to content

Use isoparse instead of parse for datetimes#848

Merged
duckontheweb merged 4 commits into
stac-utils:mainfrom
duckontheweb:fix/819-env-dependent-tzinfo
Jul 18, 2022
Merged

Use isoparse instead of parse for datetimes#848
duckontheweb merged 4 commits into
stac-utils:mainfrom
duckontheweb:fix/819-env-dependent-tzinfo

Conversation

@duckontheweb
Copy link
Copy Markdown
Contributor

@duckontheweb duckontheweb commented Jul 18, 2022

Related Issue(s):

Description:

Updates pystac.utils.str_to_datetime to use dateutil.parser.isoparse instead of dateutil.parser.parse to ensure UTC timestamps stay in UTC even if the system timezone is set to UTC as well. There were also a couple of places in the Item and Collection classes where we were using dateutil.parser.parse directly instead of using pystac.utils.str_to_datetime. These have all been updated to use str_to_datetime.

PR Checklist:

  • Code is formatted (run pre-commit run --all-files)
  • Tests pass (run scripts/test)
  • Documentation has been updated to reflect changes, if applicable
  • This PR maintains or improves overall codebase code coverage.
  • Changes are added to the CHANGELOG. See the docs for information about adding to the changelog.

@duckontheweb duckontheweb requested a review from gadomski July 18, 2022 13:45
Comment thread tests/test_item.py Outdated
Comment thread tests/test_item.py Outdated
Comment thread tests/test_collection.py Outdated
@duckontheweb duckontheweb requested a review from gadomski July 18, 2022 14:15
@duckontheweb
Copy link
Copy Markdown
Contributor Author

@TomAugspurger I verified that this fixes the original issue in pystac.read_file as well:

$ TZ=UTC python -c 'import pystac; print(pystac.read_file("https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a").extent.temporal.intervals[0][0].tzinfo)'
tzutc()

@duckontheweb duckontheweb added this to the 1.5.0 milestone Jul 18, 2022
Copy link
Copy Markdown
Collaborator

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@duckontheweb duckontheweb merged commit 26305d5 into stac-utils:main Jul 18, 2022
@duckontheweb duckontheweb deleted the fix/819-env-dependent-tzinfo branch July 18, 2022 15:20
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.

pystac.read_file returns temporal extents with tzinfo=tzlocal() depending on the environment.

3 participants