Skip to content

[refactor] engines: use datetime.fromisoformat instead of strptime - #6394

Merged
Bnyro merged 2 commits into
searxng:masterfrom
OneVth:refactor/strptime-to-fromisoformat
Jul 13, 2026
Merged

Bnyro merged 2 commits into
searxng:masterfrom
OneVth:refactor/strptime-to-fromisoformat

Conversation

@OneVth

@OneVth OneVth commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Replace strptime calls that parse ISO 8601 dates with fromisoformat.

Changes:

  • Engines using RFC 2822 or other formats that are not compatible with ISO 8601 (e.g. bt4g, google_scholar) are left unchanged.
  • In most files this is a direct replacement of strptime(text, "format") with fromisoformat(text).
  • For code that treats Z as 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.
  • In sogou.py the date is extracted with a regular expression before strptime, so strings like "2026-7-11" can also be converted to a datetime. fromisoformat does not accept this format, so the datetime is built directly instead.

How to test this PR locally?

Run the test suite:

  • make test.unit , all 339 tests pass
  • make format.python
  • make test.pyright , no new errors compared to master

After the tests, I also ran the instance locally with make run and manually confirmed that the date rendering of several affected engines is identical before and after this PR. For example, !hf llama and !arx machine learning:

Before this PR After this PR
image image
image image

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.

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>
Comment thread searx/engines/sogou.py Outdated

@Bnyro Bnyro left a comment

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.

Looks good overall at first glance, thanks for looking into this 👍

Left one comment above.

Signed-off-by: OneVth <onebrotravel@gmail.com>

@Bnyro Bnyro left a comment

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.

Thanks!

@Bnyro
Bnyro merged commit 9e25585 into searxng:master Jul 13, 2026
6 checks passed
@OneVth
OneVth deleted the refactor/strptime-to-fromisoformat branch July 13, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Use datetime.fromisoformat instead of datetime.strptime

2 participants