Skip to content

Commit

Permalink
Updating UTC handing to use UTC aware objects
Browse files Browse the repository at this point in the history
Python 3.12 will throw DeprecationWarning: datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.now(datetime.UTC)
  • Loading branch information
radez committed Jul 27, 2023
1 parent 89a071a commit 7aff6d6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@


def current_time():
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
return datetime.datetime.now(datetime.UTC)

Check warning on line 73 in src/ansible_runner/display_callback/callback/awx_display.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_runner/display_callback/callback/awx_display.py#L73

Added line #L73 was not covered by tests


# use a custom JSON serializer so we can properly handle !unsafe and !vault
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def event_callback(self, event_data):

# prefer 'created' from partial data, but verbose events set time here
if 'created' not in event_data:
event_data['created'] = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()
event_data['created'] = datetime.datetime.now(datetime.UTC).isoformat()

if self.event_handler is not None:
should_write = self.event_handler(event_data)
Expand Down

0 comments on commit 7aff6d6

Please sign in to comment.