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

Fixes isodate converter #1755

Merged
merged 2 commits into from
Mar 4, 2024
Merged

Fixes isodate converter #1755

merged 2 commits into from
Mar 4, 2024

Conversation

actlikewill
Copy link
Contributor

@actlikewill actlikewill commented Mar 4, 2024

  • This allows the converter reverse function to work with datetime objects.

closes #1669

@actlikewill actlikewill marked this pull request as ready for review March 4, 2024 11:11
@@ -70,6 +70,8 @@ def to_python(self, value):

def to_url(self, value):
# invalid values will raise ValueError which will raise NoReverseMatch
if isinstance(value, datetime):
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: we're now repeating the same code in two places. A better approach would be to get the value into the expected format (datetime) if it's not there already:

if isinstance(value, str):
    value = datetime.strptime(value, "%Y-%m-%d")
elif not isinstance(value, (datetime, date)):
    raise ValueError(value)
return value.strftime("%Y-%m-%d")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@longhotsummer agreed, converting the values to datetime and raising errors for all others is a better approach, updated

longhotsummer
longhotsummer previously approved these changes Mar 4, 2024
@actlikewill actlikewill merged commit e9fda71 into main Mar 4, 2024
9 checks passed
@actlikewill actlikewill deleted the fix-date-converter branch March 4, 2024 13:37
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.

TypeError: strptime() argument 1 must be str, not datetime.date
2 participants