Fix 12am and 12pm being swapped in parseATTime - #2925
Open
dylanpulver wants to merge 1 commit into
Open
Conversation
attime.py mapped an am hour straight through and a pm hour through (hour + 12) % 24, which is right for 1 through 11 and inverted at 12: "12am" parsed to 12:00 and "12pm" to 00:00. The same module already resolves "noon" to 12:00 and "midnight" to 00:00, so a single request using both spellings got two different times for the same instant. render_api.rst documents the format as at(1)-compatible, and POSIX at(1) defines midnight as "the time 12:00 am (00:00)" and noon as "the time 12:00 pm". Co-Authored-By: Claude <[email protected]>
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.
webapp/graphite/render/attime.py:84,90,96maps anamhour straight through and apmhour through(hour + 12) % 24. That is correct for 1 through 11 and inverted at 12:so
&from=12am&until=12pmgraphs noon → midnight — a different 12-hour window, silently, with no error.docs/render_api.rst:188calls the formatat(1)-compatible, and POSIXat(1)defines midnight as "the time 12:00 am (00:00)" and noon as "the time 12:00 pm". The same module already resolvesnoonto 12:00 andmidnightto 00:00, so today one request can get two different times for the same instant depending on which spelling is used.Measured with
parseATTime(ref, pytz.utc, now=2020-03-15 09:30)overmidnight, 12am, 12:30am, 1am, 11am, noon, 12pm, 12:30pm, 1pm, 11pm, teatime: 4/11 wrong before, 0/11 after; the seven controls pass on both sides.webapp/tests/test_attime.pynever used hour 12 —8:50am,8:50pm,8am,10pm— and 12 is the only hour where(h + 12) % 24is wrong, so the whole suite passed. Four cases added, in bothparseTimeReferenceTestandparseTimeReferenceTestNow.Mutants: reverting the source leaves exactly the 6 new tests failing and nothing else; fixing only the bare
Xam/Xpmbranches leaves12:30am/12:30pmfailing; fixing only thepmside leaves the three12amcases failing.manage.py test, Python 3.13 (in the CI matrix): 859 tests / 18 errors on clean master, 865 tests / 18 errors with this change — the 18 are pre-existing module-import errors from optional dependencies I don't have installed (whisper, ceres, rrdtool, redis), identical on both sides.Not tested: any hour above 12 with an am/pm suffix.
(h + 12) % 24andh % 12 + 12disagree there (13pmwas 01:00, is now 13:00), but POSIXatrestrictswallclock_hourto 1–12 so both are garbage-in. I also have not run the mysql/postgresql tox targets or anything on Windows.Written with Claude Code. On provenance: this did not come out of a production incident. I was checking
attime.py's hour handling against theat(1)semantics the docs claim, hour by hour, and 12 is where it breaks.