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

Specify the timezone in timestamps #1172

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/callback/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ def get_time():
def get_now():
"""
Return the current timestamp as a string to be sent over the network.
The time is always in UTC timezone and printed in a format Ruby
DateTime can easily parse.
"""
return datetime.utcnow().isoformat()
return datetime.datetime.now(datetime.timezone.utc).isoformat(sep=" ", timespec="seconds")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> datetime.datetime.now(datetime.timezone.utc).isoformat(sep=" ", timespec="seconds")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    datetime.datetime.now(datetime.timezone.utc).isoformat(sep=" ", timespec="seconds")
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'

The datetime here is datetime.datetime already. You want to change the import if you need both datetime.datetime and datetime.timezone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The correct, version agnostic way to get the UTC time is datetime.datetime.utcnow()

Now I just need to understand why you set sep and timespec (as the later is not understood by Python 2)



class CallbackModule(CallbackBase):
Expand Down