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

fix: Solve timezone issue in ActivityAuditClientV1 #206

Merged
merged 3 commits into from
May 4, 2022
Merged

fix: Solve timezone issue in ActivityAuditClientV1 #206

merged 3 commits into from
May 4, 2022

Conversation

alblasco
Copy link
Contributor

@alblasco alblasco commented Apr 20, 2022

Issue

When trying list_events() with following parameters:

    to_date = datetime.datetime.utcnow() 
    from_date = to_date - datetime.timedelta(seconds=40)

I have found that I retrieve events from 2 hours ago. Note: That my country is now UTC+2

Reason

utcnow() returns a datetime without timezone:

bool(datetime.datetime.utcnow().tzinfo)
>>>False

And so when applying timestamp to it, then Python assumes your localtime, and so the 2 hours difference

Fix

So using now(), that provides the localtime, fixes the previous issue
Thanks @marojor for suggesting the fix

Tested

Tested using a real sysdig customer:

  1. Generating activity audit events
  2. And then trying to retrieve the events with this API

Copy link
Contributor

@marojor marojor left a comment

Choose a reason for hiding this comment

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

🏅

@tembleking tembleking changed the title Fix timezone issue in ActivityAuditClientV1 fix: Solve timezone issue in ActivityAuditClientV1 May 4, 2022
@tembleking tembleking merged commit bbc45bb into sysdiglabs:master May 4, 2022
tembleking pushed a commit that referenced this pull request Jul 11, 2022
* Use now instead of utcnow()
* Fix also example
* Fix also test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants