falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.51k stars 937 forks source link

`http_date_to_dt()` should return a timezone-aware datetime #2182

Closed vytas7 closed 1 month ago

vytas7 commented 11 months ago

In line with the upstream deprecation of utcnow() in Python 3.12, I think that we should change http_date_to_dt() to return a timezone-aware datetime. Since HTTP dates are normally in GMT, we could use our own GMT zone, or simply use UTC.

This is a breaking change of relatively low value, so unfortunately we won't be able to prioritize it for 4.0. (And we need a longer deprecation window in any case.)

chgad commented 2 months ago

Sprintign on this one rn.

chgad commented 2 months ago

Looking into the time_formats allowed for checking there is one time format here, namely '%a %b %d %H:%M:%S %Y', which would allow for non-timezone-awareness.

How should we handle that?

  1. Do not allow those datetimes → potential major breaking change
  2. Assume a timezone like UTC or GMT → ambiguity what the "correct" choice is → extra breaking change in addition to the overall breaking change
vytas7 commented 2 months ago

Re these alternative datetime formats, I think we can break them quite liberally since they are already hidden by the obs_date parameter (defaults to False).

chgad commented 2 months ago

Matching timezones, except UTC/GMT and the locally defined one, is an ongoing problem see here.

So without using a package, like the popular pytz library, it is not yet possible to parse any other timezone.

EDIT:

Acoording to the third paragraph here "An HTTP-date value represents time as an instance of Coordinated Universal Time (UTC)." There shouldn't really be any date incoming which is not in GMT/UTC.