dateoxide 0.1.1__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {dateoxide-0.1.1 → dateoxide-0.2.0}/Cargo.lock +2 -2
  2. {dateoxide-0.1.1 → dateoxide-0.2.0}/Cargo.toml +1 -1
  3. {dateoxide-0.1.1 → dateoxide-0.2.0}/PKG-INFO +10 -13
  4. {dateoxide-0.1.1 → dateoxide-0.2.0}/README.md +9 -12
  5. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/Cargo.toml +10 -1
  6. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/README.md +9 -12
  7. dateoxide-0.2.0/crates/dateoxide-core/benches/parse_bench.rs +51 -0
  8. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/fast_path.rs +1 -1
  9. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/lib.rs +35 -7
  10. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/locale/mod.rs +25 -3
  11. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/relative.rs +370 -31
  12. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/search.rs +12 -0
  13. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/time_spans.rs +46 -1
  14. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/timezone.rs +15 -8
  15. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-py/src/lib.rs +146 -44
  16. {dateoxide-0.1.1 → dateoxide-0.2.0}/pyproject.toml +1 -1
  17. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/conf.py +1 -5
  18. dateoxide-0.2.0/python/dateoxide/py.typed +0 -0
  19. {dateoxide-0.1.1 → dateoxide-0.2.0}/LICENSE +0 -0
  20. {dateoxide-0.1.1 → dateoxide-0.2.0}/NOTICE +0 -0
  21. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/build.rs +0 -0
  22. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/data/locales.json +0 -0
  23. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/absolute.rs +0 -0
  24. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/calendars.rs +0 -0
  25. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/locale/schema.rs +0 -0
  26. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/settings.rs +0 -0
  27. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-core/src/umm_al_qura.rs +0 -0
  28. {dateoxide-0.1.1 → dateoxide-0.2.0}/crates/dateoxide-py/Cargo.toml +0 -0
  29. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/__init__.py +0 -0
  30. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/__init__.pyi +0 -0
  31. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/calendars/__init__.py +0 -0
  32. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/calendars/french_republican.py +0 -0
  33. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/calendars/hijri.py +0 -0
  34. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/calendars/jalali.py +0 -0
  35. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/calendars/minguo.py +0 -0
  36. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/date.py +0 -0
  37. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/freshness_date_parser.py +0 -0
  38. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/search.py +0 -0
  39. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/timezone_parser.py +0 -0
  40. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/utils/__init__.py +0 -0
  41. {dateoxide-0.1.1 → dateoxide-0.2.0}/python/dateoxide/utils/time_spans.py +0 -0
@@ -247,7 +247,7 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
247
247
 
248
248
  [[package]]
249
249
  name = "dateoxide-core"
