Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

Convert 12 AM to hour 0 in the 12-hour (`h`/`a`) date format

Madan Kumar0c6cd0c39907
diff --git a/engine/crates/xerj-query/src/dates.rs b/engine/crates/xerj-query/src/dates.rs
index 5424b4d14..a8317315b 100644
--- a/engine/crates/xerj-query/src/dates.rs
+++ b/engine/crates/xerj-query/src/dates.rs
@@ -841,10 +841,16 @@ fn parse_pattern_with(toks: &[PatTok], value: &str, text: TextMatch) -> Option<D
if st.i != value.len() {
return None; // ES: "unparsed text found at index N"
}
- if st.has_ampm && st.pm {
+ if st.has_ampm {
if let Some(h) = st.parts.hour {
- if h < 12 {
- st.parts.hour = Some(h + 12);
+ if st.pm {
+ // PM: 12 o'clock stays 12; 1-11 shift to 13-23.
+ if h < 12 {
+ st.parts.hour = Some(h + 12);
+ }
+ } else if h == 12 {
+ // AM: 12 o'clock is hour 0 (midnight); 1-11 are unchanged.
+ st.parts.hour = Some(0);
}
}
}
@@ -2453,3 +2459,24 @@ mod ignored_metadata_field_oracle {
);
}
}
+
+#[cfg(test)]
+mod ampm_twelve_hour_tests {
+ use super::{compile_formats, resolve_date_bound_str};
+
+ fn resolve(value: &str) -> Option<String> {
+ let fmts = compile_formats("hh:mm a").unwrap();
+ resolve_date_bound_str(value, false, Some(&fmts)).unwrap()
+ }
+
+ #[test]
+ fn twelve_hour_clock_converts_to_24h_like_elasticsearch() {
+ // java.time `h` (clock-hour-of-am-pm) with the `a` marker:
+ // AM 12 -> 00, AM 1-11 unchanged, PM 12 -> 12, PM 1-11 -> +12.
+ assert_eq!(resolve("12:30 AM").as_deref(), Some("1970-01-01T00:30:00.000Z"));
+ assert_eq!(resolve("01:30 AM").as_deref(), Some("1970-01-01T01:30:00.000Z"));
+ assert_eq!(resolve("11:30 AM").as_deref(), Some("1970-01-01T11:30:00.000Z"));
+ assert_eq!(resolve("12:30 PM").as_deref(), Some("1970-01-01T12:30:00.000Z"));
+ assert_eq!(resolve("01:30 PM").as_deref(), Some("1970-01-01T13:30:00.000Z"));
+ }
+}