source-impact-native: support millisecond datetime parsing in _s_to_dt function#4482
Open
SeanWhelan wants to merge 1 commit into
Open
source-impact-native: support millisecond datetime parsing in _s_to_dt function#4482SeanWhelan wants to merge 1 commit into
SeanWhelan wants to merge 1 commit into
Conversation
Alex-Bair
approved these changes
May 15, 2026
Member
Alex-Bair
left a comment
There was a problem hiding this comment.
LGTM % a potential simplification
Comment on lines
415
to
+421
| def _s_to_dt(date: str): | ||
| date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S%z") | ||
| return date | ||
| for fmt in ("%Y-%m-%dT%H:%M:%S.%f%z", "%Y-%m-%dT%H:%M:%S%z"): | ||
| try: | ||
| return datetime.strptime(date, fmt) | ||
| except ValueError: | ||
| continue | ||
| raise ValueError(f"unrecognized datetime format: {date}") |
Member
There was a problem hiding this comment.
If these strings are always in ISO 8601 format (which seems to be true based off the two formats here?), this could be simplified with datetime.fromisoformat:
Suggested change
| def _s_to_dt(date: str): | |
| date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S%z") | |
| return date | |
| for fmt in ("%Y-%m-%dT%H:%M:%S.%f%z", "%Y-%m-%dT%H:%M:%S%z"): | |
| try: | |
| return datetime.strptime(date, fmt) | |
| except ValueError: | |
| continue | |
| raise ValueError(f"unrecognized datetime format: {date}") | |
| def _s_to_dt(date: str) -> datetime: | |
| return datetime.fromisoformat(date) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Fix source-impact-native cursor parsing to accept timestamps with fractional seconds. The Impact API's Tasks endpoint returns CreationDate values like 2024-07-17T21:55:46.000+0000, which _s_to_dt could not parse because its strptime format string (%Y-%m-%dT%H:%M:%S%z) had no .%f component. The helper now tries the fractional-second format first and falls back to the original, raising a clear ValueError if neither matches. Other Impact endpoints that omit fractional seconds continue to parse as before.
Workflow steps:
N/A
Documentation links affected:
N/A
Notes for reviewers:
N/A