RedHatQE / pylero

Python wrapper for the Polarion WSDL API
https://redhatqe.github.io/pylero/
MIT License
37 stars 25 forks source link

Running datetime.datetime.now() without timezone info #135

Closed martinhoyer closed 1 year ago

martinhoyer commented 1 year ago

pylero is currently doing naive datetime.datetime.now() with tzinfo=None. Shouldn't the timezone be in sync with Polarion server timezone? Seems like it is currently dependent on the OS settings/location user runs pylero from.

From what I see in the web UI of our polarion server, the time is displayed in UTC. In that case it could be fixed by datetime.datetime.now(tz=datetime.timezone.utc). Or if timezone info would be variable, maybe something like

from datetime import datetime
from zoneinfo import ZoneInfo

POLARION_SERVER_TIMEZONE = 'EST'

datetime.now(tz=ZoneInfo(POLARION_SERVER_TIMEZONE))

Polarion docs state:

Values for time are always rendered in server's time zone, regardless of the time zone where the user is located. For example, if the server is located in the Eastern time zone of the United States, and a user who is located in the Central Europe time zone updates a Work Item, the time stamp of the update will be according to the server's time zone, not the user's time zone.

leelavg commented 1 year ago
martinhoyer commented 1 year ago
  • If possible could you pls mention where you see the difference b/n actual & expected result

    • As the linked docs state it'll be stored in Server's TZ, I don't see any particular issue in using user's locale while making requests and it may be auto-converted to server tz.

I don't actually use pylero, or polarion for that matter...much, yet. If it's auto-converted - great. Is it?

leelavg commented 1 year ago

Is it?

  • I don't know for sure how the conversion happens, all I can say is, we didn't receive any bug reports around datetime mismatch afair.
martinhoyer commented 1 year ago

ok, thank you @leelavg . If you're happy with how it is feel free to close this.
I'd say that if there is auto-conversion anyway, it might be better to use UTC always (see flake8 DTZ005 for example), but if it works :shrug:

leelavg commented 1 year ago