Skip to content

Conversation

@weirongw23-msft
Copy link
Member

@weirongw23-msft weirongw23-msft commented Oct 21, 2025

For last_modified, this is already a datetime object from the service with no microseconds supplied and timezone is defaulted to UTC. However, for change_time, creation_time, last_write_time from 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 all datetime objects timezone aware.

@weirongw23-msft weirongw23-msft marked this pull request as ready for review October 21, 2025 19:15
@Copilot Copilot AI review requested due to automatic review settings October 21, 2025 19:15
Copy link
Contributor

Copilot AI left a 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 timezone from datetime module
  • Add timezone awareness check and UTC conversion to _parse_datetime_from_str function

us = int(us[:-2]) # microseconds
datetime_obj = dt + timedelta(microseconds=us)
if not datetime_obj.tzinfo:
datetime_obj = datetime_obj.astimezone(timezone.utc)
Copy link

Copilot AI Oct 21, 2025

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.

Suggested change
datetime_obj = datetime_obj.astimezone(timezone.utc)
datetime_obj = datetime_obj.replace(tzinfo=timezone.utc)

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion

@github-actions github-actions bot added the Storage Storage Service (Queues, Blobs, Files) label Oct 21, 2025
@weirongw23-msft weirongw23-msft changed the title [Storage] Added support for timezone awareness datetimeobjects in FileProperties [Storage] Added support for timezone awareness datetime objects in FileProperties Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Storage Storage Service (Queues, Blobs, Files)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileProperties from list_directories_and_files with timestamps differs from get_file_properties on files

1 participant