Repository navigation
Convert 12 AM to hour 0 in the 12-hour (h/a) date format - #920
Conversation
The AM/PM post-processing in `parse_pattern_with` only handled the PM side (1-11 -> +12), so an AM hour of 12 was left as 12 instead of wrapping to 0. A round bound like `gte: "12:30 AM"` under `format: "hh:mm a"` resolved to 12:30 instead of 00:30, and a midnight-hour range such as `gte "12:00 AM", lt "01:00 AM"` built an inverted `12:00 <= t < 01:00` bound that silently drops every document in that hour. Handle the AM branch: 12 -> 0, 1-11 unchanged; PM behaviour is unchanged. This matches java.time's `h` (clock-hour-of-am-pm) semantics that ES follows. Add a regression test covering AM 12/01/11 and PM 12/01.
|
Thanks for this contribution — we'd like to merge it. Before we can, we need a signed Contributor License Agreement from: @winklemad It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to Once it is merged, comment |
CI runs `cargo fmt --all --check`; rustfmt 1.9 wraps the five assert_eq! lines in `ampm_twelve_hour_tests`. No behaviour change — the fix commit is @winklemad's and is untouched.
|
@cla-bot check |
|
Re-checking the CLA status for every commit author on this pull request… |
|
Merged — thank you, and welcome. The fix is on main as your commit; the only thing added on our side was a |
|
Thanks Ivan — glad the repro made it a quick merge, and appreciate the welcome. That midnight-hour range case was a satisfying one to track down. I'll keep an eye on the repo and pick up more where it's useful. |
What this changes, and why
In the 12-hour date format (
h+a, e.g.format: "hh:mm a"), the AM/PM post-processing inparse_pattern_with(crates/xerj-query/src/dates.rs) only adjusts the PM side (1–11 → +12). An AM hour of 12 is left as12instead of wrapping to0.This contradicts the token's own docstring — "AM/PM marker (
a); shifts a 12-hour value" — and java.time'sh(clock-hour-of-am-pm) semantics that ES 8.13 follows: with anamarker, AM 12 → 0, PM 12 → 12, PM 1–11 → +12.Consequences:
gte: "12:30 AM"underformat: "hh:mm a"resolves to1970-01-01T12:30instead of00:30.{"range":{"t":{"gte":"12:00 AM","lt":"01:00 AM","format":"hh:mm a"}}}builds an inverted12:00 <= t < 01:00bound, so every document in the midnight hour is silently dropped.The fix adds the missing AM branch (12 → 0; 1–11 unchanged). PM behaviour is byte-for-byte unchanged.
Evidence
Checks
cargo fmt --all—cargo fmt -p xerj-query -- --checkclean;cargo clippy -p xerj-queryno warningscargo build --release -p xerj-query(Finished, ~59s)cargo test -p xerj-querypasses (187 passed; 0 failed)ampm_twelve_hour_tests) on the date-resolution path rather than a YAML case; happy to add ahh:mm arange case underengine/tests/es-compat-yaml/yaml/if you'd prefer that formNot run: the full ES-YAML conformance suite (
es-yaml-runner) — I did not build the full engine test crate. I ran thexerj-queryunit suite, which exercisescompile_formats→resolve_date_bound_str(the exact date-resolution path this touches) directly, and all 187 tests pass.Provenance
resolve_date_bound_str("12:30 AM", false, compile_formats("hh:mm a"))→ before:Some("1970-01-01T12:30:00.000Z"); after:Some("1970-01-01T00:30:00.000Z").cargo test -p xerj-query→ 187 passed / 0 failed (was 186 + the new test);cargo fmt --check,cargo clippy,cargo build --release -p xerj-queryall clean.h+aAM/PM behaviour only. java.time's other hour letters are collapsed into one 0–23Hourtoken here, soK(hour-of-am-pm 0–11) andk(clock-hour-of-day 1–24, where"24:00"should be00:00) remain a separate, broader gap I did not address. Falsifiable by aformat: "kk:mm"value"24:00"test.