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

Replace deprecated utcfromtimestamp method #21799

Merged

Conversation

dbrtly
Copy link
Contributor

@dbrtly dbrtly commented May 12, 2024

Summary & Motivation

Fixes issue mentioned by @psarka

Refactors method to explicitly specify timezone when converting from unix timestamp to ISO8601.
Subsequently retains or discards the timezone depending on existing functionality.

How I Tested These Changes

There is probably a good learning opportunity for me here. I used a snippet to validate the output was unchanged.
Please educate me about how you want to do this properly.

Daniel Bartley added 2 commits May 12, 2024 14:15
## Summary & Motivation

Fixes issue mentioned by @psarka

Refactors method to explicitly specify timezone when converting from unix timestamp to ISO8601.
Discards the timezone for backwards compatibility as datetime.

## How I Tested These Changes

There is probably a good learning opportunity for me here. I used this snippet.
Please educate me about how you want to do this properly.

# convert unix timestamp at UTC at second precision to iso8601 timestamp at implicit utc of type timestamp.timestamp
from datetime import datetime, timezone

unix_milliseconds = 1715478630.0 * 1000
before = datetime.datetime.utcfromtimestamp(int(unix_milliseconds) / 1000)
print('before is ', before, type(before))

after=datetime.datetime.fromtimestamp(int(unix_milliseconds) / 1000, timezone.utc).replace(tzinfo=None)
print('after is None ', after, type(after))

assert before == after
## Summary & Motivation

Fixes issue mentioned by @psarka

Refactors method to explicitly specify timezone when converting from unix timestamp to ISO8601.
Retains timezone as per existing functionality.

## How I Tested These Changes

There is probably a good learning opportunity for me here. I used this snippet.
Please educate me about how you want to do this properly.

# convert unix timestamp at UTC at second precision to iso8601 timestamp at implicit utc of type timestamp.timestamp
from datetime import datetime, timezone

unix_milliseconds = 1715478630.0 * 1000
before = datetime.datetime.utcfromtimestamp(int(unix_milliseconds) / 1000)
print('before is ', before, type(before))

after=datetime.datetime.fromtimestamp(int(unix_milliseconds) / 1000, timezone.utc)
print('after is None ', after, type(after))

assert before == after
@gibsondan gibsondan self-requested a review May 15, 2024 18:46
@gibsondan
Copy link
Member

Thanks @dbrtly - I ran this through our CI which exercises these paths and did not see any issues, I think we can go ahead and merge this.

@gibsondan gibsondan merged commit b003936 into dagster-io:master May 15, 2024
1 check failed
@dbrtly dbrtly deleted the replace-deprecated-utcfromtimestamp-method branch May 15, 2024 20:56
@garethbrickman garethbrickman linked an issue May 16, 2024 that may be closed by this pull request
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.

Replace deprecated utcfromtimestamp method
2 participants