Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different rounding for timestamp and datetime when set last_modified #5303

Open
serhiy-storchaka opened this issue Dec 2, 2020 · 0 comments
Labels

Comments

@serhiy-storchaka
Copy link
Contributor

Setting the last_modified property of StreamResponse rounds the value to seconds if it is float or datetime. But different rounding mode is used for float or datetime. If it is a float (timestamp), it is rounded toward +infinity. If it is an instance of datetime, it is rounded toward -infinity.

For example:

$ cat test_last_modified.py
from aiohttp.web import StreamResponse
from datetime import datetime, timezone

resp = StreamResponse()
dt = datetime.now(timezone.utc)
resp.last_modified = dt
print(resp.last_modified)
print(repr(resp.last_modified))
print(resp.headers["Last-Modified"])
resp.last_modified = dt.timestamp()
print(resp.last_modified)
print(repr(resp.last_modified))
print(resp.headers["Last-Modified"])
$ python test_last_modified.py
2020-12-02 09:51:02+00:00
datetime.datetime(2020, 12, 2, 9, 51, 2, tzinfo=datetime.timezone.utc)
Wed, 02 Dec 2020 09:51:02 GMT
2020-12-02 09:51:03+00:00
datetime.datetime(2020, 12, 2, 9, 51, 3, tzinfo=datetime.timezone.utc)
Wed, 02 Dec 2020 09:51:03 GMT

I don't know what direction is correct, but it should be the same.

@serhiy-storchaka serhiy-storchaka changed the title Different Different rounding for timestamp and datetime when set last_modified Dec 2, 2020
greshilov added a commit to greshilov/aiohttp that referenced this issue Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant