Repository navigation
Fix :in-range and :out-of-range for time and datetime-local values with seconds - #323
Merged
facelessuser merged 1 commit intoOct 20, 2026
Merged
Conversation
…alues with seconds `RE_TIME` and `RE_DATETIME` only accepted `HH:MM`, but a valid time string may also carry seconds and up to three fraction digits. A value such as `12:30:15` was treated as invalid and so never out of range, and a `min` or `max` with seconds was dropped as if it were missing. Accept the optional seconds part, check it is below 60, and keep it as the last item of the parsed tuple so `18:45` and `18:45:00` still compare equal. Releases from 1.7, where these selectors were added, through 3.0.3 return the wrong result for a `time` input with `min="09:00"`, `max="11:00"` and `value="12:30:15"`.
Owner
|
Do browsers allow seconds as decimals? I will need to verify results in real browsers, but generally I think this is a good fix. |
Contributor
Author
|
Yes, up to three digits after the seconds. I opened the same 11 inputs in Chrome 155 and Firefox 149 (Developer Edition) and read
A fraction of one to three digits is read as part of the time. A fourth digit (row 4) or Page used<!doctype html>
<input id="A" type="time" min="09:00" max="11:00" value="12:30:15">
<input id="B" type="time" min="09:00" max="11:00" value="10:30:15.5">
<input id="C" type="time" min="09:00" max="11:00" value="12:30:15.123">
<input id="D" type="time" min="09:00" max="11:00" value="12:30:15.1234">
<input id="E" type="time" min="09:00:00.5" max="09:00:00.9" value="09:00:00.7">
<input id="F" type="time" min="09:00:00.5" max="09:00:00.9" value="09:00:00.95">
<input id="G" type="time" min="09:00" max="11:00" value="12:30:60">
<input id="H" type="time" min="09:00:30" max="09:00:45" value="09:00">
<input id="I" type="datetime-local" min="2026-10-20T09:00" max="2026-10-20T11:00" value="2026-10-20T12:30:15.5">
<input id="J" type="datetime-local" min="2026-10-20T09:00" max="2026-10-20T11:00" value="2026-10-20T10:30:15.250">
<input id="K" type="datetime-local" min="2026-10-20T09:00:00.5" max="2026-10-20T09:00:00.9" value="2026-10-20T09:00:00.95">
<pre id="out"></pre>
<script>
var r = [];
document.querySelectorAll('input').forEach(function (e) {
r.push(e.id + ' in=' + e.matches(':in-range') + ' out=' + e.matches(':out-of-range') + ' value="' + e.value + '"');
});
document.getElementById('out').textContent = r.join('\n');
</script> |
Owner
|
I've verified the cases as well. @gir-bot lgtm |
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.
:in-rangeand:out-of-rangetreat atimeordatetime-localvalue with seconds as invalid, so it is never out of range, and drop aminormaxwith seconds as if it were missing. The same call fails on 1.7.0, 1.9.6, 2.0.1, 2.5 and 3.0.3; 1.7 is where these selectors were added.On the current main this returns
[]and:in-rangereturns the input. It should return the input for:out-of-range. The HTML spec says a valid time string may continue after the minute with "A U+003A COLON character (:)" and "Two ASCII digits, representing the integer part of second, in the range 0 ≤ s ≤ 59", so12:30:15is valid. After the seconds it allows a fraction of "One, two, or three ASCII digits, representing the fractional part of second".RE_TIME(L60) andRE_DATETIME(L64-L66) only acceptHH:MM.Both now take optional seconds with an optional fraction of one to three digits. Seconds of 60 or more stay invalid. The parsed tuple always ends with the seconds, so
18:45and18:45:00compare equal.The new rows are in the
timeanddatetime-localtests of both files, with seconds in the value and inminandmax, a fraction,:60, and:00.python -m pytest tests/test_level4/test_in_range.py tests/test_level4/test_out_of_range.py: 4 failed before the fix, 16 passed after. Whole suite: 424 passed, 1 skipped.