Skip to content

source-impact-native: support millisecond datetime parsing in _s_to_dt function#4482

Open
SeanWhelan wants to merge 1 commit into
mainfrom
sean/source-impact-native-fractional-seconds
Open

source-impact-native: support millisecond datetime parsing in _s_to_dt function#4482
SeanWhelan wants to merge 1 commit into
mainfrom
sean/source-impact-native-fractional-seconds

Conversation

@SeanWhelan
Copy link
Copy Markdown
Contributor

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

@SeanWhelan SeanWhelan requested a review from a team May 14, 2026 23:13
Copy link
Copy Markdown
Member

@Alex-Bair Alex-Bair left a comment

Choose a reason for hiding this comment

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

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}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

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.

2 participants