Skip to main content

dateoxide_core/
lib.rs

1//! High-performance, low-memory, zero-ReDoS multilingual natural-language date parser in pure Rust.
2//!
3//! `dateoxide-core` powers the Python package [`dateoxide`](https://pypi.org/project/dateoxide/)
4//! across 205 languages, non-Gregorian calendars (official Saudi Umm al-Qura Hijri,
5//! Jalali, Minguo, French Republican), time spans, and parallel batch parsing.
6//!
7//! # Quick Start
8//!
9//! ```
10//! use dateoxide_core::{calendars, parse, parse_batch, parse_with_settings, search::search_dates, settings::Settings};
11//! use chrono::{Datelike, NaiveDate, NaiveDateTime};
12//!
13//! // Fast ISO-8601, RFC-2822/3339, and ISO week date parsing
14//! let dt = parse("2026-11-26").unwrap();
15//! assert_eq!(dt.naive_local().date(), NaiveDate::from_ymd_opt(2026, 11, 26).unwrap());
16//!
17//! let iso_week = parse("2026-W48-4").unwrap();
18//! assert_eq!(iso_week.naive_local().date(), NaiveDate::from_ymd_opt(2026, 11, 26).unwrap());
19//!
20//! // Multilingual natural-language & relative parsing with fixed RELATIVE_BASE
21//! let mut settings = Settings::default();
22//! settings.relative_base = Some(
23//!     NaiveDateTime::parse_from_str("2026-11-26 15:00:00", "%Y-%m-%d %H:%M:%S").unwrap(),
24//! );
25//! let tr = parse_with_settings("3 gün önce", &settings).unwrap();
26//! assert_eq!(tr.naive_local().day(), 23);
27//!
28//! // Free-form text extraction and parallel batch parsing
29//! let found = search_dates("Meeting on 12 December 2025", &settings);
30//! assert_eq!(found.len(), 1);
31//!
32//! let batch = parse_batch(&["2026-11-26", "vor 2 Wochen", "not a date"], &settings);
33//! assert!(batch[0].is_some() && batch[1].is_some() && batch[2].is_none());
34//!
35//! // Non-Gregorian calendar conversion (official Umm al-Qura Hijri)
36//! let hijri = calendars::parse_hijri("1446/09/01", &settings);
37//! assert_eq!(hijri.date_obj.unwrap().naive_local().date(), NaiveDate::from_ymd_opt(2025, 3, 1).unwrap());
38//! ```
39
40pub mod absolute;
41#[cfg(feature = "calendars")]
42pub mod calendars;
43pub mod fast_path;
44pub mod locale;
45pub mod ranges;
46pub mod relative;
47pub mod search;
48pub mod settings;
49pub mod time_spans;
50pub mod timezone;
51#[cfg(feature = "calendars")]
52pub mod umm_al_qura;
53
54use locale::{normalize_digits_and_lower, LocaleRegistry};
55#[cfg(feature = "rayon")]
56use rayon::prelude::*;
57use search::SearchMatch;
58use settings::{DateData, ParsedDateTime, ParserKind, Period, Settings};
59use timezone::{extract_trailing_timezone_with_abbrevs, finalize_datetime};
60
61/// Parse a date string using default settings.
62#[inline]
63pub fn parse(input: &str) -> Option<ParsedDateTime> {
64    parse_with_settings(input, &Settings::default())
65}
66
67/// Parse a date string using explicit `Settings`.
68#[inline]
69pub fn parse_with_settings(input: &str, settings: &Settings) -> Option<ParsedDateTime> {
70    get_date_data(input, settings).date_obj
71}
72
73fn strip_user_skip_tokens(input: &str, skip_tokens: &[String]) -> String {
74    let mut out = Vec::new();
75    for tok in input.split_whitespace() {
76        let clean = tok.trim_matches(|c: char| c == ',' || c == '.');
77        if skip_tokens
78            .iter()
79            .any(|sk| sk.eq_ignore_ascii_case(tok) || sk.eq_ignore_ascii_case(clean))
80        {
81            continue;
82        }
83        out.push(tok);
84    }
85    out.join(" ")
86}
87
88#[inline]
89fn apply_time_period(period: Period, has_time: bool, settings: &Settings) -> Period {
90    if settings.return_time_as_period && has_time {
91        Period::Time
92    } else {
93        period
94    }
95}
96
97/// Relative-only parser backing `dateparser.freshness_date_parser.FreshnessDateDataParser`.
98pub fn parse_freshness(input: &str, settings: &Settings) -> DateData {
99    let trimmed = input.trim();
100    if trimmed.is_empty() {
101        return DateData::empty();
102    }
103    let (without_tz, tz) =
104        extract_trailing_timezone_with_abbrevs(trimmed, &settings.timezone_abbreviations);
105    let normalized = normalize_digits_and_lower(without_tz);
106    if normalized.is_empty() {
107        return DateData::empty();
108    }
109    let registry = LocaleRegistry::global();
110    let tokens: Vec<&str> = normalized
111        .split(|c: char| c.is_whitespace() || c == ',' || c == '/')
112        .map(|t| t.trim_matches(|c: char| c == '.' || c == '(' || c == ')'))
113        .filter(|t| !t.is_empty())
114        .collect();
115    let candidates = registry.detect_candidates(
116        &normalized,
117        &tokens,
118        settings.languages.as_deref(),
119        &settings.default_languages,
120        settings.normalize,
121        settings.use_given_language_order,
122    );
123    if let Some(m) = relative::try_parse_relative(&normalized, &candidates, registry, settings) {
124        return DateData {
125            date_obj: Some(finalize_datetime(m.naive, tz, settings)),
126            period: apply_time_period(m.period, m.has_time, settings),
127            locale: Some(m.locale),
128            parts: m.parts,
129            part_of_day: m.part_of_day,
130        };
131    }
132    DateData::empty()
133}
134
135/// Full `dateparser.date.DateDataParser.get_date_data` equivalent returning
136/// `DateData { date_obj, period, locale, parts, part_of_day }`.
137pub fn get_date_data(input: &str, settings: &Settings) -> DateData {
138    let trimmed_raw = input.trim();
139    if trimmed_raw.is_empty() {
140        return DateData::empty();
141    }
142
143    let owned_cleaned;
144    let trimmed: &str = if settings.skip_tokens.is_empty() {
145        trimmed_raw
146    } else {
147        owned_cleaned = strip_user_skip_tokens(trimmed_raw, &settings.skip_tokens);
148        if owned_cleaned.trim().is_empty() {
149            return DateData::empty();
150        }
151        owned_cleaned.trim()
152    };
153
154    // 0. Custom user strptime formats (`date_formats`)
155    if let Some(m) = fast_path::try_custom_formats(trimmed, settings) {
156        return DateData {
157            date_obj: Some(finalize_datetime(m.naive, m.tz, settings)),
158            period: apply_time_period(m.period, m.has_time, settings),
159            locale: Some("en".to_string()),
160            parts: m.parts,
161            part_of_day: None,
162        };
163    }
164
165    // 1. Zero-regex, zero-allocation fast path
166    if let Some(m) = fast_path::try_fast_path(trimmed, settings) {
167        return DateData {
168            date_obj: Some(finalize_datetime(m.naive, m.tz, settings)),
169            period: apply_time_period(m.period, m.has_time, settings),
170            locale: Some("en".to_string()),
171            parts: m.parts,
172            part_of_day: None,
173        };
174    }
175
176    // 2. Peel off optional trailing timezone before natural-language normalization
177    let (without_tz, tz) =
178        extract_trailing_timezone_with_abbrevs(trimmed, &settings.timezone_abbreviations);
179    let normalized = normalize_digits_and_lower(without_tz);
180    if normalized.is_empty() {
181        return DateData::empty();
182    }
183
184    // Re-check fast path if Unicode digits (e.g. Arabic-Indic / Persian) were normalized to ASCII
185    if normalized.as_bytes()[0].is_ascii_digit() && normalized != without_tz {
186        if let Some(m) = fast_path::try_fast_path(&normalized, settings) {
187            return DateData {
188                date_obj: Some(finalize_datetime(m.naive, m.tz.or(tz), settings)),
189                period: apply_time_period(m.period, m.has_time, settings),
190                locale: Some("en".to_string()),
191                parts: m.parts,
192                part_of_day: None,
193            };
194        }
195    }
196
197    // 3. Lazy-load the compact 205-language registry and detect top candidates in O(tokens)
198    let registry = LocaleRegistry::global();
199    let mut tokens: Vec<&str> = Vec::with_capacity(8);
200    for chunk in normalized.split(|c: char| {
201        c.is_whitespace() || c == ',' || c == '/' || c == '[' || c == ']' || c == '–' || c == '—'
202    }) {
203        let clean = chunk.trim_matches(|c: char| matches!(c, '.' | '(' | ')' | '[' | ']'));
204        if clean.is_empty() {
205            continue;
206        }
207        if registry.token_to_langs.contains_key(clean) {
208            tokens.push(clean);
209            continue;
210        }
211        for sub in clean.split(['-', '.']) {
212            if sub.is_empty() {
213                continue;
214            }
215            if sub.chars().any(|c| c.is_ascii_digit()) && sub.chars().any(|c| c.is_alphabetic()) {
216                let mut start = 0usize;
217                let mut prev_d = sub.chars().next().unwrap().is_ascii_digit();
218                for (idx, ch) in sub.char_indices().skip(1) {
219                    let cur_d = ch.is_ascii_digit();
220                    if cur_d != prev_d {
221                        tokens.push(&sub[start..idx]);
222                        start = idx;
223                        prev_d = cur_d;
224                    }
225                }
226                if start < sub.len() {
227                    tokens.push(&sub[start..]);
228                }
229            } else {
230                tokens.push(sub);
231            }
232        }
233    }
234
235    let candidates = registry.detect_candidates(
236        &normalized,
237        &tokens,
238        settings.languages.as_deref(),
239        &settings.default_languages,
240        settings.normalize,
241        settings.use_given_language_order,
242    );
243
244    if candidates.is_empty() {
245        if settings.allows_parser(ParserKind::RelativeTime) {
246            if let Some(m) = relative::try_conversational_clock_or_fraction(&normalized, settings) {
247                return DateData {
248                    date_obj: Some(finalize_datetime(m.naive, tz, settings)),
249                    period: apply_time_period(m.period, m.has_time, settings),
250                    locale: Some(m.locale),
251                    parts: m.parts,
252                    part_of_day: m.part_of_day,
253                };
254            }
255        }
256        let is_cjk_or_bare_year = (normalized.len() == 4
257            && normalized.bytes().all(|b| b.is_ascii_digit()))
258            || normalized.contains('年')
259            || normalized.contains('月')
260            || normalized.contains('日')
261            || normalized.contains('년')
262            || normalized.contains('월')
263            || normalized.contains('일');
264        if settings.allows_parser(ParserKind::AbsoluteTime) && is_cjk_or_bare_year {
265            if let Some(m) = absolute::try_parse_absolute(&normalized, &[], registry, settings) {
266                return DateData {
267                    date_obj: Some(finalize_datetime(m.naive, tz, settings)),
268                    period: apply_time_period(m.period, m.has_time, settings),
269                    locale: Some(m.locale),
270                    parts: m.parts,
271                    part_of_day: m.part_of_day,
272                };
273            }
274        }
275        return ignore_surrounding_fallback(trimmed, settings);
276    }
277
278    // 4. Multilingual Relative Date Engine
279    if settings.allows_parser(ParserKind::RelativeTime) {
280        if let Some(m) = relative::try_parse_relative(&normalized, &candidates, registry, settings) {
281            return DateData {
282                date_obj: Some(finalize_datetime(m.naive, tz, settings)),
283                period: apply_time_period(m.period, m.has_time, settings),
284                locale: Some(m.locale),
285                parts: m.parts,
286                part_of_day: m.part_of_day,
287            };
288        }
289    }
290
291    // 5. Multilingual Absolute & Partial Date Engine
292    if settings.allows_parser(ParserKind::AbsoluteTime) {
293        if let Some(m) = absolute::try_parse_absolute(&normalized, &candidates, registry, settings) {
294            return DateData {
295                date_obj: Some(finalize_datetime(m.naive, tz, settings)),
296                period: apply_time_period(m.period, m.has_time, settings),
297                locale: Some(m.locale),
298                parts: m.parts,
299                part_of_day: m.part_of_day,
300            };
301        }
302    }
303
304    ignore_surrounding_fallback(trimmed, settings)
305}
306
307fn ignore_surrounding_fallback(trimmed: &str, settings: &Settings) -> DateData {
308    if !settings.ignore_surrounding_text {
309        return DateData::empty();
310    }
311    let mut inner = settings.clone();
312    inner.ignore_surrounding_text = false;
313    let found = search_dates_full(trimmed, &inner);
314    if let Some(first) = found.into_iter().next() {
315        return DateData {
316            date_obj: Some(first.date_obj),
317            period: first.period,
318            locale: first.locale,
319            parts: vec!["year", "month", "day"],
320            part_of_day: None,
321        };
322    }
323    DateData::empty()
324}
325
326/// Parallel batch parsing powered by Rayon across all available CPU cores
327/// (falls back to sequential iteration when the `rayon` feature is disabled).
328pub fn parse_batch<S: AsRef<str> + Sync>(
329    inputs: &[S],
330    settings: &Settings,
331) -> Vec<Option<ParsedDateTime>> {
332    #[cfg(feature = "rayon")]
333    {
334        if inputs.len() < 256 {
335            return inputs
336                .iter()
337                .map(|s| parse_with_settings(s.as_ref(), settings))
338                .collect();
339        }
340        return inputs
341            .par_iter()
342            .map(|s| parse_with_settings(s.as_ref(), settings))
343            .collect();
344    }
345    #[cfg(not(feature = "rayon"))]
346    {
347        inputs
348            .iter()
349            .map(|s| parse_with_settings(s.as_ref(), settings))
350            .collect()
351    }
352}
353
354/// Nullable parallel batch parsing (`Option<String>` inputs skip `None` cleanly).
355pub fn parse_batch_opt<S: AsRef<str> + Sync>(
356    inputs: &[Option<S>],
357    settings: &Settings,
358) -> Vec<Option<ParsedDateTime>> {
359    #[cfg(feature = "rayon")]
360    {
361        if inputs.len() < 256 {
362            return inputs
363                .iter()
364                .map(|opt| opt.as_ref().and_then(|s| parse_with_settings(s.as_ref(), settings)))
365                .collect();
366        }
367        return inputs
368            .par_iter()
369            .map(|opt| opt.as_ref().and_then(|s| parse_with_settings(s.as_ref(), settings)))
370            .collect();
371    }
372    #[cfg(not(feature = "rayon"))]
373    {
374        inputs
375            .iter()
376            .map(|opt| opt.as_ref().and_then(|s| parse_with_settings(s.as_ref(), settings)))
377            .collect()
378    }
379}
380
381/// Parse natural-language or numeric date/time ranges into `(start, end)`.
382pub fn parse_date_range(
383    input: &str,
384    settings: &Settings,
385) -> Option<(ParsedDateTime, ParsedDateTime)> {
386    ranges::parse_date_range(input, settings)
387}
388
389/// Find and parse all date expressions embedded in free-form text.
390pub fn search_dates(text: &str, settings: &Settings) -> Vec<(String, ParsedDateTime)> {
391    search::search_dates(text, settings)
392}
393
394/// Find and parse all date expressions embedded in free-form text, including detected locale code.
395pub fn search_dates_with_locale(
396    text: &str,
397    settings: &Settings,
398) -> Vec<(String, ParsedDateTime, Option<String>)> {
399    search::search_dates_with_locale(text, settings)
400}
401
402/// Find and parse all date expressions returning full match metadata.
403pub fn search_dates_full(text: &str, settings: &Settings) -> Vec<SearchMatch> {
404    search::search_dates_full(text, settings)
405}
406
407#[cfg(test)]
408mod tests {
409    use super::*;
410    use chrono::{NaiveDate, NaiveDateTime, NaiveTime, Timelike};
411    use settings::{DateOrder, PartOfDay, PreferDatesFrom, PreferDayOfMonth, StrictDateOrder};
412
413    fn fixed_settings() -> Settings {
414        Settings {
415            relative_base: Some(
416                NaiveDate::from_ymd_opt(2026, 11, 26)
417                    .unwrap()
418                    .and_hms_opt(15, 0, 0)
419                    .unwrap(),
420            ),
421            ..Default::default()
422        }
423    }
424
425    #[test]
426    fn test_fast_path_and_strict_date_order() {
427        let mut s = fixed_settings();
428        s.date_order = Some(DateOrder::MDY);
429        s.strict_date_order = StrictDateOrder::None;
430        assert_eq!(
431            parse_with_settings("26/11/2026", &s).unwrap().naive_local().date(),
432            NaiveDate::from_ymd_opt(2026, 11, 26).unwrap()
433        );
434
435        s.strict_date_order = StrictDateOrder::All;
436        assert!(parse_with_settings("26/11/2026", &s).is_none());
437        assert_eq!(
438            parse_with_settings("2026/11/26", &s).unwrap().naive_local().date(),
439            NaiveDate::from_ymd_opt(2026, 11, 26).unwrap()
440        );
441    }
442
443    #[cfg(feature = "calendars")]
444    #[test]
445    fn test_calendars_conversions() {
446        let s = fixed_settings();
447        assert_eq!(
448            calendars::jalali_to_gregorian(1395, 1, 1),
449            Some(NaiveDate::from_ymd_opt(2016, 3, 20).unwrap())
450        );
451        assert_eq!(
452            calendars::jalali_to_gregorian(1400, 1, 1),
453            Some(NaiveDate::from_ymd_opt(2021, 3, 21).unwrap())
454        );
455        assert_eq!(
456            calendars::jalali_to_gregorian(1404, 9, 5),
457            Some(NaiveDate::from_ymd_opt(2025, 11, 26).unwrap())
458        );
459        assert_eq!(
460            calendars::parse_jalali("۵ آذر ۱۴۰۴", &s).date_obj.unwrap().naive_local().date(),
461            NaiveDate::from_ymd_opt(2025, 11, 26).unwrap()
462        );
463
464        assert_eq!(
465            calendars::hijri_to_gregorian(1445, 1, 1),
466            Some(NaiveDate::from_ymd_opt(2023, 7, 19).unwrap())
467        );
468        assert_eq!(
469            calendars::hijri_to_gregorian(1446, 9, 1),
470            Some(NaiveDate::from_ymd_opt(2025, 3, 1).unwrap())
471        );
472
473        assert_eq!(
474            calendars::parse_minguo("115年11月26日", &s).date_obj.unwrap().naive_local().date(),
475            NaiveDate::from_ymd_opt(2026, 11, 26).unwrap()
476        );
477
478        assert_eq!(
479            calendars::french_republican_to_gregorian(1, 1, 1),
480            Some(NaiveDate::from_ymd_opt(1792, 9, 22).unwrap())
481        );
482        assert_eq!(
483            calendars::parse_french_republican("14 Germinal an III", &s)
484                .date_obj
485                .unwrap()
486                .naive_local()
487                .date(),
488            NaiveDate::from_ymd_opt(1795, 4, 3).unwrap()
489        );
490    }
491
492    #[test]
493    fn test_parts_of_day_bare_durations_and_surrounding_text() {
494        let mut s = fixed_settings();
495        s.parts_of_day.morning = NaiveTime::from_hms_opt(8, 30, 0).unwrap();
496        let dd = get_date_data("yesterday morning", &s);
497        assert_eq!(
498            dd.date_obj.unwrap().naive_local(),
499            NaiveDate::from_ymd_opt(2026, 11, 25)
500                .unwrap()
501                .and_hms_opt(8, 30, 0)
502                .unwrap()
503        );
504        assert_eq!(dd.part_of_day, Some(PartOfDay::Morning));
505        assert_eq!(dd.parts, vec!["year", "month", "day", "time"]);
506
507        // Bare duration
508        let d_bare = parse_with_settings("2 days", &fixed_settings()).unwrap();
509        assert_eq!(d_bare.naive_local().date(), NaiveDate::from_ymd_opt(2026, 11, 24).unwrap());
510
511        // Week period
512        let dd_week = get_date_data("last week", &fixed_settings());
513        assert_eq!(dd_week.period, Period::Week);
514
515        // Ignore surrounding text
516        let mut s_ign = fixed_settings();
517        s_ign.ignore_surrounding_text = true;
518        assert_eq!(
519            parse_with_settings("Published: 12 December 2025", &s_ign)
520                .unwrap()
521                .naive_local()
522                .date(),
523            NaiveDate::from_ymd_opt(2025, 12, 12).unwrap()
524        );
525    }
526
527    #[test]
528    fn test_time_spans_and_custom_tz_abbrevs() {
529        let mut s = fixed_settings();
530        s.return_time_span = true;
531        let span_matches = search_dates_full("Show logs from last week please", &s);
532        assert_eq!(span_matches.len(), 2);
533
534        let mut s_tz = fixed_settings();
535        s_tz.timezone_abbreviations
536            .insert("FOO".to_string(), "+04:30".to_string());
537        s_tz.return_as_timezone_aware = Some(true);
538        let dt = parse_with_settings("2026-11-26 10:00 FOO", &s_tz).unwrap();
539        assert!(dt.is_aware());
540        assert_eq!(dt.naive_local().hour(), 10);
541    }
542
543    #[test]
544    fn test_timezone_conversion_and_preferences() {
545        let mut s = fixed_settings();
546        s.to_timezone = Some("Europe/Istanbul".to_string());
547        s.return_as_timezone_aware = Some(true);
548        let dt = parse_with_settings("2026-11-26T12:00:00Z", &s).unwrap();
549        assert_eq!(
550            dt.naive_local(),
551            NaiveDateTime::parse_from_str("2026-11-26 15:00:00", "%Y-%m-%d %H:%M:%S").unwrap()
552        );
553
554        s.prefer_day_of_month = PreferDayOfMonth::First;
555        assert_eq!(
556            parse_with_settings("December 2025", &s).unwrap().naive_local().date(),
557            NaiveDate::from_ymd_opt(2025, 12, 1).unwrap()
558        );
559        s.prefer_dates_from = PreferDatesFrom::Past;
560        assert_eq!(
561            parse_with_settings("December 15", &s).unwrap().naive_local().date(),
562            NaiveDate::from_ymd_opt(2025, 12, 15).unwrap()
563        );
564    }
565
566    #[test]
567    fn test_iso_week_dates_and_year_zero_guard() {
568        let s = fixed_settings();
569        assert_eq!(
570            parse_with_settings("2026-W48-4", &s).unwrap().naive_local().date(),
571            NaiveDate::from_ymd_opt(2026, 11, 26).unwrap()
572        );
573        assert_eq!(
574            parse_with_settings("2026-W48", &s).unwrap().naive_local().date(),
575            NaiveDate::from_ymd_opt(2026, 11, 23).unwrap()
576        );
577        assert_eq!(
578            parse_with_settings("2026W484", &s).unwrap().naive_local().date(),
579            NaiveDate::from_ymd_opt(2026, 11, 26).unwrap()
580        );
581        assert!(parse_with_settings("2026-W54-1", &s).is_none());
582        assert!(parse_with_settings("0000-01-01", &s).is_none());
583
584        let mut s_strict = fixed_settings();
585        s_strict.strict_parsing = true;
586        assert!(parse_with_settings("2026-W48", &s_strict).is_none());
587    }
588
589    #[test]
590    fn test_no_spaces_time_and_time_only_preferences() {
591        let mut s_ns = fixed_settings();
592        s_ns.parsers = Some(vec![ParserKind::NoSpacesTime]);
593        assert_eq!(
594            parse_with_settings("1430", &s_ns).unwrap().naive_local(),
595            NaiveDate::from_ymd_opt(2026, 11, 26)
596                .unwrap()
597                .and_hms_opt(14, 30, 0)
598                .unwrap()
599        );
600        assert_eq!(
601            parse_with_settings("143025", &s_ns).unwrap().naive_local(),
602            NaiveDate::from_ymd_opt(2026, 11, 26)
603                .unwrap()
604                .and_hms_opt(14, 30, 25)
605                .unwrap()
606        );
607        s_ns.date_order = Some(DateOrder::DMY);
608        assert_eq!(
609            parse_with_settings("26112026", &s_ns).unwrap().naive_local().date(),
610            NaiveDate::from_ymd_opt(2026, 11, 26).unwrap()
611        );
612        s_ns.date_order = Some(DateOrder::MDY);
613        assert_eq!(
614            parse_with_settings("11262026", &s_ns).unwrap().naive_local().date(),
615            NaiveDate::from_ymd_opt(2026, 11, 26).unwrap()
616        );
617
618        let mut s_fut = fixed_settings();
619        s_fut.prefer_dates_from = PreferDatesFrom::Future;
620        assert_eq!(
621            parse_with_settings("09:00", &s_fut).unwrap().naive_local(),
622            NaiveDate::from_ymd_opt(2026, 11, 27)
623                .unwrap()
624                .and_hms_opt(9, 0, 0)
625                .unwrap()
626        );
627
628        let mut s_past = fixed_settings();
629        s_past.prefer_dates_from = PreferDatesFrom::Past;
630        assert_eq!(
631            parse_with_settings("18:00", &s_past).unwrap().naive_local(),
632            NaiveDate::from_ymd_opt(2026, 11, 25)
633                .unwrap()
634                .and_hms_opt(18, 0, 0)
635                .unwrap()
636        );
637    }
638
639    #[test]
640    fn test_search_dates_false_positive_guards() {
641        let s = fixed_settings();
642        let found = search_dates_full("Let us meet tomorrow at 5pm or next Friday.", &s);
643        assert!(!found.iter().any(|m| m.text == "Let"));
644        assert_eq!(found.len(), 2);
645
646        assert!(search_dates_full("She can see her man, did you say?", &s).is_empty());
647        assert!(search_dates_full("Python 3.12.1 on 192.168.1.1", &s).is_empty());
648    }
649}