Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

chore(samples): use timezone aware datetimes #208

Merged
merged 4 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions samples/snippets/snippets_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def create_finding(source_name):
client = securitycenter.SecurityCenterClient()

# Use the current time as the finding "event time".
event_time = datetime.datetime.now()
event_time = datetime.datetime.now(tz=datetime.timezone.utc)

# source_name is the resource path for a source that has been
# created previously (you can use list_sources to find a specific one).
Expand Down Expand Up @@ -230,7 +230,7 @@ def create_finding_with_source_properties(source_name):
num_value.number_value = 1234

# Use the current time as the finding "event time".
event_time = datetime.datetime.now()
event_time = datetime.datetime.now(tz=datetime.timezone.utc)

finding = Finding(
state=Finding.State.ACTIVE,
Expand Down Expand Up @@ -268,7 +268,7 @@ def update_finding(source_name):

# Set the update time to Now. This must be some time greater then the
# event_time on the original finding.
event_time = datetime.datetime.now()
event_time = datetime.datetime.now(tz=datetime.timezone.utc)

# source_name is the resource path for a source that has been
# created previously (you can use list_sources to find a specific one).
Expand Down Expand Up @@ -319,7 +319,7 @@ def update_finding_state(source_name):
request={
"name": finding_name,
"state": Finding.State.INACTIVE,
"start_time": datetime.datetime.now(),
"start_time": datetime.datetime.now(tz=datetime.timezone.utc),
}
)
print(f"New state: {new_finding.state}")
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/snippets_list_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def list_assets_with_filters_and_read_time(organization_id):
)

# Lists assets as of yesterday.
read_time = datetime.utcnow() - timedelta(days=1)
read_time = datetime.datetime.now(tz=datetime.timezone.utc) - timedelta(days=1)

# Call the API and print results.
asset_iterator = client.list_assets(
Expand Down