[refactor] engines: use datetime.fromisoformat instead of strptime - #6394
Merged
Merged
Conversation
Refactor engines that parse ISO 8601 dates with strptime to use
fromisoformat instead. In most cases this is a direct replacement of
strptime(text, "format") with fromisoformat(text).
For engines where the source has a trailing "Z" that strptime consumed
as a literal (e.g. "%Y-%m-%dT%H:%M:%S.%fZ" in huggingface.py), add
rstrip("Z") to keep the output naive and preserve the existing behavior.
In sogou.py the date is extracted with a regular expression, which can
yield strings like "2026-7-11". strptime accepts this via its format
string, but fromisoformat does not. To preserve the existing behavior
and satisfy the format fromisoformat expects, add zero-padding for the
month and day.
Closes: searxng#6098
Signed-off-by: OneVth <onebrotravel@gmail.com>
Bnyro
reviewed
Jul 13, 2026
Bnyro
reviewed
Jul 13, 2026
Bnyro
left a comment
Member
There was a problem hiding this comment.
Looks good overall at first glance, thanks for looking into this 👍
Left one comment above.
Signed-off-by: OneVth <onebrotravel@gmail.com>
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.
What does this PR do?
Replace
strptimecalls that parse ISO 8601 dates withfromisoformat.Changes:
strptime(text, "format")withfromisoformat(text).Zas a literal (e.g."%Y-%m-%dT%H:%M:%S.%fZ"in huggingface.py),rstrip("Z")is added to keep the output naive and preserve the existing behavior.strptime, so strings like"2026-7-11"can also be converted to a datetime.fromisoformatdoes not accept this format, so thedatetimeis built directly instead.How to test this PR locally?
Run the test suite:
make test.unit, all 339 tests passmake format.pythonmake test.pyright, no new errors compared to masterAfter the tests, I also ran the instance locally with
make runand manually confirmed that the date rendering of several affected engines is identical before and after this PR. For example,!hf llamaand!arx machine learning:As shown above, the date rendering does not change before and after this PR.
Related issues
Closes: #6098
Code of Conduct
I hereby confirm that this PR conforms with the AI Policy.
If I have used AI tools for working on the changes in this PR, I will
attach a list of all AI tools I used and how I used them. I hereby confirm
that I haven't used any other tools than the ones I mention below.
I used Claude Code to understand the issue, analyze the codebase, and figure out which files needed to be changed. All other code changes were made by me.
Since English is not my native language, I used Claude Desktop to help with the commit message and this PR. I wrote the commit message and PR in my native language (Korean), and asked Claude Desktop to translate them into English and suggest suitable wording for the context.