mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-04 22:49:54 +00:00
Merge pull request #8873
This commit is contained in:
@@ -16,8 +16,8 @@ mod objects;
|
||||
pub(crate) use header_footer::saved_copy;
|
||||
use header_footer::{create_hf, edit_hf, header_footer, new_empty_headers, strip_headers};
|
||||
pub use items::{
|
||||
DropCapState, default_date_picture, drop_cap_state, format_date, format_date_at, format_date_at_in, format_date_in, format_date_parts,
|
||||
format_date_parts_in,
|
||||
DropCapState, default_date_picture, default_time_picture, drop_cap_state, format_date, format_date_at, format_date_at_in, format_date_in,
|
||||
format_date_parts, format_date_parts_in,
|
||||
};
|
||||
use items::{cover_page, date_time, drop_cap, drop_cap_off, field, page_number, symbol};
|
||||
use links::{bookmark, delete_bookmark, link, link_targets};
|
||||
|
||||
@@ -218,6 +218,8 @@ struct DateNames {
|
||||
days_short: [&'static str; 7],
|
||||
/// The picture of a `DATE` field without `\@`.
|
||||
default: &'static str,
|
||||
/// The picture of a `TIME` field without `\@`.
|
||||
default_time: &'static str,
|
||||
}
|
||||
|
||||
const ENGLISH: DateNames = DateNames {
|
||||
@@ -226,6 +228,7 @@ const ENGLISH: DateNames = DateNames {
|
||||
days: ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"],
|
||||
days_short: ["Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"],
|
||||
default: "M/d/yyyy",
|
||||
default_time: "h:mm am/pm",
|
||||
};
|
||||
|
||||
/// Portuguese (observed in Word for Mac with a pt-BR document): lower-case names, `MMM` = `out`,
|
||||
@@ -236,6 +239,7 @@ const PORTUGUESE: DateNames = DateNames {
|
||||
days: ["quinta-feira", "sexta-feira", "sábado", "domingo", "segunda-feira", "terça-feira", "quarta-feira"],
|
||||
days_short: ["qui", "sex", "sáb", "dom", "seg", "ter", "qua"],
|
||||
default: "dd/MM/yyyy",
|
||||
default_time: "h:mm am/pm",
|
||||
};
|
||||
|
||||
/// German (Word's Windows NLS forms): `MMMM` = `März`, `MMM` = `Mrz`, `ddd` = `Fr` (two
|
||||
@@ -246,6 +250,7 @@ const GERMAN: DateNames = DateNames {
|
||||
days: ["Donnerstag", "Freitag", "Samstag", "Sonntag", "Montag", "Dienstag", "Mittwoch"],
|
||||
days_short: ["Do", "Fr", "Sa", "So", "Mo", "Di", "Mi"],
|
||||
default: "dd.MM.yyyy",
|
||||
default_time: "HH:mm",
|
||||
};
|
||||
|
||||
/// Austrian Standard German: January is `Jänner`, abbreviated `Jän` (Österreichisches
|
||||
@@ -256,6 +261,7 @@ const GERMAN_AUSTRIA: DateNames = DateNames {
|
||||
days: ["Donnerstag", "Freitag", "Samstag", "Sonntag", "Montag", "Dienstag", "Mittwoch"],
|
||||
days_short: ["Do", "Fr", "Sa", "So", "Mo", "Di", "Mi"],
|
||||
default: "dd.MM.yyyy",
|
||||
default_time: "HH:mm",
|
||||
};
|
||||
|
||||
/// Choose month and weekday names from the language tag: the primary subtag picks the language,
|
||||
@@ -279,6 +285,12 @@ pub fn default_date_picture(lang: Option<&str>) -> &'static str {
|
||||
date_names(lang).default
|
||||
}
|
||||
|
||||
/// The picture Word gives a `TIME` field that has no `\@` switch, in the field's language: German
|
||||
/// shows the 24-hour clock (#8562).
|
||||
pub fn default_time_picture(lang: Option<&str>) -> &'static str {
|
||||
date_names(lang).default_time
|
||||
}
|
||||
|
||||
/// Format a date and time with a Word picture; `days_since` (days since 1970-01-01) gives the weekday.
|
||||
pub fn format_date_parts(fmt: &str, y: i64, m: usize, d: u32, hms: (u32, u32, u32), days_since: i64) -> String {
|
||||
format_date_parts_in(fmt, None, y, m, d, hms, days_since)
|
||||
@@ -622,6 +634,28 @@ mod date_time_locale_tests {
|
||||
assert_eq!(default_date_picture(Some("de-CH")), "dd.MM.yyyy");
|
||||
}
|
||||
|
||||
/// A `TIME` field without `\@` shows the 24-hour clock in a German document and the 12-hour
|
||||
/// clock in an English one (#8562).
|
||||
#[test]
|
||||
fn bare_time_field_follows_the_document_language() {
|
||||
let refreshed = |lang: &str| {
|
||||
let mut s = Session::new(wordcraft_doc::Document::new());
|
||||
s.run("review.language", &json!({"lang": lang, "default": true})).unwrap();
|
||||
s.run("insert.field", &json!({"instr": "TIME", "result": "stale"})).unwrap();
|
||||
crate::cmd::references::refresh_date_fields(&mut s.doc);
|
||||
let path = s.doc.para_paths(StoryRef::Body).remove(0);
|
||||
let p = s.doc.para(StoryRef::Body, &path).unwrap();
|
||||
let result = p.objects.iter().find_map(|o| if let InlineObject::Field { result, .. } = o { Some(result.clone()) } else { None });
|
||||
result.expect("a TIME field")
|
||||
};
|
||||
for lang in ["de-DE", "de-AT", "de-CH"] {
|
||||
let time = refreshed(lang);
|
||||
assert!(time != "stale" && !time.contains("AM") && !time.contains("PM"), "{lang}: {time}");
|
||||
}
|
||||
let time = refreshed("en-US");
|
||||
assert!(time.contains("AM") || time.contains("PM"), "en-US: {time}");
|
||||
}
|
||||
|
||||
/// Windows NLS short forms: two-letter weekdays (`Mo`, `Di`…) and `Mrz` for March, with no
|
||||
/// trailing full stop (#7146).
|
||||
#[test]
|
||||
|
||||
@@ -607,7 +607,7 @@ fn created_at(stamp: &str) -> Option<(u64, i64)> {
|
||||
|
||||
/// Word's default date or time picture when a field instruction carries no `\@` picture switch.
|
||||
fn default_picture(name: &str, lang: Option<&str>) -> String {
|
||||
if name == "TIME" { "h:mm am/pm".into() } else { crate::cmd::insert::default_date_picture(lang).into() }
|
||||
if name == "TIME" { crate::cmd::insert::default_time_picture(lang).into() } else { crate::cmd::insert::default_date_picture(lang).into() }
|
||||
}
|
||||
/// Most names SET fields give values.
|
||||
const MAX_SET: usize = 10_000;
|
||||
|
||||
Reference in New Issue
Block a user