Skip to content

timedelta: support microseconds and negative values - #795

Open
methane wants to merge 1 commit into
PyMySQL:mainfrom
methane:fix-timedelta
Open

timedelta: support microseconds and negative values#795
methane wants to merge 1 commit into
PyMySQL:mainfrom
methane:fix-timedelta

Conversation

@methane

@methane methane commented Aug 18, 2026

Copy link
Copy Markdown
Member

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.66%. Comparing base (e2a908b) to head (2487dee).
⚠️ Report is 49 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #795      +/-   ##
==========================================
+ Coverage   88.86%   90.66%   +1.79%     
==========================================
  Files           7        7              
  Lines         548      557       +9     
==========================================
+ Hits          487      505      +18     
+ Misses         61       52       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates MySQLdb’s timedelta string formatting to correctly handle negative values and to include microseconds, aligning both literal conversion and formatting behavior with MySQL’s expected TIME literal semantics.

Changes:

  • Fix format_TIMEDELTA to render negative timedeltas with a single leading sign and an absolute-value day/time component (avoids MySQL interpreting a “double-negative”).
  • Extend format_TIMEDELTA output to include fractional seconds when timedelta.microseconds is non-zero.
  • Expand/adjust tests to cover negative timedeltas and microsecond precision, and update an existing negative-case expectation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/test_MySQLdb_times.py Adds/updates assertions for negative and microsecond-precision timedelta formatting and literals.
src/MySQLdb/times.py Revises format_TIMEDELTA to correctly handle negative timedeltas and microseconds.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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