250
- version = "0.1.1"
250
+ version = "0.2.0"
251
251
  dependencies = [
252
252
  "aho-corasick",
253
253
  "chrono",
@@ -263,7 +263,7 @@ dependencies = [
263
263
 
264
264
  [[package]]
265
265
  name = "dateoxide-py"
266
- version = "0.1.1"
266
+ version = "0.2.0"
267
267
  dependencies = [
268
268
  "chrono",
269
269
  "chrono-tz",
@@ -3,7 +3,7 @@ resolver = "2"
3
3
  members = ["crates/dateoxide-core", "crates/dateoxide-py"]
4
4
 
5
5
  [workspace.package]
6
- version = "0.1.1"
6
+ version = "0.2.0"
7
7
  edition = "2021"
8
8
  license = "MIT OR Apache-2.0"
9
9
  repository = "https://github.com/Pastalikek65/dateoxide"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dateoxide
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -92,20 +92,17 @@ python benchmarks/torture_benchmark.py --json
92
92
 
93
93
  ### Independent Torture Benchmark (Accuracy, ReDoS & Known Differences)
94
94
 
95
- Measured with [`benchmarks/torture_benchmark.py`](benchmarks/torture_benchmark.py) across 79 adversarial cases (multilingual casing/scripts, month-end clamping, leap/ISO-week traps, RFC/CLF/DST, false-positive traps), dirty `search_dates`, and 6 ReDoS stress bombs (`dateoxide 0.1.0` vs `dateparser 1.5.1` on Windows 11, 32-core, Python 3.12.10):
95
+ Measured with [`benchmarks/torture_benchmark.py`](benchmarks/torture_benchmark.py) across 79 adversarial cases (multilingual casing/scripts, fractional/conversational phrases, month-end clamping, leap/ISO-week traps, RFC/CLF/DST, false-positive traps), dirty `search_dates`, and 6 ReDoS stress bombs (`dateoxide 0.2.0` vs `dateparser 1.5.1` on Python 3.12.10):
96
96
 
97
- | Metric | `dateparser 1.5.1` | `dateoxide` |
97
+ | Metric | `dateparser 1.5.1` | `dateoxide 0.2.0` |
98
98
  | :--- | ---: | ---: |
99
- | **Torture accuracy (79 hard cases)** | 66 / 79 (`1,675.90 ms`) | **74 / 79 (`0.77 ms`)** |
100
- | **Dirty `search_dates` (6 docs)** | 4 / 6 (`678.77 ms`) | **5 / 6 (`0.47 ms`)** |
101
- | **6 ReDoS stress bombs (3k–5k chars)** | `8,298.90 ms` | **`2.51 ms`** |
102
- | **Full 79-case isolated throughput & RSS** | `134.0 /s` (`+64.79 MB`) | **`38,938.5 /s` (`+10.21 MB`)** *(290.6x)* |
103
-
104
- **Transparently noted misses & differences (`5 / 79` on `dateoxide`):**
105
- - `"the day after tomorrow"` returns `None` (`"day after tomorrow"` works; leading `"the"` isn't stripped yet; `dateparser` parses it).
106
- - `"quarter past 3"` and `"two and a half hours ago"` return `None` in **both** `dateoxide` and `dateparser`.
107
- - `"last Friday"` preserves `RELATIVE_BASE` time (`15:00`) in `dateoxide`, whereas `dateparser` resets time to `00:00`.
108
- - `"2026-13-01"` swaps to `2026-01-13` under default `STRICT_DATE_ORDER="none"` in **both** libraries (set `STRICT_DATE_ORDER="all"` to reject).
99
+ | **Torture accuracy (79 hard cases)** | 66 / 79 (`4,243.30 ms`) | **78 / 79 (`1.60 ms`)** |
100
+ | **Dirty `search_dates` (6 docs)** | 4 / 6 (`1,885.91 ms`) | **6 / 6 (`0.48 ms`)** |
101
+ | **6 ReDoS stress bombs (3k–5k chars)** | `20,111.62 ms` | **`5.46 ms`** |
102
+ | **Full 79-case isolated throughput & RSS** | `57.4 /s` (`+64.52 MB`) | **`20,629.9 /s` (`+10.24 MB`)** *(359.4x)* |
103
+
104
+ **Transparently noted difference (`1 / 79`):**
105
+ - `"2026-13-01"` swaps to `2026-01-13` under default `STRICT_DATE_ORDER="none"` in **both** `dateoxide` and `dateparser` (set `STRICT_DATE_ORDER="all"` to reject invalid month indices strictly).
109
106
 
110
107
  ---
111
108
 
@@ -59,20 +59,17 @@ python benchmarks/torture_benchmark.py --json
59
59
 
60
60
  ### Independent Torture Benchmark (Accuracy, ReDoS & Known Differences)
61
61
 
62
- Measured with [`benchmarks/torture_benchmark.py`](benchmarks/torture_benchmark.py) across 79 adversarial cases (multilingual casing/scripts, month-end clamping, leap/ISO-week traps, RFC/CLF/DST, false-positive traps), dirty `search_dates`, and 6 ReDoS stress bombs (`dateoxide 0.1.0` vs `dateparser 1.5.1` on Windows 11, 32-core, Python 3.12.10):
62
+ Measured with [`benchmarks/torture_benchmark.py`](benchmarks/torture_benchmark.py) across 79 adversarial cases (multilingual casing/scripts, fractional/conversational phrases, month-end clamping, leap/ISO-week traps, RFC/CLF/DST, false-positive traps), dirty `search_dates`, and 6 ReDoS stress bombs (`dateoxide 0.2.0` vs `dateparser 1.5.1` on Python 3.12.10):
63
63
 
64
- | Metric | `dateparser 1.5.1` | `dateoxide` |
64
+ | Metric | `dateparser 1.5.1` | `dateoxide 0.2.0` |
65
65
  | :--- | ---: | ---: |
66
- | **Torture accuracy (79 hard cases)** | 66 / 79 (`1,675.90 ms`) | **74 / 79 (`0.77 ms`)** |
67
- | **Dirty `search_dates` (6 docs)** | 4 / 6 (`678.77 ms`) | **5 / 6 (`0.47 ms`)** |
68
- | **6 ReDoS stress bombs (3k–5k chars)** | `8,298.90 ms` | **`2.51 ms`** |
69
- | **Full 79-case isolated throughput & RSS** | `134.0 /s` (`+64.79 MB`) | **`38,938.5 /s` (`+10.21 MB`)** *(290.6x)* |
70
-
71
- **Transparently noted misses & differences (`5 / 79` on `dateoxide`):**
72
- - `"the day after tomorrow"` returns `None` (`"day after tomorrow"` works; leading `"the"` isn't stripped yet; `dateparser` parses it).
73
- - `"quarter past 3"` and `"two and a half hours ago"` return `None` in **both** `dateoxide` and `dateparser`.
74
- - `"last Friday"` preserves `RELATIVE_BASE` time (`15:00`) in `dateoxide`, whereas `dateparser` resets time to `00:00`.
75
- - `"2026-13-01"` swaps to `2026-01-13` under default `STRICT_DATE_ORDER="none"` in **both** libraries (set `STRICT_DATE_ORDER="all"` to reject).
66
+ | **Torture accuracy (79 hard cases)** | 66 / 79 (`4,243.30 ms`) | **78 / 79 (`1.60 ms`)** |
67
+ | **Dirty `search_dates` (6 docs)** | 4 / 6 (`1,885.91 ms`) | **6 / 6 (`0.48 ms`)** |
68
+ | **6 ReDoS stress bombs (3k–5k chars)** | `20,111.62 ms` | **`5.46 ms`** |
69
+ | **Full 79-case isolated throughput & RSS** | `57.4 /s` (`+64.52 MB`) | **`20,629.9 /s` (`+10.24 MB`)** *(359.4x)* |
70
+
71
+ **Transparently noted difference (`1 / 79`):**
72
+ - `"2026-13-01"` swaps to `2026-01-13` under default `STRICT_DATE_ORDER="none"` in **both** `dateoxide` and `dateparser` (set `STRICT_DATE_ORDER="all"` to reject invalid month indices strictly).
76
73
 
77
74
  ---
78
75
 
@@ -11,12 +11,17 @@ description = "High-performance, low-memory multilingual natural-language date p
11
11
  keywords = ["date", "datetime", "parser", "multilingual", "nlp"]
12
12
  categories = ["date-and-time", "internationalization", "parsing", "text-processing"]
13
13
 
14
+ [features]
15
+ default = ["rayon", "calendars"]
16
+ rayon = ["dep:rayon"]
17
+ calendars = []
18
+
14
19
  [dependencies]
15
20
  aho-corasick = "1.1"
16
21
  chrono = { version = "0.4", features = ["serde"] }
17
22
  chrono-tz = "0.10"
18
23
  postcard = { version = "1.1", features = ["alloc"] }
19
- rayon = "1.10"
24
+ rayon = { version = "1.10", optional = true }
20
25
  regex = "1.11"
21
26
  rustc-hash = "2.1"
22
27
  serde = { version = "1.0", features = ["derive"] }
@@ -28,3 +33,7 @@ serde_json = "1.0"
28
33
 
29
34
  [dev-dependencies]
30
35
  criterion = "0.5"
36
+
37
+ [[bench]]
38
+ name = "parse_bench"
39
+ harness = false
@@ -59,20 +59,17 @@ python benchmarks/torture_benchmark.py --json
59
59
 
60
60
  ### Independent Torture Benchmark (Accuracy, ReDoS & Known Differences)
61
61
 
62
- Measured with [`benchmarks/torture_benchmark.py`](benchmarks/torture_benchmark.py) across 79 adversarial cases (multilingual casing/scripts, month-end clamping, leap/ISO-week traps, RFC/CLF/DST, false-positive traps), dirty `search_dates`, and 6 ReDoS stress bombs (`dateoxide 0.1.0` vs `dateparser 1.5.1` on Windows 11, 32-core, Python 3.12.10):
62
+ Measured with [`benchmarks/torture_benchmark.py`](benchmarks/torture_benchmark.py) across 79 adversarial cases (multilingual casing/scripts, fractional/conversational phrases, month-end clamping, leap/ISO-week traps, RFC/CLF/DST, false-positive traps), dirty `search_dates`, and 6 ReDoS stress bombs (`dateoxide 0.2.0` vs `dateparser 1.5.1` on Python 3.12.10):
63
63
 
64
- | Metric | `dateparser 1.5.1` | `dateoxide` |
64
+ | Metric | `dateparser 1.5.1` | `dateoxide 0.2.0` |
65
65
  | :--- | ---: | ---: |
66
- | **Torture accuracy (79 hard cases)** | 66 / 79 (`1,675.90 ms`) | **74 / 79 (`0.77 ms`)** |
67
- | **Dirty `search_dates` (6 docs)** | 4 / 6 (`678.77 ms`) | **5 / 6 (`0.47 ms`)** |
68
- | **6 ReDoS stress bombs (3k–5k chars)** | `8,298.90 ms` | **`2.51 ms`** |
69
- | **Full 79-case isolated throughput & RSS** | `134.0 /s` (`+64.79 MB`) | **`38,938.5 /s` (`+10.21 MB`)** *(290.6x)* |
70
-
71
- **Transparently noted misses & differences (`5 / 79` on `dateoxide`):**
72
- - `"the day after tomorrow"` returns `None` (`"day after tomorrow"` works; leading `"the"` isn't stripped yet; `dateparser` parses it).
73
- - `"quarter past 3"` and `"two and a half hours ago"` return `None` in **both** `dateoxide` and `dateparser`.
74
- - `"last Friday"` preserves `RELATIVE_BASE` time (`15:00`) in `dateoxide`, whereas `dateparser` resets time to `00:00`.
75
- - `"2026-13-01"` swaps to `2026-01-13` under default `STRICT_DATE_ORDER="none"` in **both** libraries (set `STRICT_DATE_ORDER="all"` to reject).
66
+ | **Torture accuracy (79 hard cases)** | 66 / 79 (`4,243.30 ms`) | **78 / 79 (`1.60 ms`)** |
67
+ | **Dirty `search_dates` (6 docs)** | 4 / 6 (`1,885.91 ms`) | **6 / 6 (`0.48 ms`)** |
68
+ | **6 ReDoS stress bombs (3k–5k chars)** | `20,111.62 ms` | **`5.46 ms`** |
69
+ | **Full 79-case isolated throughput & RSS** | `57.4 /s` (`+64.52 MB`) | **`20,629.9 /s` (`+10.24 MB`)** *(359.4x)* |
70
+
71
+ **Transparently noted difference (`1 / 79`):**
72
+ - `"2026-13-01"` swaps to `2026-01-13` under default `STRICT_DATE_ORDER="none"` in **both** `dateoxide` and `dateparser` (set `STRICT_DATE_ORDER="all"` to reject invalid month indices strictly).
76
73
 
77
74
  ---
78
75
 
@@ -0,0 +1,51 @@
1
+ use criterion::{black_box, criterion_group, criterion_main, Criterion};
2
+ use dateoxide_core::{parse_batch, parse_with_settings, search::search_dates, settings::Settings};
3
+
4
+ fn bench_dateoxide_core(c: &mut Criterion) {
5
+ let settings = Settings::default();
6
+ let dashes = "-".repeat(5000);
7
+ let batch_inputs: Vec<&str> = [
8
+ "2026-11-26T15:30:00Z",
9
+ "12 December 2025",
10
+ "3 gün önce",
11
+ "vor 2 Wochen",
12
+ "2026-W48-4",
13
+ "not a date",
14
+ ]
15
+ .into_iter()
16
+ .cycle()
17
+ .take(1000)
18
+ .collect();
19
+
20
+ c.bench_function("parse_iso_fast_path", |b| {
21
+ b.iter(|| parse_with_settings(black_box("2026-11-26T15:30:00Z"), &settings))
22
+ });
23
+
24
+ c.bench_function("parse_multilingual_relative", |b| {
25
+ b.iter(|| parse_with_settings(black_box("3 gün önce"), &settings))
26
+ });
27
+
28
+ c.bench_function("parse_multilingual_absolute", |b| {
29
+ b.iter(|| parse_with_settings(black_box("12 December 2025"), &settings))
30
+ });
31
+
32
+ c.bench_function("search_dates_mixed_sentence", |b| {
33
+ b.iter(|| {
34
+ search_dates(
35
+ black_box("Berlin: 12. Dezember 2025, Paris: hier à 14h30"),
36
+ &settings,
37
+ )
38
+ })
39
+ });
40
+
41
+ c.bench_function("redos_dashes_5000", |b| {
42
+ b.iter(|| parse_with_settings(black_box(&dashes), &settings))
43
+ });
44
+
45
+ c.bench_function("parse_batch_1000", |b| {
46
+ b.iter(|| parse_batch(black_box(&batch_inputs), &settings))
47
+ });
48
+ }
49
+
50
+ criterion_group!(benches, bench_dateoxide_core);
51
+ criterion_main!(benches);
@@ -180,7 +180,7 @@ fn try_compact_iso_datetime(core: &str, tz: Option<TzSpec>) -> Option<FastPathMa
180
180
  })
181
181
  }
182
182
 
183
- fn resolve_time_only_date(time: NaiveTime, settings: &Settings) -> NaiveDate {
183
+ pub(crate) fn resolve_time_only_date(time: NaiveTime, settings: &Settings) -> NaiveDate {
184
184
  let base = settings.effective_base();
185
185
  let mut date = base.date();
186
186
  match settings.prefer_dates_from {
@@ -38,6 +38,7 @@
38
38
  //! ```
39
39
 
40
40
  pub mod absolute;
41
+ #[cfg(feature = "calendars")]
41
42
  pub mod calendars;
42
43
  pub mod fast_path;
43
44
  pub mod locale;
@@ -46,9 +47,11 @@ pub mod search;
46
47
  pub mod settings;
47
48
  pub mod time_spans;
48
49
  pub mod timezone;
50
+ #[cfg(feature = "calendars")]
49
51
  pub mod umm_al_qura;
50
52
 
51
53
  use locale::{normalize_digits_and_lower, LocaleRegistry};
54
+ #[cfg(feature = "rayon")]
52
55
  use rayon::prelude::*;
53
56
  use search::SearchMatch;
54
57
  use settings::{DateData, ParsedDateTime, ParserKind, Period, Settings};
@@ -114,6 +117,7 @@ pub fn parse_freshness(input: &str, settings: &Settings) -> DateData {
114
117
  settings.languages.as_deref(),
115
118
  &settings.default_languages,
116
119
  settings.normalize,
120
+ settings.use_given_language_order,
117
121
  );
118
122
  if let Some(m) = relative::try_parse_relative(&normalized, &candidates, registry, settings) {
119
123
  return DateData {
@@ -233,9 +237,21 @@ pub fn get_date_data(input: &str, settings: &Settings) -> DateData {
233
237
  settings.languages.as_deref(),
234
238
  &settings.default_languages,
235
239
  settings.normalize,
240
+ settings.use_given_language_order,
236
241
  );
237
242
 
238
243
  if candidates.is_empty() {
244
+ if settings.allows_parser(ParserKind::RelativeTime) {
245
+ if let Some(m) = relative::try_conversational_clock_or_fraction(&normalized, settings) {
246
+ return DateData {
247
+ date_obj: Some(finalize_datetime(m.naive, tz, settings)),
248
+ period: apply_time_period(m.period, m.has_time, settings),
249
+ locale: Some(m.locale),
250
+ parts: m.parts,
251
+ part_of_day: m.part_of_day,
252
+ };
253
+ }
254
+ }
239
255
  let is_cjk_or_bare_year = (normalized.len() == 4
240
256
  && normalized.bytes().all(|b| b.is_ascii_digit()))
241
257
  || normalized.contains('年')
@@ -306,21 +322,32 @@ fn ignore_surrounding_fallback(trimmed: &str, settings: &Settings) -> DateData {
306
322
  DateData::empty()
307
323
  }
308
324
 
309
- /// Parallel batch parsing powered by Rayon across all available CPU cores.
325
+ /// Parallel batch parsing powered by Rayon across all available CPU cores
326
+ /// (falls back to sequential iteration when the `rayon` feature is disabled).
310
327
  pub fn parse_batch<S: AsRef<str> + Sync>(
311
328
  inputs: &[S],
312
329
  settings: &Settings,
313
330
  ) -> Vec<Option<ParsedDateTime>> {
314
- if inputs.len() < 256 {
331
+ #[cfg(feature = "rayon")]
332
+ {
333
+ if inputs.len() < 256 {
334
+ return inputs
335
+ .iter()
336
+ .map(|s| parse_with_settings(s.as_ref(), settings))
337
+ .collect();
338
+ }
315
339
  return inputs
316
- .iter()
340
+ .par_iter()
317
341
  .map(|s| parse_with_settings(s.as_ref(), settings))
318
342
  .collect();
319
343
  }
320
- inputs
321
- .par_iter()
322
- .map(|s| parse_with_settings(s.as_ref(), settings))
323
- .collect()
344
+ #[cfg(not(feature = "rayon"))]
345
+ {
346
+ inputs
347
+ .iter()
348
+ .map(|s| parse_with_settings(s.as_ref(), settings))
349
+ .collect()
350
+ }
324
351
  }
325
352
 
326
353
  /// Find and parse all date expressions embedded in free-form text.
@@ -377,6 +404,7 @@ mod tests {
377
404
  );
378
405
  }
379
406
 
407
+ #[cfg(feature = "calendars")]
380
408
  #[test]
381
409
  fn test_calendars_conversions() {
382
410
  let s = fixed_settings();
@@ -405,6 +405,7 @@ impl LocaleRegistry {
405
405
  explicit_langs: Option<&[String]>,
406
406
  default_langs: &[String],
407
407
  normalize: bool,
408
+ use_given_order: bool,
408
409
  ) -> Vec<usize> {
409
410
  if let Some(langs) = explicit_langs {
410
411
  if !langs.is_empty() {
@@ -420,12 +421,32 @@ impl LocaleRegistry {
420
421
  }
421
422
  }
422
423
 
424
+ let order_with_defaults = |mut ids: Vec<usize>| -> Vec<usize> {
425
+ if use_given_order && !default_langs.is_empty() {
426
+ let mut ordered = Vec::with_capacity(ids.len());
427
+ for code in default_langs {
428
+ if let Some(did) = self.resolve_lang_id(code) {
429
+ if ids.contains(&did) && !ordered.contains(&did) {
430
+ ordered.push(did);
431
+ }
432
+ }
433
+ }
434
+ for id in ids {
435
+ if !ordered.contains(&id) {
436
+ ordered.push(id);
437
+ }
438
+ }
439
+ ids = ordered;
440
+ }
441
+ ids
442
+ };
443
+
423
444
  // Fast exact relative phrase lookup
424
445
  if let Some(matches) = self.exact_phrase_index.get(normalized) {
425
446
  let mut out: Vec<usize> = matches.iter().map(|(id, _)| *id as usize).collect();
426
447
  out.sort_unstable();
427
448
  out.dedup();
428
- return out;
449
+ return order_with_defaults(out);
429
450
  }
430
451
 
431
452
  if normalize {
@@ -434,7 +455,7 @@ impl LocaleRegistry {
434
455
  let mut out: Vec<usize> = matches.iter().map(|(id, _)| *id as usize).collect();
435
456
  out.sort_unstable();
436
457
  out.dedup();
437
- return out;
458
+ return order_with_defaults(out);
438
459
  }
439
460
  }
440
461
 
@@ -521,7 +542,8 @@ impl LocaleRegistry {
521
542
  // Highest score first; ties broken by global language priority (lower id = higher priority)
522
543
  ranked.sort_unstable_by(|a, b| b.1.cmp(&a.1).then_with(|| a.0.cmp(&b.0)));
523
544
 
524
- ranked.into_iter().take(8).map(|(id, _)| id as usize).collect()
545
+ let top: Vec<usize> = ranked.into_iter().take(8).map(|(id, _)| id as usize).collect();
546
+ order_with_defaults(top)
525
547
  }
526
548
  }
527
549