-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
replace utcnow with now, due to utcnow will be deprecated #2215
replace utcnow with now, due to utcnow will be deprecated #2215
Conversation
@@ -1028,7 +1028,7 @@ def test_load_gcp_token_no_refresh(self): | |||
def test_load_gcp_token_with_refresh(self): | |||
def cred(): return None | |||
cred.token = TEST_ANOTHER_DATA_BASE64 | |||
cred.expiry = datetime.datetime.utcnow() | |||
cred.expiry = datetime.datetime.now(tz=UTC).replace(tzinfo=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate why do we do .replace(tzinfo=None)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure!
Because the output of datetime.datetime.utcnow()
is timezone-naive, but datetime.datetime.now(tz=UTC)
's output is not, hence I utilize .replace(tzinfo=None)
to replace the timezone information from the datetime object. Essentially, it converts the datetime object to a timezone-naive form, without any specific time zone associated with it.
For an instance:
datetime.datetime.utcnow()
output is :
2024-04-02 12:25:49.213759
datetime.datetime.now(tz=UTC)
output is:
2024-04-02 12:25:49.213766+00:00
datetime.datetime.now(tz=UTC).replace(tzinfo=None)
output is:
2024-04-02 12:25:49.213766
Hope above explanation makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks for the explanation!
Had one question. LGTM otherwise. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: roycaihw, showjason The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
What this PR does / why we need it:
datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version
Which issue(s) this PR fixes:
Fixes #2213
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: