Repository navigation
A MySQL TIME past a day or below zero reads as itself, so TIMEDIFF of 30 hours is 30:15:00, not null - #1411
Open
rudycelekli wants to merge 1 commit into
Open
A MySQL TIME past a day or below zero reads as itself, so TIMEDIFF of 30 hours is 30:15:00, not null#1411rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
WaylandYang
requested changes
Oct 25, 2026
WaylandYang
left a comment
Contributor
There was a problem hiding this comment.
The fix looks right, and good catch on is_negative. CI has no MySQL, so the live test never runs there. Please add a unit test of time_text built with MySqlTime::new (covering >24h, negative and microseconds). Please also keep chrono's fractional style (.500, not .500000) so existing output doesn't change.
… 30 hours is 30:15:00, not null Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
rudycelekli
force-pushed
the
mysql-time-duration
branch
from
November 5, 2026 03:28
e656234 to
bd35447
Compare
Contributor
Author
|
Rebased on dev after #1410 and #1413. time_text now writes fractions the way chrono NaiveTime does (.500, and .000500 only when it is not whole milliseconds), so output for a TIME within a day does not change. A new unit test, a_time_is_written_as_the_duration_it_holds, builds MySqlTime::new values over 24 h, negative and fractional, so it runs in CI without MySQL. |
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.
Why
A MySQL
TIMEis a signed duration from-838:59:59to838:59:59, not a time of day.TIMEDIFF,SEC_TO_TIMEandTIMEcolumns that hold elapsed hours all return it. The MySQL engine read it aschrono::NaiveTime, and that read has two problems.TIMEeither, so the cell isnull.TIMEDIFF('2024-01-02 06:15:00', '2024-01-01 00:00:00')came back asnullinstead of30:15:00.-01:30:00, came back as01:30:00, so the model reads it as 1h30 late.What changes
Cell::Timereadssqlx::mysql::types::MySqlTime, which covers the full range. It is written the way MySQL prints it: an optional-, zero-paddedHH:MM:SS, and.ffffffonly when there are microseconds. Ordinary times of day, such as08:05:00, read the same as before.The sign is taken from
sign(). In sqlx 0.8.6,MySqlTime::is_negative()returnssign.is_positive(). Using it would invert every value, and the test catches that.How it was checked
a_time_past_a_day_or_below_zero_reads_as_itself_mysql, selects twoTIMEDIFFs andCAST('08:05:00' AS TIME). It expects{"late":"30:15:00","early":"-01:30:00","start":"08:05:00"}.UTOPIA_TEST_MYSQL_URL=mysql://root:pw@127.0.0.1:13306/sales cargo test -p utopia-server --bins query_engine::mysql, run againstmariadb:11.4: 8 passed.left: ["{\"late\":null,\"early\":\"01:30:00\",\"start\":\"08:05:00\"}"].cargo fmt --all --checkandcargo clippy -p utopia-server --all-targets -- -D warningspass.Before review
git commit -s)cargo fmt --all --check,cargo clippyandcargo testpass for the touched crate