cherrypy / cherrypy

CherryPy is a pythonic, object-oriented HTTP framework. https://cherrypy.dev
https://docs.cherrypy.dev
BSD 3-Clause "New" or "Revised" License
1.8k stars 357 forks source link

Local time is used as utc time in LazyRfc3339UtcTime #1991

Closed chiatchiat closed 1 year ago

chiatchiat commented 1 year ago

I'm submitting a ...

Do you want to request a feature or report a bug? Report a bug

What is the current behavior? LazyRfc3339UtcTime returns server local time as utc time in RFC3339 format.

If the current behavior is a bug, please provide the steps to reproduce and if possible a screenshots and logs of the problem. If you can, show us your code.

import datetime
from cherrypy._cplogging import LazyRfc3339UtcTime

# Both datetime are out by timezone offset
print(LazyRfc3339UtcTime())
print(f"{datetime.datetime.utcnow().isoformat()}Z")

What is the expected behavior? LazyRfc3339UtcTime should return utc time string in RFC3339 format.

What is the motivation / use case for changing the behavior? Log timestamp should display the correct timestamp of an event.

Please tell us about your environment:

cheroot: 9.0.0
CherryPy: 18.8.0
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
OS: Windows 10

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, e.g. stackoverflow, gitter, etc.)

Suggestions on bug fix: Replace now() with utcnow()

class LazyRfc3339UtcTime(object):
    def __str__(self):
        """Return utcnow() in RFC3339 UTC Format."""
        return f"{datetime.datetime.utcnow().isoformat('T')}Z"
webknjaz commented 1 year ago

Thanks for the report! Feel free to send a PR, including a regression test.