mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-30 21:47:00 -06:00
Merge pull request #1324
Long English dates follow each English locale's day order and punctuation
This commit is contained in:
@@ -449,6 +449,17 @@ mod tests {
|
||||
assert_eq!(undo(&s), before + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_long_british_date_puts_the_day_first() {
|
||||
let mut s = session();
|
||||
edit_title(&mut s);
|
||||
let v = s.execute("insert.dateTime", &json!({"format": "datetime4", "update": false, "language": "en-GB"})).unwrap();
|
||||
let text = v["text"].as_str().unwrap().to_string();
|
||||
assert!(text.chars().next().is_some_and(|c| c.is_ascii_digit()) && !text.contains(','), "{text}");
|
||||
let v = s.execute("insert.dateTime", &json!({"format": "datetime4", "update": false, "language": "en-US"})).unwrap();
|
||||
assert!(v["text"].as_str().is_some_and(|t| t.contains(',')), "{v}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_named_format_in_french_and_a_bad_value_change_nothing() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -104,11 +104,20 @@ pub fn field_text(kind: &str, lang: Option<&str>, now: DateTime) -> Option<Strin
|
||||
let ampm = if now.hour < 12 { "AM" } else { "PM" };
|
||||
let (mi, s) = (now.minute, now.second);
|
||||
let short = short_date(&lang, now);
|
||||
// British-style English writes the day before the month ("9 October 2026"). The punctuation
|
||||
// follows PowerPoint on Windows per locale: Irish English has no comma after the weekday,
|
||||
// British and Australian English put one after the month in `datetime3`, and South African
|
||||
// English writes the weekday form day first too.
|
||||
let day_first = matches!(lang.as_str(), "en-gb" | "en-au" | "en-nz" | "en-ie" | "en-in");
|
||||
let named = |text: String| english.then_some(text);
|
||||
match kind {
|
||||
"datetime" | "datetimeFigureOut" | "datetime1" => Some(short),
|
||||
"datetime2" if lang == "en-ie" => named(format!("{day} {d} {month} {y}")),
|
||||
"datetime2" if day_first || lang == "en-za" => named(format!("{day}, {d} {month} {y}")),
|
||||
"datetime2" => named(format!("{day}, {month} {d}, {y}")),
|
||||
"datetime3" if matches!(lang.as_str(), "en-gb" | "en-au") => named(format!("{d} {month}, {y}")),
|
||||
"datetime3" => named(format!("{d} {month} {y}")),
|
||||
"datetime4" if day_first => named(format!("{d} {month} {y}")),
|
||||
"datetime4" => named(format!("{month} {d}, {y}")),
|
||||
"datetime5" => named(format!("{d}-{mon}-{yy:02}")),
|
||||
"datetime6" => named(format!("{month} {yy:02}")),
|
||||
@@ -183,7 +192,32 @@ mod tests {
|
||||
// Month names in another language: not computed (the field keeps its saved text).
|
||||
assert_eq!(field_text("datetime2", Some("de-DE"), FRI), None);
|
||||
assert_eq!(field_text("datetime12", Some("fr-FR"), FRI), None);
|
||||
assert_eq!(field_text("datetime4", Some("en-GB"), FRI).as_deref(), Some("October 9, 2026"));
|
||||
assert_eq!(field_text("datetime4", Some("en-GB"), FRI).as_deref(), Some("9 October 2026"));
|
||||
assert_eq!(field_text("datetime2", Some("en-GB"), FRI).as_deref(), Some("Friday, 9 October 2026"));
|
||||
assert_eq!(field_text("datetime4", Some("en-AU"), FRI).as_deref(), Some("9 October 2026"));
|
||||
assert_eq!(field_text("datetime4", Some("en-US"), FRI).as_deref(), Some("October 9, 2026"));
|
||||
}
|
||||
|
||||
/// The long English dates as PowerPoint on Windows shows them on Tuesday 27 October 2026, read
|
||||
/// per run language (datetime2, datetime3, datetime4).
|
||||
#[test]
|
||||
fn long_english_dates_follow_each_locale() {
|
||||
let tue = DateTime::new(2026, 10, 27, 9, 0, 0);
|
||||
let rows = [
|
||||
("en-US", "Tuesday, October 27, 2026", "27 October 2026", "October 27, 2026"),
|
||||
("en-GB", "Tuesday, 27 October 2026", "27 October, 2026", "27 October 2026"),
|
||||
("en-AU", "Tuesday, 27 October 2026", "27 October, 2026", "27 October 2026"),
|
||||
("en-NZ", "Tuesday, 27 October 2026", "27 October 2026", "27 October 2026"),
|
||||
("en-IE", "Tuesday 27 October 2026", "27 October 2026", "27 October 2026"),
|
||||
("en-IN", "Tuesday, 27 October 2026", "27 October 2026", "27 October 2026"),
|
||||
("en-CA", "Tuesday, October 27, 2026", "27 October 2026", "October 27, 2026"),
|
||||
];
|
||||
for (lang, d2, d3, d4) in rows {
|
||||
assert_eq!(field_text("datetime2", Some(lang), tue).as_deref(), Some(d2), "{lang}");
|
||||
assert_eq!(field_text("datetime3", Some(lang), tue).as_deref(), Some(d3), "{lang}");
|
||||
assert_eq!(field_text("datetime4", Some(lang), tue).as_deref(), Some(d4), "{lang}");
|
||||
}
|
||||
assert_eq!(field_text("datetime2", Some("en-ZA"), tue).as_deref(), Some("Tuesday, 27 October 2026"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user