-
Couldn't load subscription status.
- Fork 3.2k
[Storage] Added support for timezone awareness datetime objects in FileProperties
#43566
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
base: main
Are you sure you want to change the base?
[Storage] Added support for timezone awareness datetime objects in FileProperties
#43566
Conversation
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.
Pull Request Overview
This PR adds timezone awareness to datetime objects in FileProperties by ensuring all parsed datetime values are converted to UTC timezone when they lack timezone information.
Key Changes:
- Import
timezonefrom datetime module - Add timezone awareness check and UTC conversion to
_parse_datetime_from_strfunction
| us = int(us[:-2]) # microseconds | ||
| datetime_obj = dt + timedelta(microseconds=us) | ||
| if not datetime_obj.tzinfo: | ||
| datetime_obj = datetime_obj.astimezone(timezone.utc) |
Copilot
AI
Oct 21, 2025
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.
Calling astimezone() on a naive datetime object (one without tzinfo) will raise a ValueError. Use datetime_obj.replace(tzinfo=timezone.utc) instead to set UTC timezone on naive datetime objects.
| datetime_obj = datetime_obj.astimezone(timezone.utc) | |
| datetime_obj = datetime_obj.replace(tzinfo=timezone.utc) |
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.
Good suggestion
datetimeobjects in FilePropertiesdatetime objects in FileProperties
For
last_modified, this is already adatetimeobject from the service with no microseconds supplied andtimezoneis defaulted to UTC. However, forchange_time,creation_time,last_write_timefrom the service is returned as a string object, to be parsed into datetime, and is assumed to be UTC. This PR ensures consistency across all the fields and make alldatetimeobjects timezone aware.