Skip to content

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

@TomAugspurger

Description

@TomAugspurger

Depending on the environment (I think the value of TZ, maybe other things), the timezones on pystac Collections can be tzlocal rather than utc.

>>> pystac.read_file("https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a").extent.temporal.intervals[0][0].tzinfo
tzlocal()

Here's a demonstration of the environment TZ influencing the output:

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)'
tzlocal()TZ="US/Central" 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()

Since the STAC spec says that all datetimes should be UTC, I think that the datetimes should be tz-aware. If python-dateutil happens to return a tzlocal timezone, I think pystac can assume that local = UTC and localize it to UTC.

Upstream issue in python-dateutil: dateutil/dateutil#349

xref #760. I'm not sure if this would fix this behavior or not (cc. @philvarner)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions