Merge pull request #58: feat(settings): regional format for dates, times and week start
@@ -313,6 +313,8 @@ dependencies = [
313
313
"calling",
314
314
"chatsvc",
315
315
"chrono",
316
"core-foundation 0.10.1",
317
"core-foundation-sys 0.8.7",
316
318
"directories",
317
319
"futures-channel",
318
320
"futures-util",
@@ -313,6 +313,8 @@ dependencies = [313
"calling",313
"calling",314
"chatsvc",314
"chatsvc",315
"chrono",315
"chrono",316
"core-foundation 0.10.1",317
"core-foundation-sys 0.8.7",316
"directories",318
"directories",317
"futures-channel",319
"futures-channel",318
"futures-util",320
"futures-util",@@ -36,6 +36,10 @@ resvg = { version = "0.46", default-features = false, features = ["text"] }
36
36
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
37
37
rodio = { version = "0.22", default-features = false, features = ["playback", "mp3"] }
38
38
39
[target.'cfg(target_os = "macos")'.dependencies]
40
core-foundation = "0.10"
41
core-foundation-sys = "0.8"
42
39
43
[target.'cfg(target_os = "linux")'.dependencies]
40
44
x11rb = { version = "0.13", features = ["shape"] }
41
45
ksni = { version = "0.3", features = ["blocking"] }
@@ -48,6 +52,7 @@ tray-icon = { version = "0.21", default-features = false }
48
52
windows = { version = "0.62", features = [
49
53
"Win32_Foundation",
50
54
"Win32_Graphics_Dwm",
55
"Win32_Globalization",
51
56
"Win32_Graphics_Gdi",
52
57
"Win32_Security",
53
58
"Win32_System_Diagnostics_Debug",
@@ -36,6 +36,10 @@ resvg = { version = "0.46", default-features = false, features = ["text"] }36
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]36
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]37
rodio = { version = "0.22", default-features = false, features = ["playback", "mp3"] }37
rodio = { version = "0.22", default-features = false, features = ["playback", "mp3"] }38
38
39
[target.'cfg(target_os = "macos")'.dependencies]40
core-foundation = "0.10"41
core-foundation-sys = "0.8"42
39
[target.'cfg(target_os = "linux")'.dependencies]43
[target.'cfg(target_os = "linux")'.dependencies]40
x11rb = { version = "0.13", features = ["shape"] }44
x11rb = { version = "0.13", features = ["shape"] }41
ksni = { version = "0.3", features = ["blocking"] }45
ksni = { version = "0.3", features = ["blocking"] }@@ -48,6 +52,7 @@ tray-icon = { version = "0.21", default-features = false }48
windows = { version = "0.62", features = [52
windows = { version = "0.62", features = [49
"Win32_Foundation",53
"Win32_Foundation",50
"Win32_Graphics_Dwm",54
"Win32_Graphics_Dwm",55
"Win32_Globalization",51
"Win32_Graphics_Gdi",56
"Win32_Graphics_Gdi",52
"Win32_Security",57
"Win32_Security",53
"Win32_System_Diagnostics_Debug",58
"Win32_System_Diagnostics_Debug",@@ -243,6 +243,9 @@ settings:
243
243
language:
244
244
en: LANGUAGE
245
245
de: SPRACHE
246
regional_format:
247
en: REGIONAL FORMAT
248
de: REGIONALES FORMAT
246
249
theme:
247
250
en: THEME
248
251
de: DESIGN
@@ -328,15 +331,6 @@ settings:
328
331
last_used:
329
332
en: Last used
330
333
de: Zuletzt verwendet
331
first_day:
332
en: First day of week
333
de: Erster Wochentag
334
first_day_detail:
335
en: Week, work week and month start on this day
336
de: Woche, Arbeitswoche und Monat beginnen an diesem Tag
337
first_day_regional:
338
en: "As in Outlook (%{day})"
339
de: "Wie in Outlook (%{day})"
340
334
work_days:
341
335
en: Work days
342
336
de: Arbeitstage
@@ -569,6 +563,42 @@ settings:
569
563
german:
570
564
en: Deutsch
571
565
de: Deutsch
566
region:
567
title:
568
en: Region
569
de: Region
570
detail:
571
en: Date and number format, also when the app language differs
572
de: Datums- und Zahlenformat, auch bei anderer App-Sprache
573
follow_system:
574
en: "Follow system (%{region})"
575
de: "Systemeinstellung folgen (%{region})"
576
clock:
577
title:
578
en: Time format
579
de: Zeitformat
580
detail:
581
en: Times in chats, calendar and notifications
582
de: Uhrzeiten in Chats, Kalender und Benachrichtigungen
583
auto:
584
en: "Automatic (%{example})"
585
de: "Automatisch (%{example})"
586
hours_24:
587
en: "24-hour (%{example})"
588
de: "24 Stunden (%{example})"
589
hours_12:
590
en: "12-hour (%{example})"
591
de: "12 Stunden (%{example})"
592
first_day:
593
title:
594
en: First day of week
595
de: Erster Wochentag
596
detail:
597
en: Calendar weeks, months and date pickers start on this day
598
de: Wochen, Monate und Datumsauswahl im Kalender beginnen an diesem Tag
599
auto:
600
en: "Automatic (%{day})"
601
de: "Automatisch (%{day})"
572
602
chats:
573
603
density:
574
604
en: Message density
@@ -1898,3 +1928,92 @@ shortcuts:
1898
1928
calls:
1899
1929
en: Calls
1900
1930
de: Anrufe
1931
regional:
1932
today:
1933
en: Today
1934
de: Heute
1935
yesterday:
1936
en: Yesterday
1937
de: Gestern
1938
tomorrow:
1939
en: Tomorrow
1940
de: Morgen
1941
today_clock:
1942
en: "today %{clock}"
1943
de: "heute %{clock}"
1944
today_at:
1945
en: "today at %{clock}"
1946
de: "heute um %{clock}"
1947
yesterday_at:
1948
en: "yesterday at %{clock}"
1949
de: "gestern um %{clock}"
1950
date_at:
1951
en: "%{date} at %{clock}"
1952
de: "%{date} um %{clock}"
1953
until:
1954
en: "until %{time}"
1955
de: "bis %{time}"
1956
region:
1957
at:
1958
en: Austria
1959
de: Österreich
1960
au:
1961
en: Australia
1962
de: Australien
1963
br:
1964
en: Brazil
1965
de: Brasilien
1966
ca:
1967
en: Canada
1968
de: Kanada
1969
ch:
1970
en: Switzerland
1971
de: Schweiz
1972
cz:
1973
en: Czechia
1974
de: Tschechien
1975
de:
1976
en: Germany
1977
de: Deutschland
1978
dk:
1979
en: Denmark
1980
de: Dänemark
1981
es:
1982
en: Spain
1983
de: Spanien
1984
fi:
1985
en: Finland
1986
de: Finnland
1987
fr:
1988
en: France
1989
de: Frankreich
1990
gb:
1991
en: United Kingdom
1992
de: Vereinigtes Königreich
1993
ie:
1994
en: Ireland
1995
de: Irland
1996
in:
1997
en: India
1998
de: Indien
1999
it:
2000
en: Italy
2001
de: Italien
2002
jp:
2003
en: Japan
2004
de: Japan
2005
nl:
2006
en: Netherlands
2007
de: Niederlande
2008
no:
2009
en: Norway
2010
de: Norwegen
2011
pl:
2012
en: Poland
2013
de: Polen
2014
se:
2015
en: Sweden
2016
de: Schweden
2017
us:
2018
en: United States
2019
de: Vereinigte Staaten
@@ -243,6 +243,9 @@ settings:243
language:243
language:244
en: LANGUAGE244
en: LANGUAGE245
de: SPRACHE245
de: SPRACHE246
regional_format:247
en: REGIONAL FORMAT248
de: REGIONALES FORMAT246
theme:249
theme:247
en: THEME250
en: THEME248
de: DESIGN251
de: DESIGN@@ -328,15 +331,6 @@ settings:328
last_used:331
last_used:329
en: Last used332
en: Last used330
de: Zuletzt verwendet333
de: Zuletzt verwendet331
first_day:332
en: First day of week333
de: Erster Wochentag334
first_day_detail:335
en: Week, work week and month start on this day336
de: Woche, Arbeitswoche und Monat beginnen an diesem Tag337
first_day_regional:338
en: "As in Outlook (%{day})"339
de: "Wie in Outlook (%{day})"340
work_days:334
work_days:341
en: Work days335
en: Work days342
de: Arbeitstage336
de: Arbeitstage@@ -569,6 +563,42 @@ settings:569
german:563
german:570
en: Deutsch564
en: Deutsch571
de: Deutsch565
de: Deutsch566
region:567
title:568
en: Region569
de: Region570
detail:571
en: Date and number format, also when the app language differs572
de: Datums- und Zahlenformat, auch bei anderer App-Sprache573
follow_system:574
en: "Follow system (%{region})"575
de: "Systemeinstellung folgen (%{region})"576
clock:577
title:578
en: Time format579
de: Zeitformat580
detail:581
en: Times in chats, calendar and notifications582
de: Uhrzeiten in Chats, Kalender und Benachrichtigungen583
auto:584
en: "Automatic (%{example})"585
de: "Automatisch (%{example})"586
hours_24:587
en: "24-hour (%{example})"588
de: "24 Stunden (%{example})"589
hours_12:590
en: "12-hour (%{example})"591
de: "12 Stunden (%{example})"592
first_day:593
title:594
en: First day of week595
de: Erster Wochentag596
detail:597
en: Calendar weeks, months and date pickers start on this day598
de: Wochen, Monate und Datumsauswahl im Kalender beginnen an diesem Tag599
auto:600
en: "Automatic (%{day})"601
de: "Automatisch (%{day})"572
chats:602
chats:573
density:603
density:574
en: Message density604
en: Message density@@ -1898,3 +1928,92 @@ shortcuts:1898
calls:1928
calls:1899
en: Calls1929
en: Calls1900
de: Anrufe1930
de: Anrufe1931
regional:1932
today:1933
en: Today1934
de: Heute1935
yesterday:1936
en: Yesterday1937
de: Gestern1938
tomorrow:1939
en: Tomorrow1940
de: Morgen1941
today_clock:1942
en: "today %{clock}"1943
de: "heute %{clock}"1944
today_at:1945
en: "today at %{clock}"1946
de: "heute um %{clock}"1947
yesterday_at:1948
en: "yesterday at %{clock}"1949
de: "gestern um %{clock}"1950
date_at:1951
en: "%{date} at %{clock}"1952
de: "%{date} um %{clock}"1953
until:1954
en: "until %{time}"1955
de: "bis %{time}"1956
region:1957
at:1958
en: Austria1959
de: Österreich1960
au:1961
en: Australia1962
de: Australien1963
br:1964
en: Brazil1965
de: Brasilien1966
ca:1967
en: Canada1968
de: Kanada1969
ch:1970
en: Switzerland1971
de: Schweiz1972
cz:1973
en: Czechia1974
de: Tschechien1975
de:1976
en: Germany1977
de: Deutschland1978
dk:1979
en: Denmark1980
de: Dänemark1981
es:1982
en: Spain1983
de: Spanien1984
fi:1985
en: Finland1986
de: Finnland1987
fr:1988
en: France1989
de: Frankreich1990
gb:1991
en: United Kingdom1992
de: Vereinigtes Königreich1993
ie:1994
en: Ireland1995
de: Irland1996
in:1997
en: India1998
de: Indien1999
it:2000
en: Italy2001
de: Italien2002
jp:2003
en: Japan2004
de: Japan2005
nl:2006
en: Netherlands2007
de: Niederlande2008
no:2009
en: Norway2010
de: Norwegen2011
pl:2012
en: Poland2013
de: Polen2014
se:2015
en: Sweden2016
de: Schweden2017
us:2018
en: United States2019
de: Vereinigte Staaten@@ -38,6 +38,14 @@ const SUNDAY_FIRST_LOCALES: [&str; 13] = [
38
38
];
39
39
/// Arabic regions that start on Monday instead of Saturday.
40
40
const ARABIC_MONDAY_LOCALES: [&str; 2] = ["ar-ma", "ar-tn"];
41
/// Languages that write a decimal comma (CLDR), except the locales below.
42
const DECIMAL_COMMA_LANGUAGES: [&str; 17] = [
43
"de", "fr", "it", "es", "pt", "nl", "sv", "da", "nb", "no", "fi", "pl", "cs", "sk", "ru", "tr",
44
"uk",
45
];
46
const DECIMAL_POINT_LOCALES: [&str; 4] = ["de-ch", "de-li", "it-ch", "es-mx"];
47
const TWELVE_HOUR_CLOCK: &str = "%-I:%M %p";
48
const TWENTY_FOUR_HOUR_CLOCK: &str = "%H:%M";
41
49
42
50
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43
51
pub struct DateStyle {
@@ -45,30 +53,20 @@ pub struct DateStyle {
45
53
day_month_year: &'static str,
46
54
clock: &'static str,
47
55
first_day: Weekday,
56
decimal: char,
48
57
}
49
58
50
59
thread_local! {
51
60
static DATE_STYLE: Cell<Option<DateStyle>> = const { Cell::new(None) };
52
61
}
53
62
54
pub fn set_date_locale(locale: Option<&str>) {
55
DATE_STYLE.with(|style| style.set(locale.map(date_style)));
56
}
57
58
/// Teams desktop formats dates and times with the OS regional format, not the account language.
59
pub fn os_regional_locale() -> Option<String> {
60
sys_locale::get_locale()
61
.as_deref()
62
.and_then(normalize_locale)
63
/// The regional format every label below uses; [`crate::regional::resolve`] builds it.
64
pub fn set_date_style(style: Option<DateStyle>) {
65
DATE_STYLE.with(|current| current.set(style));
63
66
}
64
67
65
fn normalize_locale(raw: &str) -> Option<String> {
66
let tag = raw
67
.split(['.', '@'])
68
.next()
69
.unwrap_or_default()
70
.replace('_', "-");
71
(!tag.is_empty() && tag != "C" && tag != "POSIX").then_some(tag)
68
pub fn set_date_locale(locale: Option<&str>) {
69
set_date_style(locale.map(date_style));
72
70
}
73
71
74
72
fn current_date_style() -> Option<DateStyle> {
@@ -98,10 +96,37 @@ fn first_day_for(locale: &str, language: &str) -> Weekday {
98
96
}
99
97
100
98
pub fn clock_format() -> &'static str {
101
current_date_style().map_or("%H:%M", |style| style.clock)
99
current_date_style().map_or(TWENTY_FOUR_HOUR_CLOCK, |style| style.clock)
102
100
}
103
101
104
102
impl DateStyle {
103
/// The same patterns with a forced clock; a 12-hour region keeps its own am/pm spelling.
104
pub fn with_twelve_hour(self, twelve_hour: bool) -> DateStyle {
105
let clock = match (twelve_hour, self.twelve_hour()) {
106
(true, true) | (false, false) => self.clock,
107
(true, false) => TWELVE_HOUR_CLOCK,
108
(false, true) => TWENTY_FOUR_HOUR_CLOCK,
109
};
110
DateStyle { clock, ..self }
111
}
112
113
pub fn with_first_day(self, first_day: Weekday) -> DateStyle {
114
DateStyle { first_day, ..self }
115
}
116
117
pub fn twelve_hour(&self) -> bool {
118
self.clock.contains("%p") || self.clock.contains("%P")
119
}
120
121
pub fn first_day(&self) -> Weekday {
122
self.first_day
123
}
124
125
/// chrono pattern of the clock, such as `%H:%M`.
126
pub fn clock(&self) -> &'static str {
127
self.clock
128
}
129
105
130
fn month_first(&self) -> bool {
106
131
self.day_month.starts_with("%-m")
107
132
}
@@ -221,11 +246,58 @@ pub fn date_style(locale: &str) -> DateStyle {
221
246
language if PADDED_DOT_LOCALES.contains(&language) => ("%d.%m", "%d.%m.%Y"),
222
247
_ => ("%d/%m", "%d/%m/%Y"),
223
248
};
249
let decimal_comma = DECIMAL_COMMA_LANGUAGES.contains(&language)
250
&& !DECIMAL_POINT_LOCALES.contains(&locale.as_str());
224
251
DateStyle {
225
252
day_month,
226
253
day_month_year,
227
254
clock,
228
255
first_day: first_day_for(&locale, language),
256
decimal: if decimal_comma { ',' } else { '.' },
257
}
258
}
259
260
/// "16.11." / "11/16": numeric day and month of the regional format.
261
pub fn day_month_label(date: NaiveDate) -> String {
262
date.format(current_date_style().map_or("%b %-d", |style| style.day_month))
263
.to_string()
264
}
265
266
/// "16.11.2026" / "11/16/2026": numeric date of the regional format.
267
pub fn date_label(date: NaiveDate) -> String {
268
date.format(current_date_style().map_or("%b %-d, %Y", |style| style.day_month_year))
269
.to_string()
270
}
271
272
/// "Mon, 16.11." / "Mon, 11/16": short weekday in the app language, date in the regional format.
273
pub fn weekday_date_label(date: NaiveDate) -> String {
274
format!(
275
"{}, {}",
276
weekday_name(date.weekday(), WeekdayWidth::Short),
277
day_month_label(date)
278
)
279
}
280
281
/// "16. November 2026" / "November 16, 2026" / "16 November 2026".
282
pub fn long_date_label(date: NaiveDate) -> String {
283
let style = current_date_style();
284
let month = month_name(date);
285
let day = date.day();
286
if style.is_none_or(|style| style.month_first()) {
287
format!("{month} {day}, {}", date.year())
288
} else if style.is_some_and(|style| style.day_month.ends_with('.')) {
289
format!("{day}. {month} {}", date.year())
290
} else {
291
format!("{day} {month} {}", date.year())
292
}
293
}
294
295
/// A number with `decimals` places and the regional decimal separator: "1,5" in Austria.
296
pub fn decimal_label(value: f64, decimals: usize) -> String {
297
let text = format!("{value:.decimals$}");
298
match current_date_style().map_or('.', |style| style.decimal) {
299
'.' => text,
300
separator => text.replace('.', &separator.to_string()),
229
301
}
230
302
}
231
303
@@ -276,18 +348,6 @@ pub fn badge_text(count: u32) -> String {
276
348
}
277
349
}
278
350
279
fn weekday_label(weekday: Weekday) -> &'static str {
280
match weekday {
281
Weekday::Mon => "Mon",
282
Weekday::Tue => "Tue",
283
Weekday::Wed => "Wed",
284
Weekday::Thu => "Thu",
285
Weekday::Fri => "Fri",
286
Weekday::Sat => "Sat",
287
Weekday::Sun => "Sun",
288
}
289
}
290
291
351
pub fn file_size_label(bytes: u64) -> String {
292
352
const KIB: f64 = 1024.;
293
353
let value = bytes as f64;
@@ -296,7 +356,7 @@ pub fn file_size_label(bytes: u64) -> String {
296
356
} else if value < KIB * KIB {
297
357
format!("{:.0} KB", value / KIB)
298
358
} else {
299
format!("{:.1} MB", value / (KIB * KIB))
359
format!("{} MB", decimal_label(value / (KIB * KIB), 1))
300
360
}
301
361
}
302
362
@@ -323,7 +383,7 @@ pub fn list_time_label_in(
323
383
.format(style.map_or("%H:%M", |style| style.clock))
324
384
.to_string()
325
385
} else if days_ago <= WEEKDAY_WINDOW_DAYS {
326
weekday_label(local.weekday()).to_owned()
386
weekday_name(local.weekday(), WeekdayWidth::Short)
327
387
} else {
328
388
local
329
389
.format(style.map_or("%b %-d", |style| style.day_month))
@@ -375,9 +435,12 @@ pub fn post_time_label_in(
375
435
if days_ago <= 0 {
376
436
clock.to_string()
377
437
} else if days_ago == 1 {
378
format!("Yesterday {clock}")
438
format!("{} {clock}", crate::ui_locale::tr("regional.yesterday"))
379
439
} else if days_ago <= WEEKDAY_WINDOW_DAYS {
380
format!("{} {clock}", weekday_label(local.weekday()))
440
format!(
441
"{} {clock}",
442
weekday_name(local.weekday(), WeekdayWidth::Short)
443
)
381
444
} else if let Some(style) = style {
382
445
let date = if same_year {
383
446
style.day_month
@@ -394,14 +457,14 @@ pub fn post_time_label_in(
394
457
395
458
pub fn day_label(day: NaiveDate, today: NaiveDate) -> String {
396
459
if day == today {
397
"Today".to_owned()
460
crate::ui_locale::tr("regional.today")
398
461
} else if today.pred_opt() == Some(day) {
399
"Yesterday".to_owned()
462
crate::ui_locale::tr("regional.yesterday")
400
463
} else {
401
464
format!(
402
465
"{}, {}",
403
weekday_label(day.weekday()),
404
day.format("%b %-d, %Y")
466
weekday_name(day.weekday(), WeekdayWidth::Short),
467
long_date_label(day)
405
468
)
406
469
}
407
470
}
@@ -510,16 +573,6 @@ mod tests {
510
573
assert_eq!(team_initials(""), "?");
511
574
}
512
575
513
#[test]
514
fn os_locale_names_become_language_tags() {
515
assert_eq!(normalize_locale("en-GB").as_deref(), Some("en-GB"));
516
assert_eq!(normalize_locale("en_GB.UTF-8").as_deref(), Some("en-GB"));
517
assert_eq!(normalize_locale("de_DE@euro").as_deref(), Some("de-DE"));
518
assert_eq!(normalize_locale("C"), None);
519
assert_eq!(normalize_locale("POSIX"), None);
520
assert_eq!(normalize_locale(""), None);
521
}
522
523
576
#[test]
524
577
fn the_clock_follows_the_display_language() {
525
578
set_date_locale(Some("en-US"));
@@ -608,6 +661,7 @@ mod tests {
608
661
609
662
#[test]
610
663
fn list_time_is_clock_today_weekday_this_week_date_before() {
664
let _guard = crate::ui_locale::locale_test_lock();
611
665
assert_eq!(list_time_label(utc(7, 13), today(), zero()), "13:05");
612
666
assert_eq!(list_time_label(utc(5, 13), today(), zero()), "Mon");
613
667
assert_eq!(list_time_label(utc(6, 9), today(), zero()), "Tue");
@@ -633,6 +687,7 @@ mod tests {
633
687
634
688
#[test]
635
689
fn post_time_adds_the_day_when_not_today() {
690
let _guard = crate::ui_locale::locale_test_lock();
636
691
assert_eq!(post_time_label(utc(7, 13), today(), zero()), "13:05");
637
692
assert_eq!(
638
693
post_time_label(utc(6, 9), today(), zero()),
@@ -679,11 +734,12 @@ mod tests {
679
734
680
735
#[test]
681
736
fn day_labels() {
737
let _guard = crate::ui_locale::locale_test_lock();
682
738
assert_eq!(day_label(today(), today()), "Today");
683
739
assert_eq!(day_label(today().pred_opt().unwrap(), today()), "Yesterday");
684
740
assert_eq!(
685
741
day_label(NaiveDate::from_ymd_opt(2026, 10, 1).unwrap(), today()),
686
"Thu, Oct 1, 2026"
742
"Thu, October 1, 2026"
687
743
);
688
744
}
689
745
}
@@ -38,6 +38,14 @@ const SUNDAY_FIRST_LOCALES: [&str; 13] = [38
];38
];39
/// Arabic regions that start on Monday instead of Saturday.39
/// Arabic regions that start on Monday instead of Saturday.40
const ARABIC_MONDAY_LOCALES: [&str; 2] = ["ar-ma", "ar-tn"];40
const ARABIC_MONDAY_LOCALES: [&str; 2] = ["ar-ma", "ar-tn"];41
/// Languages that write a decimal comma (CLDR), except the locales below.42
const DECIMAL_COMMA_LANGUAGES: [&str; 17] = [43
"de", "fr", "it", "es", "pt", "nl", "sv", "da", "nb", "no", "fi", "pl", "cs", "sk", "ru", "tr",44
"uk",45
];46
const DECIMAL_POINT_LOCALES: [&str; 4] = ["de-ch", "de-li", "it-ch", "es-mx"];47
const TWELVE_HOUR_CLOCK: &str = "%-I:%M %p";48
const TWENTY_FOUR_HOUR_CLOCK: &str = "%H:%M";41
49
42
#[derive(Debug, Clone, Copy, PartialEq, Eq)]50
#[derive(Debug, Clone, Copy, PartialEq, Eq)]43
pub struct DateStyle {51
pub struct DateStyle {@@ -45,30 +53,20 @@ pub struct DateStyle {45
day_month_year: &'static str,53
day_month_year: &'static str,46
clock: &'static str,54
clock: &'static str,47
first_day: Weekday,55
first_day: Weekday,56
decimal: char,48
}57
}49
58
50
thread_local! {59
thread_local! {51
static DATE_STYLE: Cell<Option<DateStyle>> = const { Cell::new(None) };60
static DATE_STYLE: Cell<Option<DateStyle>> = const { Cell::new(None) };52
}61
}53
62
54
pub fn set_date_locale(locale: Option<&str>) {63
/// The regional format every label below uses; [`crate::regional::resolve`] builds it.55
DATE_STYLE.with(|style| style.set(locale.map(date_style)));64
pub fn set_date_style(style: Option<DateStyle>) {56
}65
DATE_STYLE.with(|current| current.set(style));57
58
/// Teams desktop formats dates and times with the OS regional format, not the account language.59
pub fn os_regional_locale() -> Option<String> {60
sys_locale::get_locale()61
.as_deref()62
.and_then(normalize_locale)63
}66
}64
67
65
fn normalize_locale(raw: &str) -> Option<String> {68
pub fn set_date_locale(locale: Option<&str>) {66
let tag = raw69
set_date_style(locale.map(date_style));67
.split(['.', '@'])68
.next()69
.unwrap_or_default()70
.replace('_', "-");71
(!tag.is_empty() && tag != "C" && tag != "POSIX").then_some(tag)72
}70
}73
71
74
fn current_date_style() -> Option<DateStyle> {72
fn current_date_style() -> Option<DateStyle> {@@ -98,10 +96,37 @@ fn first_day_for(locale: &str, language: &str) -> Weekday {98
}96
}99
97
100
pub fn clock_format() -> &'static str {98
pub fn clock_format() -> &'static str {101
current_date_style().map_or("%H:%M", |style| style.clock)99
current_date_style().map_or(TWENTY_FOUR_HOUR_CLOCK, |style| style.clock)102
}100
}103
101
104
impl DateStyle {102
impl DateStyle {103
/// The same patterns with a forced clock; a 12-hour region keeps its own am/pm spelling.104
pub fn with_twelve_hour(self, twelve_hour: bool) -> DateStyle {105
let clock = match (twelve_hour, self.twelve_hour()) {106
(true, true) | (false, false) => self.clock,107
(true, false) => TWELVE_HOUR_CLOCK,108
(false, true) => TWENTY_FOUR_HOUR_CLOCK,109
};110
DateStyle { clock, ..self }111
}112
113
pub fn with_first_day(self, first_day: Weekday) -> DateStyle {114
DateStyle { first_day, ..self }115
}116
117
pub fn twelve_hour(&self) -> bool {118
self.clock.contains("%p") || self.clock.contains("%P")119
}120
121
pub fn first_day(&self) -> Weekday {122
self.first_day123
}124
125
/// chrono pattern of the clock, such as `%H:%M`.126
pub fn clock(&self) -> &'static str {127
self.clock128
}129
105
fn month_first(&self) -> bool {130
fn month_first(&self) -> bool {106
self.day_month.starts_with("%-m")131
self.day_month.starts_with("%-m")107
}132
}@@ -221,11 +246,58 @@ pub fn date_style(locale: &str) -> DateStyle {221
language if PADDED_DOT_LOCALES.contains(&language) => ("%d.%m", "%d.%m.%Y"),246
language if PADDED_DOT_LOCALES.contains(&language) => ("%d.%m", "%d.%m.%Y"),222
_ => ("%d/%m", "%d/%m/%Y"),247
_ => ("%d/%m", "%d/%m/%Y"),223
};248
};249
let decimal_comma = DECIMAL_COMMA_LANGUAGES.contains(&language)250
&& !DECIMAL_POINT_LOCALES.contains(&locale.as_str());224
DateStyle {251
DateStyle {225
day_month,252
day_month,226
day_month_year,253
day_month_year,227
clock,254
clock,228
first_day: first_day_for(&locale, language),255
first_day: first_day_for(&locale, language),256
decimal: if decimal_comma { ',' } else { '.' },257
}258
}259
260
/// "16.11." / "11/16": numeric day and month of the regional format.261
pub fn day_month_label(date: NaiveDate) -> String {262
date.format(current_date_style().map_or("%b %-d", |style| style.day_month))263
.to_string()264
}265
266
/// "16.11.2026" / "11/16/2026": numeric date of the regional format.267
pub fn date_label(date: NaiveDate) -> String {268
date.format(current_date_style().map_or("%b %-d, %Y", |style| style.day_month_year))269
.to_string()270
}271
272
/// "Mon, 16.11." / "Mon, 11/16": short weekday in the app language, date in the regional format.273
pub fn weekday_date_label(date: NaiveDate) -> String {274
format!(275
"{}, {}",276
weekday_name(date.weekday(), WeekdayWidth::Short),277
day_month_label(date)278
)279
}280
281
/// "16. November 2026" / "November 16, 2026" / "16 November 2026".282
pub fn long_date_label(date: NaiveDate) -> String {283
let style = current_date_style();284
let month = month_name(date);285
let day = date.day();286
if style.is_none_or(|style| style.month_first()) {287
format!("{month} {day}, {}", date.year())288
} else if style.is_some_and(|style| style.day_month.ends_with('.')) {289
format!("{day}. {month} {}", date.year())290
} else {291
format!("{day} {month} {}", date.year())292
}293
}294
295
/// A number with `decimals` places and the regional decimal separator: "1,5" in Austria.296
pub fn decimal_label(value: f64, decimals: usize) -> String {297
let text = format!("{value:.decimals$}");298
match current_date_style().map_or('.', |style| style.decimal) {299
'.' => text,300
separator => text.replace('.', &separator.to_string()),229
}301
}230
}302
}231
303
@@ -276,18 +348,6 @@ pub fn badge_text(count: u32) -> String {276
}348
}277
}349
}278
350
279
fn weekday_label(weekday: Weekday) -> &'static str {280
match weekday {281
Weekday::Mon => "Mon",282
Weekday::Tue => "Tue",283
Weekday::Wed => "Wed",284
Weekday::Thu => "Thu",285
Weekday::Fri => "Fri",286
Weekday::Sat => "Sat",287
Weekday::Sun => "Sun",288
}289
}290
291
pub fn file_size_label(bytes: u64) -> String {351
pub fn file_size_label(bytes: u64) -> String {292
const KIB: f64 = 1024.;352
const KIB: f64 = 1024.;293
let value = bytes as f64;353
let value = bytes as f64;@@ -296,7 +356,7 @@ pub fn file_size_label(bytes: u64) -> String {296
} else if value < KIB * KIB {356
} else if value < KIB * KIB {297
format!("{:.0} KB", value / KIB)357
format!("{:.0} KB", value / KIB)298
} else {358
} else {299
format!("{:.1} MB", value / (KIB * KIB))359
format!("{} MB", decimal_label(value / (KIB * KIB), 1))300
}360
}301
}361
}302
362
@@ -323,7 +383,7 @@ pub fn list_time_label_in(323
.format(style.map_or("%H:%M", |style| style.clock))383
.format(style.map_or("%H:%M", |style| style.clock))324
.to_string()384
.to_string()325
} else if days_ago <= WEEKDAY_WINDOW_DAYS {385
} else if days_ago <= WEEKDAY_WINDOW_DAYS {326
weekday_label(local.weekday()).to_owned()386
weekday_name(local.weekday(), WeekdayWidth::Short)327
} else {387
} else {328
local388
local329
.format(style.map_or("%b %-d", |style| style.day_month))389
.format(style.map_or("%b %-d", |style| style.day_month))@@ -375,9 +435,12 @@ pub fn post_time_label_in(375
if days_ago <= 0 {435
if days_ago <= 0 {376
clock.to_string()436
clock.to_string()377
} else if days_ago == 1 {437
} else if days_ago == 1 {378
format!("Yesterday {clock}")438
format!("{} {clock}", crate::ui_locale::tr("regional.yesterday"))379
} else if days_ago <= WEEKDAY_WINDOW_DAYS {439
} else if days_ago <= WEEKDAY_WINDOW_DAYS {380
format!("{} {clock}", weekday_label(local.weekday()))440
format!(441
"{} {clock}",442
weekday_name(local.weekday(), WeekdayWidth::Short)443
)381
} else if let Some(style) = style {444
} else if let Some(style) = style {382
let date = if same_year {445
let date = if same_year {383
style.day_month446
style.day_month@@ -394,14 +457,14 @@ pub fn post_time_label_in(394
457
395
pub fn day_label(day: NaiveDate, today: NaiveDate) -> String {458
pub fn day_label(day: NaiveDate, today: NaiveDate) -> String {396
if day == today {459
if day == today {397
"Today".to_owned()460
crate::ui_locale::tr("regional.today")398
} else if today.pred_opt() == Some(day) {461
} else if today.pred_opt() == Some(day) {399
"Yesterday".to_owned()462
crate::ui_locale::tr("regional.yesterday")400
} else {463
} else {401
format!(464
format!(402
"{}, {}",465
"{}, {}",403
weekday_label(day.weekday()),466
weekday_name(day.weekday(), WeekdayWidth::Short),404
day.format("%b %-d, %Y")467
long_date_label(day)405
)468
)406
}469
}407
}470
}@@ -510,16 +573,6 @@ mod tests {510
assert_eq!(team_initials(""), "?");573
assert_eq!(team_initials(""), "?");511
}574
}512
575
513
#[test]514
fn os_locale_names_become_language_tags() {515
assert_eq!(normalize_locale("en-GB").as_deref(), Some("en-GB"));516
assert_eq!(normalize_locale("en_GB.UTF-8").as_deref(), Some("en-GB"));517
assert_eq!(normalize_locale("de_DE@euro").as_deref(), Some("de-DE"));518
assert_eq!(normalize_locale("C"), None);519
assert_eq!(normalize_locale("POSIX"), None);520
assert_eq!(normalize_locale(""), None);521
}522
523
#[test]576
#[test]524
fn the_clock_follows_the_display_language() {577
fn the_clock_follows_the_display_language() {525
set_date_locale(Some("en-US"));578
set_date_locale(Some("en-US"));@@ -608,6 +661,7 @@ mod tests {608
661
609
#[test]662
#[test]610
fn list_time_is_clock_today_weekday_this_week_date_before() {663
fn list_time_is_clock_today_weekday_this_week_date_before() {664
let _guard = crate::ui_locale::locale_test_lock();611
assert_eq!(list_time_label(utc(7, 13), today(), zero()), "13:05");665
assert_eq!(list_time_label(utc(7, 13), today(), zero()), "13:05");612
assert_eq!(list_time_label(utc(5, 13), today(), zero()), "Mon");666
assert_eq!(list_time_label(utc(5, 13), today(), zero()), "Mon");613
assert_eq!(list_time_label(utc(6, 9), today(), zero()), "Tue");667
assert_eq!(list_time_label(utc(6, 9), today(), zero()), "Tue");@@ -633,6 +687,7 @@ mod tests {633
687
634
#[test]688
#[test]635
fn post_time_adds_the_day_when_not_today() {689
fn post_time_adds_the_day_when_not_today() {690
let _guard = crate::ui_locale::locale_test_lock();636
assert_eq!(post_time_label(utc(7, 13), today(), zero()), "13:05");691
assert_eq!(post_time_label(utc(7, 13), today(), zero()), "13:05");637
assert_eq!(692
assert_eq!(638
post_time_label(utc(6, 9), today(), zero()),693
post_time_label(utc(6, 9), today(), zero()),@@ -679,11 +734,12 @@ mod tests {679
734
680
#[test]735
#[test]681
fn day_labels() {736
fn day_labels() {737
let _guard = crate::ui_locale::locale_test_lock();682
assert_eq!(day_label(today(), today()), "Today");738
assert_eq!(day_label(today(), today()), "Today");683
assert_eq!(day_label(today().pred_opt().unwrap(), today()), "Yesterday");739
assert_eq!(day_label(today().pred_opt().unwrap(), today()), "Yesterday");684
assert_eq!(740
assert_eq!(685
day_label(NaiveDate::from_ymd_opt(2026, 10, 1).unwrap(), today()),741
day_label(NaiveDate::from_ymd_opt(2026, 10, 1).unwrap(), today()),686
"Thu, Oct 1, 2026"742
"Thu, October 1, 2026"687
);743
);688
}744
}689
}745
}@@ -32,6 +32,7 @@ pub mod orgs;
32
32
pub mod presence_link;
33
33
pub mod read_state;
34
34
pub mod recap;
35
pub mod regional;
35
36
pub mod release_feed;
36
37
pub mod remote_image;
37
38
pub mod runtime;
@@ -32,6 +32,7 @@ pub mod orgs;32
pub mod presence_link;32
pub mod presence_link;33
pub mod read_state;33
pub mod read_state;34
pub mod recap;34
pub mod recap;35
pub mod regional;35
pub mod release_feed;36
pub mod release_feed;36
pub mod remote_image;37
pub mod remote_image;37
pub mod runtime;38
pub mod runtime;@@ -0,0 +1,547 @@
1
//! Regional format: the date and time patterns, clock and week start the app uses.
2
//!
3
//! It is separate from the app language, as on the OS: English words in Austrian
4
//! patterns ("Mon, 16.11.", "14:30") is a normal setup. Teams has no account setting
5
//! for it and follows the OS, so the choice is stored locally.
6
7
use chrono::Weekday;
8
use serde::{Deserialize, Serialize};
9
use store::Store;
10
11
use crate::format::{self, DateStyle};
12
13
const PREFS_KEY: &str = "regional.format";
14
const FALLBACK_LOCALE: &str = "en";
15
16
/// Regions the date patterns in [`format::date_style`] know. A region decides the
17
/// patterns, whatever its language: Austria formats as `de-AT` in an English UI too.
18
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
19
#[serde(rename_all = "snake_case")]
20
pub enum Region {
21
Australia,
22
Austria,
23
Brazil,
24
Canada,
25
Czechia,
26
Denmark,
27
Finland,
28
France,
29
Germany,
30
India,
31
Ireland,
32
Italy,
33
Japan,
34
Netherlands,
35
Norway,
36
Poland,
37
Spain,
38
Sweden,
39
Switzerland,
40
UnitedKingdom,
41
UnitedStates,
42
}
43
44
impl Region {
45
pub const ALL: [Region; 21] = [
46
Region::Australia,
47
Region::Austria,
48
Region::Brazil,
49
Region::Canada,
50
Region::Czechia,
51
Region::Denmark,
52
Region::Finland,
53
Region::France,
54
Region::Germany,
55
Region::India,
56
Region::Ireland,
57
Region::Italy,
58
Region::Japan,
59
Region::Netherlands,
60
Region::Norway,
61
Region::Poland,
62
Region::Spain,
63
Region::Sweden,
64
Region::Switzerland,
65
Region::UnitedKingdom,
66
Region::UnitedStates,
67
];
68
69
/// ISO 3166 region code.
70
pub fn code(self) -> &'static str {
71
match self {
72
Region::Australia => "AU",
73
Region::Austria => "AT",
74
Region::Brazil => "BR",
75
Region::Canada => "CA",
76
Region::Czechia => "CZ",
77
Region::Denmark => "DK",
78
Region::Finland => "FI",
79
Region::France => "FR",
80
Region::Germany => "DE",
81
Region::India => "IN",
82
Region::Ireland => "IE",
83
Region::Italy => "IT",
84
Region::Japan => "JP",
85
Region::Netherlands => "NL",
86
Region::Norway => "NO",
87
Region::Poland => "PL",
88
Region::Spain => "ES",
89
Region::Sweden => "SE",
90
Region::Switzerland => "CH",
91
Region::UnitedKingdom => "GB",
92
Region::UnitedStates => "US",
93
}
94
}
95
96
/// The locale whose patterns the region uses.
97
fn format_locale(self) -> &'static str {
98
match self {
99
Region::Australia => "en-AU",
100
Region::Austria => "de-AT",
101
Region::Brazil => "pt-BR",
102
Region::Canada => "en-CA",
103
Region::Czechia => "cs-CZ",
104
Region::Denmark => "da-DK",
105
Region::Finland => "fi-FI",
106
Region::France => "fr-FR",
107
Region::Germany => "de-DE",
108
Region::India => "en-IN",
109
Region::Ireland => "en-IE",
110
Region::Italy => "it-IT",
111
Region::Japan => "ja-JP",
112
Region::Netherlands => "nl-NL",
113
Region::Norway => "nb-NO",
114
Region::Poland => "pl-PL",
115
Region::Spain => "es-ES",
116
Region::Sweden => "sv-SE",
117
Region::Switzerland => "de-CH",
118
Region::UnitedKingdom => "en-GB",
119
Region::UnitedStates => "en-US",
120
}
121
}
122
123
pub fn from_code(code: &str) -> Option<Region> {
124
Self::ALL
125
.into_iter()
126
.find(|region| region.code().eq_ignore_ascii_case(code))
127
}
128
129
/// The region of a locale tag such as `en-AT`.
130
pub fn of_locale(locale: &str) -> Option<Region> {
131
locale
132
.split(['-', '_'])
133
.skip(1)
134
.find(|part| part.len() == 2)
135
.and_then(Region::from_code)
136
}
137
138
/// Region name in the app language.
139
pub fn label(self) -> String {
140
crate::ui_locale::tr(&format!(
141
"regional.region.{}",
142
self.code().to_ascii_lowercase()
143
))
144
}
145
}
146
147
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
148
#[serde(rename_all = "snake_case")]
149
pub enum ClockPreference {
150
/// The region's clock, or the system's when the region follows the system.
151
#[default]
152
Auto,
153
Hours24,
154
Hours12,
155
}
156
157
impl ClockPreference {
158
pub const ALL: [ClockPreference; 3] = [
159
ClockPreference::Auto,
160
ClockPreference::Hours24,
161
ClockPreference::Hours12,
162
];
163
}
164
165
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
166
#[serde(default)]
167
pub struct RegionalPrefs {
168
/// `None` follows the system.
169
pub region: Option<Region>,
170
pub clock: ClockPreference,
171
/// `None` follows the mailbox language as Outlook does, then the region.
172
pub first_day: Option<Weekday>,
173
}
174
175
impl RegionalPrefs {
176
/// The same preferences with every field on automatic except the region.
177
pub fn automatic(self) -> RegionalPrefs {
178
RegionalPrefs {
179
region: self.region,
180
..RegionalPrefs::default()
181
}
182
}
183
}
184
185
/// `None` when the user never saved a choice.
186
pub fn load(store: &Store) -> Option<RegionalPrefs> {
187
let json = store.meta(PREFS_KEY).ok().flatten()?;
188
Some(serde_json::from_str(&json).unwrap_or_default())
189
}
190
191
pub fn save(store: &Store, prefs: &RegionalPrefs) {
192
let json = serde_json::to_string(prefs).unwrap_or_default();
193
if let Err(error) = store.set_meta(PREFS_KEY, &json) {
194
log::warn!("regional format not saved: {error}");
195
}
196
}
197
198
/// The OS regional format. Every field is `None` when the OS does not say.
199
#[derive(Debug, Clone, Default, PartialEq, Eq)]
200
pub struct SystemFormat {
201
/// Format locale such as `en-AT`; on macOS the region override wins over the language's region.
202
pub locale: Option<String>,
203
/// Set only when the user forced a clock on the OS.
204
pub twelve_hour: Option<bool>,
205
/// Set only when the OS has a first day of its own.
206
pub first_day: Option<Weekday>,
207
}
208
209
impl SystemFormat {
210
pub fn read() -> SystemFormat {
211
platform::read()
212
}
213
214
pub fn region(&self) -> Option<Region> {
215
self.locale.as_deref().and_then(Region::of_locale)
216
}
217
}
218
219
/// What the regional format falls back to besides the user's choice.
220
#[derive(Debug, Clone, Copy)]
221
pub struct FormatSources<'a> {
222
pub system: &'a SystemFormat,
223
/// Teams account display language, used when the OS gives no locale.
224
pub display_locale: Option<&'a str>,
225
/// Outlook mailbox language; Outlook takes the default first day from it.
226
pub mailbox_locale: Option<&'a str>,
227
}
228
229
/// The date style for the preferences. The region decides the patterns; the clock and
230
/// first day can be set on their own.
231
pub fn resolve(prefs: &RegionalPrefs, sources: FormatSources) -> DateStyle {
232
let follows_system = prefs.region.is_none();
233
let locale = match prefs.region {
234
Some(region) => region.format_locale(),
235
None => sources
236
.system
237
.locale
238
.as_deref()
239
.or(sources.display_locale)
240
.unwrap_or(FALLBACK_LOCALE),
241
};
242
let locale = Region::of_locale(locale).map_or(locale, |region| region.format_locale());
243
let mut style = format::date_style(locale);
244
let twelve_hour = match prefs.clock {
245
ClockPreference::Hours24 => Some(false),
246
ClockPreference::Hours12 => Some(true),
247
ClockPreference::Auto => sources.system.twelve_hour.filter(|_| follows_system),
248
};
249
if let Some(twelve_hour) = twelve_hour {
250
style = style.with_twelve_hour(twelve_hour);
251
}
252
let first_day = prefs
253
.first_day
254
.or(sources.mailbox_locale.map(format::first_day_for_locale))
255
.or(sources.system.first_day.filter(|_| follows_system));
256
if let Some(first_day) = first_day {
257
style = style.with_first_day(first_day);
258
}
259
style
260
}
261
262
/// `de_AT.UTF-8` and `de-AT` become `de-AT`; `C` and `POSIX` say nothing.
263
#[cfg_attr(target_os = "macos", allow(dead_code))]
264
fn normalize_locale(raw: &str) -> Option<String> {
265
let tag = raw
266
.split(['.', '@'])
267
.next()
268
.unwrap_or_default()
269
.replace('_', "-");
270
(!tag.is_empty() && tag != "C" && tag != "POSIX").then_some(tag)
271
}
272
273
/// macOS keeps the region in `AppleLocale`; a region set apart from the language
274
/// is an `rg` keyword: `en_US@rg=atzzzz` formats as Austria.
275
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
276
fn apple_locale_tag(raw: &str) -> Option<String> {
277
let (base, keywords) = raw.split_once('@').unwrap_or((raw, ""));
278
let mut parts = base.split(['_', '-']).filter(|part| !part.is_empty());
279
let language = parts.next()?;
280
let base_region = parts.find(|part| part.len() == 2);
281
let override_region = keywords
282
.split(';')
283
.find_map(|keyword| keyword.strip_prefix("rg="))
284
.and_then(|value| value.get(..2));
285
Some(match override_region.or(base_region) {
286
Some(region) => format!("{language}-{}", region.to_ascii_uppercase()),
287
None => language.to_owned(),
288
})
289
}
290
291
#[cfg(target_os = "macos")]
292
mod platform {
293
use std::ffi::c_void;
294
295
use chrono::Weekday;
296
use core_foundation::base::{CFType, TCFType};
297
use core_foundation::boolean::CFBoolean;
298
use core_foundation::number::CFNumber;
299
use core_foundation::string::CFString;
300
use core_foundation_sys::dictionary::{CFDictionaryGetTypeID, CFDictionaryGetValue};
301
use core_foundation_sys::preferences::{
302
CFPreferencesCopyAppValue, kCFPreferencesAnyApplication,
303
};
304
305
use super::SystemFormat;
306
307
/// A value of the global preferences domain (`defaults read -g`).
308
fn global(key: &str) -> Option<CFType> {
309
let key = CFString::new(key);
310
// SAFETY: a valid key and the any-application domain; the copy is owned.
311
let value = unsafe {
312
CFPreferencesCopyAppValue(key.as_concrete_TypeRef(), kCFPreferencesAnyApplication)
313
};
314
// SAFETY: non-null values come from a Copy function.
315
(!value.is_null()).then(|| unsafe { CFType::wrap_under_create_rule(value) })
316
}
317
318
fn flag(key: &str) -> bool {
319
global(key)
320
.and_then(|value| value.downcast::<CFBoolean>())
321
.is_some_and(bool::from)
322
}
323
324
/// `AppleFirstWeekday = { gregorian = 2 }`, counted from Sunday as 1.
325
fn first_weekday() -> Option<Weekday> {
326
let dictionary = global("AppleFirstWeekday")?;
327
// SAFETY: plain type id lookup.
328
if dictionary.type_of() != unsafe { CFDictionaryGetTypeID() } {
329
return None;
330
}
331
let key = CFString::new("gregorian");
332
// SAFETY: the dictionary type was checked; the value is borrowed from it.
333
let value = unsafe {
334
CFDictionaryGetValue(
335
dictionary.as_CFTypeRef().cast(),
336
key.as_concrete_TypeRef() as *const c_void,
337
)
338
};
339
if value.is_null() {
340
return None;
341
}
342
// SAFETY: non-null and owned by the dictionary, which outlives this call.
343
let number = unsafe { CFType::wrap_under_get_rule(value) }.downcast::<CFNumber>()?;
344
let from_sunday = number.to_i64().filter(|day| (1..=7).contains(day))?;
345
// chrono counts from Monday as 0.
346
Weekday::try_from(u8::try_from((from_sunday + 5) % 7).ok()?).ok()
347
}
348
349
pub fn read() -> SystemFormat {
350
let locale = global("AppleLocale")
351
.and_then(|value| value.downcast::<CFString>())
352
.and_then(|value| super::apple_locale_tag(&value.to_string()));
353
let twelve_hour = if flag("AppleICUForce24HourTime") {
354
Some(false)
355
} else if flag("AppleICUForce12HourTime") {
356
Some(true)
357
} else {
358
None
359
};
360
SystemFormat {
361
locale,
362
twelve_hour,
363
first_day: first_weekday(),
364
}
365
}
366
}
367
368
#[cfg(windows)]
369
mod platform {
370
use chrono::Weekday;
371
use windows::Win32::Globalization::{
372
GetLocaleInfoEx, GetUserDefaultLocaleName, LOCALE_IFIRSTDAYOFWEEK, LOCALE_ITIME,
373
};
374
use windows::core::PCWSTR;
375
376
use super::SystemFormat;
377
378
const LOCALE_NAME_MAX_LENGTH: usize = 85;
379
380
/// A value of the user's regional format, with the user's overrides applied.
381
fn user_info(kind: u32) -> Option<String> {
382
let mut buffer = [0u16; 8];
383
// SAFETY: a null name reads the user default locale; the buffer is sized for the value.
384
let length = unsafe { GetLocaleInfoEx(PCWSTR::null(), kind, Some(&mut buffer)) };
385
let length = usize::try_from(length).ok()?.checked_sub(1)?;
386
Some(String::from_utf16_lossy(&buffer[..length]))
387
}
388
389
pub fn read() -> SystemFormat {
390
let mut name = [0u16; LOCALE_NAME_MAX_LENGTH];
391
// SAFETY: the buffer has the documented maximum length.
392
let length = unsafe { GetUserDefaultLocaleName(&mut name) };
393
let locale = usize::try_from(length)
394
.ok()
395
.and_then(|length| length.checked_sub(1))
396
.map(|length| String::from_utf16_lossy(&name[..length]))
397
.and_then(|raw| super::normalize_locale(&raw));
398
// `LOCALE_IFIRSTDAYOFWEEK` counts from Monday as 0.
399
let first_day = user_info(LOCALE_IFIRSTDAYOFWEEK)
400
.and_then(|value| value.parse::<u8>().ok())
401
.and_then(|from_monday| Weekday::try_from(from_monday).ok());
402
SystemFormat {
403
locale,
404
twelve_hour: user_info(LOCALE_ITIME).map(|value| value == "0"),
405
first_day,
406
}
407
}
408
}
409
410
#[cfg(not(any(target_os = "macos", windows)))]
411
mod platform {
412
use super::SystemFormat;
413
414
/// `LC_TIME` is the date and time format; `LC_ALL` overrides it, `LANG` is the default.
415
pub fn read() -> SystemFormat {
416
let locale = ["LC_ALL", "LC_TIME", "LANG"]
417
.into_iter()
418
.find_map(|name| std::env::var(name).ok().filter(|value| !value.is_empty()))
419
.and_then(|raw| super::normalize_locale(&raw));
420
SystemFormat {
421
locale,
422
..SystemFormat::default()
423
}
424
}
425
}
426
427
#[cfg(test)]
428
mod tests {
429
use chrono::NaiveDate;
430
431
use super::*;
432
433
fn system(locale: &str) -> SystemFormat {
434
SystemFormat {
435
locale: Some(locale.to_owned()),
436
..SystemFormat::default()
437
}
438
}
439
440
fn style(prefs: RegionalPrefs, system: &SystemFormat, mailbox: Option<&str>) -> DateStyle {
441
resolve(
442
&prefs,
443
FormatSources {
444
system,
445
display_locale: None,
446
mailbox_locale: mailbox,
447
},
448
)
449
}
450
451
#[test]
452
fn the_macos_region_override_wins_over_the_language() {
453
assert_eq!(
454
apple_locale_tag("en_US@rg=atzzzz").as_deref(),
455
Some("en-AT")
456
);
457
assert_eq!(apple_locale_tag("de_AT").as_deref(), Some("de-AT"));
458
assert_eq!(apple_locale_tag("zh-Hans_CN").as_deref(), Some("zh-CN"));
459
assert_eq!(apple_locale_tag("en").as_deref(), Some("en"));
460
}
461
462
#[test]
463
fn os_locale_names_become_language_tags() {
464
assert_eq!(normalize_locale("en_GB.UTF-8").as_deref(), Some("en-GB"));
465
assert_eq!(normalize_locale("de_DE@euro").as_deref(), Some("de-DE"));
466
assert_eq!(normalize_locale("C"), None);
467
assert_eq!(normalize_locale(""), None);
468
}
469
470
#[test]
471
fn english_in_austria_formats_as_austria() {
472
let style = style(RegionalPrefs::default(), &system("en-AT"), None);
473
let date = NaiveDate::from_ymd_opt(2026, 3, 9).unwrap();
474
assert_eq!(style.clock(), "%H:%M");
475
assert_eq!(style.first_day(), Weekday::Mon);
476
format::set_date_style(Some(style));
477
assert_eq!(format::date_label(date), "9.3.2026");
478
assert_eq!(format::decimal_label(1.5, 1), "1,5");
479
format::set_date_style(None);
480
}
481
482
#[test]
483
fn a_chosen_region_ignores_the_system_clock_and_first_day() {
484
let forced = SystemFormat {
485
twelve_hour: Some(false),
486
first_day: Some(Weekday::Sat),
487
..system("de-AT")
488
};
489
let follows = style(RegionalPrefs::default(), &forced, None);
490
assert!(!follows.twelve_hour());
491
assert_eq!(follows.first_day(), Weekday::Sat);
492
let chosen = RegionalPrefs {
493
region: Some(Region::UnitedStates),
494
..RegionalPrefs::default()
495
};
496
let us = style(chosen, &forced, None);
497
assert!(us.twelve_hour());
498
assert_eq!(us.first_day(), Weekday::Sun);
499
}
500
501
#[test]
502
fn the_first_day_is_the_choice_then_the_mailbox_then_the_region() {
503
let us = system("en-US");
504
assert_eq!(
505
style(RegionalPrefs::default(), &us, None).first_day(),
506
Weekday::Sun
507
);
508
assert_eq!(
509
style(RegionalPrefs::default(), &us, Some("en-AT")).first_day(),
510
Weekday::Mon
511
);
512
let chosen = RegionalPrefs {
513
first_day: Some(Weekday::Sat),
514
..RegionalPrefs::default()
515
};
516
assert_eq!(style(chosen, &us, Some("en-AT")).first_day(), Weekday::Sat);
517
}
518
519
#[test]
520
fn the_clock_choice_overrides_the_region() {
521
let hours_12 = RegionalPrefs {
522
clock: ClockPreference::Hours12,
523
..RegionalPrefs::default()
524
};
525
assert_eq!(style(hours_12, &system("de-AT"), None).clock(), "%-I:%M %p");
526
let hours_24 = RegionalPrefs {
527
clock: ClockPreference::Hours24,
528
..RegionalPrefs::default()
529
};
530
assert_eq!(style(hours_24, &system("en-US"), None).clock(), "%H:%M");
531
// A 12-hour region keeps its own spelling.
532
assert_eq!(style(hours_12, &system("en-AU"), None).clock(), "%-I:%M %P");
533
}
534
535
#[test]
536
fn prefs_are_none_until_saved_and_round_trip() {
537
let store = Store::open_in_memory().unwrap();
538
assert_eq!(load(&store), None);
539
let prefs = RegionalPrefs {
540
region: Some(Region::Austria),
541
clock: ClockPreference::Hours24,
542
first_day: Some(Weekday::Mon),
543
};
544
save(&store, &prefs);
545
assert_eq!(load(&store), Some(prefs));
546
}
547
}
@@ -0,0 +1,547 @@1
//! Regional format: the date and time patterns, clock and week start the app uses.2
//!3
//! It is separate from the app language, as on the OS: English words in Austrian4
//! patterns ("Mon, 16.11.", "14:30") is a normal setup. Teams has no account setting5
//! for it and follows the OS, so the choice is stored locally.6
7
use chrono::Weekday;8
use serde::{Deserialize, Serialize};9
use store::Store;10
11
use crate::format::{self, DateStyle};12
13
const PREFS_KEY: &str = "regional.format";14
const FALLBACK_LOCALE: &str = "en";15
16
/// Regions the date patterns in [`format::date_style`] know. A region decides the17
/// patterns, whatever its language: Austria formats as `de-AT` in an English UI too.18
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]19
#[serde(rename_all = "snake_case")]20
pub enum Region {21
Australia,22
Austria,23
Brazil,24
Canada,25
Czechia,26
Denmark,27
Finland,28
France,29
Germany,30
India,31
Ireland,32
Italy,33
Japan,34
Netherlands,35
Norway,36
Poland,37
Spain,38
Sweden,39
Switzerland,40
UnitedKingdom,41
UnitedStates,42
}43
44
impl Region {45
pub const ALL: [Region; 21] = [46
Region::Australia,47
Region::Austria,48
Region::Brazil,49
Region::Canada,50
Region::Czechia,51
Region::Denmark,52
Region::Finland,53
Region::France,54
Region::Germany,55
Region::India,56
Region::Ireland,57
Region::Italy,58
Region::Japan,59
Region::Netherlands,60
Region::Norway,61
Region::Poland,62
Region::Spain,63
Region::Sweden,64
Region::Switzerland,65
Region::UnitedKingdom,66
Region::UnitedStates,67
];68
69
/// ISO 3166 region code.70
pub fn code(self) -> &'static str {71
match self {72
Region::Australia => "AU",73
Region::Austria => "AT",74
Region::Brazil => "BR",75
Region::Canada => "CA",76
Region::Czechia => "CZ",77
Region::Denmark => "DK",78
Region::Finland => "FI",79
Region::France => "FR",80
Region::Germany => "DE",81
Region::India => "IN",82
Region::Ireland => "IE",83
Region::Italy => "IT",84
Region::Japan => "JP",85
Region::Netherlands => "NL",86
Region::Norway => "NO",87
Region::Poland => "PL",88
Region::Spain => "ES",89
Region::Sweden => "SE",90
Region::Switzerland => "CH",91
Region::UnitedKingdom => "GB",92
Region::UnitedStates => "US",93
}94
}95
96
/// The locale whose patterns the region uses.97
fn format_locale(self) -> &'static str {98
match self {99
Region::Australia => "en-AU",100
Region::Austria => "de-AT",101
Region::Brazil => "pt-BR",102
Region::Canada => "en-CA",103
Region::Czechia => "cs-CZ",104
Region::Denmark => "da-DK",105
Region::Finland => "fi-FI",106
Region::France => "fr-FR",107
Region::Germany => "de-DE",108
Region::India => "en-IN",109
Region::Ireland => "en-IE",110
Region::Italy => "it-IT",111
Region::Japan => "ja-JP",112
Region::Netherlands => "nl-NL",113
Region::Norway => "nb-NO",114
Region::Poland => "pl-PL",115
Region::Spain => "es-ES",116
Region::Sweden => "sv-SE",117
Region::Switzerland => "de-CH",118
Region::UnitedKingdom => "en-GB",119
Region::UnitedStates => "en-US",120
}121
}122
123
pub fn from_code(code: &str) -> Option<Region> {124
Self::ALL125
.into_iter()126
.find(|region| region.code().eq_ignore_ascii_case(code))127
}128
129
/// The region of a locale tag such as `en-AT`.130
pub fn of_locale(locale: &str) -> Option<Region> {131
locale132
.split(['-', '_'])133
.skip(1)134
.find(|part| part.len() == 2)135
.and_then(Region::from_code)136
}137
138
/// Region name in the app language.139
pub fn label(self) -> String {140
crate::ui_locale::tr(&format!(141
"regional.region.{}",142
self.code().to_ascii_lowercase()143
))144
}145
}146
147
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]148
#[serde(rename_all = "snake_case")]149
pub enum ClockPreference {150
/// The region's clock, or the system's when the region follows the system.151
#[default]152
Auto,153
Hours24,154
Hours12,155
}156
157
impl ClockPreference {158
pub const ALL: [ClockPreference; 3] = [159
ClockPreference::Auto,160
ClockPreference::Hours24,161
ClockPreference::Hours12,162
];163
}164
165
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]166
#[serde(default)]167
pub struct RegionalPrefs {168
/// `None` follows the system.169
pub region: Option<Region>,170
pub clock: ClockPreference,171
/// `None` follows the mailbox language as Outlook does, then the region.172
pub first_day: Option<Weekday>,173
}174
175
impl RegionalPrefs {176
/// The same preferences with every field on automatic except the region.177
pub fn automatic(self) -> RegionalPrefs {178
RegionalPrefs {179
region: self.region,180
..RegionalPrefs::default()181
}182
}183
}184
185
/// `None` when the user never saved a choice.186
pub fn load(store: &Store) -> Option<RegionalPrefs> {187
let json = store.meta(PREFS_KEY).ok().flatten()?;188
Some(serde_json::from_str(&json).unwrap_or_default())189
}190
191
pub fn save(store: &Store, prefs: &RegionalPrefs) {192
let json = serde_json::to_string(prefs).unwrap_or_default();193
if let Err(error) = store.set_meta(PREFS_KEY, &json) {194
log::warn!("regional format not saved: {error}");195
}196
}197
198
/// The OS regional format. Every field is `None` when the OS does not say.199
#[derive(Debug, Clone, Default, PartialEq, Eq)]200
pub struct SystemFormat {201
/// Format locale such as `en-AT`; on macOS the region override wins over the language's region.202
pub locale: Option<String>,203
/// Set only when the user forced a clock on the OS.204
pub twelve_hour: Option<bool>,205
/// Set only when the OS has a first day of its own.206
pub first_day: Option<Weekday>,207
}208
209
impl SystemFormat {210
pub fn read() -> SystemFormat {211
platform::read()212
}213
214
pub fn region(&self) -> Option<Region> {215
self.locale.as_deref().and_then(Region::of_locale)216
}217
}218
219
/// What the regional format falls back to besides the user's choice.220
#[derive(Debug, Clone, Copy)]221
pub struct FormatSources<'a> {222
pub system: &'a SystemFormat,223
/// Teams account display language, used when the OS gives no locale.224
pub display_locale: Option<&'a str>,225
/// Outlook mailbox language; Outlook takes the default first day from it.226
pub mailbox_locale: Option<&'a str>,227
}228
229
/// The date style for the preferences. The region decides the patterns; the clock and230
/// first day can be set on their own.231
pub fn resolve(prefs: &RegionalPrefs, sources: FormatSources) -> DateStyle {232
let follows_system = prefs.region.is_none();233
let locale = match prefs.region {234
Some(region) => region.format_locale(),235
None => sources236
.system237
.locale238
.as_deref()239
.or(sources.display_locale)240
.unwrap_or(FALLBACK_LOCALE),241
};242
let locale = Region::of_locale(locale).map_or(locale, |region| region.format_locale());243
let mut style = format::date_style(locale);244
let twelve_hour = match prefs.clock {245
ClockPreference::Hours24 => Some(false),246
ClockPreference::Hours12 => Some(true),247
ClockPreference::Auto => sources.system.twelve_hour.filter(|_| follows_system),248
};249
if let Some(twelve_hour) = twelve_hour {250
style = style.with_twelve_hour(twelve_hour);251
}252
let first_day = prefs253
.first_day254
.or(sources.mailbox_locale.map(format::first_day_for_locale))255
.or(sources.system.first_day.filter(|_| follows_system));256
if let Some(first_day) = first_day {257
style = style.with_first_day(first_day);258
}259
style260
}261
262
/// `de_AT.UTF-8` and `de-AT` become `de-AT`; `C` and `POSIX` say nothing.263
#[cfg_attr(target_os = "macos", allow(dead_code))]264
fn normalize_locale(raw: &str) -> Option<String> {265
let tag = raw266
.split(['.', '@'])267
.next()268
.unwrap_or_default()269
.replace('_', "-");270
(!tag.is_empty() && tag != "C" && tag != "POSIX").then_some(tag)271
}272
273
/// macOS keeps the region in `AppleLocale`; a region set apart from the language274
/// is an `rg` keyword: `en_US@rg=atzzzz` formats as Austria.275
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]276
fn apple_locale_tag(raw: &str) -> Option<String> {277
let (base, keywords) = raw.split_once('@').unwrap_or((raw, ""));278
let mut parts = base.split(['_', '-']).filter(|part| !part.is_empty());279
let language = parts.next()?;280
let base_region = parts.find(|part| part.len() == 2);281
let override_region = keywords282
.split(';')283
.find_map(|keyword| keyword.strip_prefix("rg="))284
.and_then(|value| value.get(..2));285
Some(match override_region.or(base_region) {286
Some(region) => format!("{language}-{}", region.to_ascii_uppercase()),287
None => language.to_owned(),288
})289
}290
291
#[cfg(target_os = "macos")]292
mod platform {293
use std::ffi::c_void;294
295
use chrono::Weekday;296
use core_foundation::base::{CFType, TCFType};297
use core_foundation::boolean::CFBoolean;298
use core_foundation::number::CFNumber;299
use core_foundation::string::CFString;300
use core_foundation_sys::dictionary::{CFDictionaryGetTypeID, CFDictionaryGetValue};301
use core_foundation_sys::preferences::{302
CFPreferencesCopyAppValue, kCFPreferencesAnyApplication,303
};304
305
use super::SystemFormat;306
307
/// A value of the global preferences domain (`defaults read -g`).308
fn global(key: &str) -> Option<CFType> {309
let key = CFString::new(key);310
// SAFETY: a valid key and the any-application domain; the copy is owned.311
let value = unsafe {312
CFPreferencesCopyAppValue(key.as_concrete_TypeRef(), kCFPreferencesAnyApplication)313
};314
// SAFETY: non-null values come from a Copy function.315
(!value.is_null()).then(|| unsafe { CFType::wrap_under_create_rule(value) })316
}317
318
fn flag(key: &str) -> bool {319
global(key)320
.and_then(|value| value.downcast::<CFBoolean>())321
.is_some_and(bool::from)322
}323
324
/// `AppleFirstWeekday = { gregorian = 2 }`, counted from Sunday as 1.325
fn first_weekday() -> Option<Weekday> {326
let dictionary = global("AppleFirstWeekday")?;327
// SAFETY: plain type id lookup.328
if dictionary.type_of() != unsafe { CFDictionaryGetTypeID() } {329
return None;330
}331
let key = CFString::new("gregorian");332
// SAFETY: the dictionary type was checked; the value is borrowed from it.333
let value = unsafe {334
CFDictionaryGetValue(335
dictionary.as_CFTypeRef().cast(),336
key.as_concrete_TypeRef() as *const c_void,337
)338
};339
if value.is_null() {340
return None;341
}342
// SAFETY: non-null and owned by the dictionary, which outlives this call.343
let number = unsafe { CFType::wrap_under_get_rule(value) }.downcast::<CFNumber>()?;344
let from_sunday = number.to_i64().filter(|day| (1..=7).contains(day))?;345
// chrono counts from Monday as 0.346
Weekday::try_from(u8::try_from((from_sunday + 5) % 7).ok()?).ok()347
}348
349
pub fn read() -> SystemFormat {350
let locale = global("AppleLocale")351
.and_then(|value| value.downcast::<CFString>())352
.and_then(|value| super::apple_locale_tag(&value.to_string()));353
let twelve_hour = if flag("AppleICUForce24HourTime") {354
Some(false)355
} else if flag("AppleICUForce12HourTime") {356
Some(true)357
} else {358
None359
};360
SystemFormat {361
locale,362
twelve_hour,363
first_day: first_weekday(),364
}365
}366
}367
368
#[cfg(windows)]369
mod platform {370
use chrono::Weekday;371
use windows::Win32::Globalization::{372
GetLocaleInfoEx, GetUserDefaultLocaleName, LOCALE_IFIRSTDAYOFWEEK, LOCALE_ITIME,373
};374
use windows::core::PCWSTR;375
376
use super::SystemFormat;377
378
const LOCALE_NAME_MAX_LENGTH: usize = 85;379
380
/// A value of the user's regional format, with the user's overrides applied.381
fn user_info(kind: u32) -> Option<String> {382
let mut buffer = [0u16; 8];383
// SAFETY: a null name reads the user default locale; the buffer is sized for the value.384
let length = unsafe { GetLocaleInfoEx(PCWSTR::null(), kind, Some(&mut buffer)) };385
let length = usize::try_from(length).ok()?.checked_sub(1)?;386
Some(String::from_utf16_lossy(&buffer[..length]))387
}388
389
pub fn read() -> SystemFormat {390
let mut name = [0u16; LOCALE_NAME_MAX_LENGTH];391
// SAFETY: the buffer has the documented maximum length.392
let length = unsafe { GetUserDefaultLocaleName(&mut name) };393
let locale = usize::try_from(length)394
.ok()395
.and_then(|length| length.checked_sub(1))396
.map(|length| String::from_utf16_lossy(&name[..length]))397
.and_then(|raw| super::normalize_locale(&raw));398
// `LOCALE_IFIRSTDAYOFWEEK` counts from Monday as 0.399
let first_day = user_info(LOCALE_IFIRSTDAYOFWEEK)400
.and_then(|value| value.parse::<u8>().ok())401
.and_then(|from_monday| Weekday::try_from(from_monday).ok());402
SystemFormat {403
locale,404
twelve_hour: user_info(LOCALE_ITIME).map(|value| value == "0"),405
first_day,406
}407
}408
}409
410
#[cfg(not(any(target_os = "macos", windows)))]411
mod platform {412
use super::SystemFormat;413
414
/// `LC_TIME` is the date and time format; `LC_ALL` overrides it, `LANG` is the default.415
pub fn read() -> SystemFormat {416
let locale = ["LC_ALL", "LC_TIME", "LANG"]417
.into_iter()418
.find_map(|name| std::env::var(name).ok().filter(|value| !value.is_empty()))419
.and_then(|raw| super::normalize_locale(&raw));420
SystemFormat {421
locale,422
..SystemFormat::default()423
}424
}425
}426
427
#[cfg(test)]428
mod tests {429
use chrono::NaiveDate;430
431
use super::*;432
433
fn system(locale: &str) -> SystemFormat {434
SystemFormat {435
locale: Some(locale.to_owned()),436
..SystemFormat::default()437
}438
}439
440
fn style(prefs: RegionalPrefs, system: &SystemFormat, mailbox: Option<&str>) -> DateStyle {441
resolve(442
&prefs,443
FormatSources {444
system,445
display_locale: None,446
mailbox_locale: mailbox,447
},448
)449
}450
451
#[test]452
fn the_macos_region_override_wins_over_the_language() {453
assert_eq!(454
apple_locale_tag("en_US@rg=atzzzz").as_deref(),455
Some("en-AT")456
);457
assert_eq!(apple_locale_tag("de_AT").as_deref(), Some("de-AT"));458
assert_eq!(apple_locale_tag("zh-Hans_CN").as_deref(), Some("zh-CN"));459
assert_eq!(apple_locale_tag("en").as_deref(), Some("en"));460
}461
462
#[test]463
fn os_locale_names_become_language_tags() {464
assert_eq!(normalize_locale("en_GB.UTF-8").as_deref(), Some("en-GB"));465
assert_eq!(normalize_locale("de_DE@euro").as_deref(), Some("de-DE"));466
assert_eq!(normalize_locale("C"), None);467
assert_eq!(normalize_locale(""), None);468
}469
470
#[test]471
fn english_in_austria_formats_as_austria() {472
let style = style(RegionalPrefs::default(), &system("en-AT"), None);473
let date = NaiveDate::from_ymd_opt(2026, 3, 9).unwrap();474
assert_eq!(style.clock(), "%H:%M");475
assert_eq!(style.first_day(), Weekday::Mon);476
format::set_date_style(Some(style));477
assert_eq!(format::date_label(date), "9.3.2026");478
assert_eq!(format::decimal_label(1.5, 1), "1,5");479
format::set_date_style(None);480
}481
482
#[test]483
fn a_chosen_region_ignores_the_system_clock_and_first_day() {484
let forced = SystemFormat {485
twelve_hour: Some(false),486
first_day: Some(Weekday::Sat),487
..system("de-AT")488
};489
let follows = style(RegionalPrefs::default(), &forced, None);490
assert!(!follows.twelve_hour());491
assert_eq!(follows.first_day(), Weekday::Sat);492
let chosen = RegionalPrefs {493
region: Some(Region::UnitedStates),494
..RegionalPrefs::default()495
};496
let us = style(chosen, &forced, None);497
assert!(us.twelve_hour());498
assert_eq!(us.first_day(), Weekday::Sun);499
}500
501
#[test]502
fn the_first_day_is_the_choice_then_the_mailbox_then_the_region() {503
let us = system("en-US");504
assert_eq!(505
style(RegionalPrefs::default(), &us, None).first_day(),506
Weekday::Sun507
);508
assert_eq!(509
style(RegionalPrefs::default(), &us, Some("en-AT")).first_day(),510
Weekday::Mon511
);512
let chosen = RegionalPrefs {513
first_day: Some(Weekday::Sat),514
..RegionalPrefs::default()515
};516
assert_eq!(style(chosen, &us, Some("en-AT")).first_day(), Weekday::Sat);517
}518
519
#[test]520
fn the_clock_choice_overrides_the_region() {521
let hours_12 = RegionalPrefs {522
clock: ClockPreference::Hours12,523
..RegionalPrefs::default()524
};525
assert_eq!(style(hours_12, &system("de-AT"), None).clock(), "%-I:%M %p");526
let hours_24 = RegionalPrefs {527
clock: ClockPreference::Hours24,528
..RegionalPrefs::default()529
};530
assert_eq!(style(hours_24, &system("en-US"), None).clock(), "%H:%M");531
// A 12-hour region keeps its own spelling.532
assert_eq!(style(hours_12, &system("en-AU"), None).clock(), "%-I:%M %P");533
}534
535
#[test]536
fn prefs_are_none_until_saved_and_round_trip() {537
let store = Store::open_in_memory().unwrap();538
assert_eq!(load(&store), None);539
let prefs = RegionalPrefs {540
region: Some(Region::Austria),541
clock: ClockPreference::Hours24,542
first_day: Some(Weekday::Mon),543
};544
save(&store, &prefs);545
assert_eq!(load(&store), Some(prefs));546
}547
}@@ -131,7 +131,7 @@ pub fn day_choices(today: NaiveDate) -> Vec<DayChoice> {
131
131
let date = today + Duration::days(offset);
132
132
DayChoice {
133
133
date,
134
label: date.format("%a %-d %b").to_string(),
134
label: crate::format::weekday_date_label(date),
135
135
}
136
136
})
137
137
.collect()
@@ -174,13 +174,13 @@ pub fn format_time(time: NaiveTime) -> String {
174
174
175
175
pub fn describe(at: DateTime<Local>, now: DateTime<Local>) -> String {
176
176
let days_ahead = (at.date_naive() - now.date_naive()).num_days();
177
let clock = at.format(crate::format::clock_format()).to_string();
177
178
match days_ahead {
178
0 => format!("today {}", at.format(crate::format::clock_format())),
179
0 => crate::ui_locale::tr_with("regional.today_clock", &[("clock", &clock)]),
179
180
1..=6 => weekday_clock(at),
180
181
_ => format!(
181
"{} {}",
182
at.format("%a %-d %b"),
183
at.format(crate::format::clock_format())
182
"{} {clock}",
183
crate::format::weekday_date_label(at.date_naive())
184
184
),
185
185
}
186
186
}
@@ -188,7 +188,7 @@ pub fn describe(at: DateTime<Local>, now: DateTime<Local>) -> String {
188
188
fn weekday_clock(at: DateTime<Local>) -> String {
189
189
format!(
190
190
"{} {}",
191
at.format("%a"),
191
crate::format::weekday_name(at.weekday(), crate::format::WeekdayWidth::Short),
192
192
at.format(crate::format::clock_format())
193
193
)
194
194
}
@@ -226,6 +226,7 @@ mod tests {
226
226
227
227
#[test]
228
228
fn midweek_offers_tomorrow_and_next_monday() {
229
let _guard = crate::ui_locale::locale_test_lock();
229
230
let found = presets(at(8, 9, 0));
230
231
let labels: Vec<_> = found.iter().map(|preset| preset.label).collect();
231
232
assert_eq!(
@@ -250,6 +251,7 @@ mod tests {
250
251
251
252
#[test]
252
253
fn sunday_shows_tomorrow_only_because_monday_would_duplicate_it() {
254
let _guard = crate::ui_locale::locale_test_lock();
253
255
let found = presets(at(11, 21, 0));
254
256
assert_eq!(found.len(), 1);
255
257
assert_eq!(found[0].kind, PresetKind::TomorrowMorning);
@@ -285,10 +287,11 @@ mod tests {
285
287
286
288
#[test]
287
289
fn day_choices_run_from_today_for_seven_days() {
290
let _guard = crate::ui_locale::locale_test_lock();
288
291
let choices = day_choices(at(9, 12, 0).date_naive());
289
292
assert_eq!(choices.len(), 7);
290
assert_eq!(choices[0].label, "Fri 9 Oct");
291
assert_eq!(choices[6].label, "Thu 15 Oct");
293
assert_eq!(choices[0].label, "Fri, Oct 9");
294
assert_eq!(choices[6].label, "Thu, Oct 15");
292
295
}
293
296
294
297
#[test]
@@ -318,9 +321,10 @@ mod tests {
318
321
319
322
#[test]
320
323
fn describing_a_time_names_today_or_the_weekday() {
324
let _guard = crate::ui_locale::locale_test_lock();
321
325
let now = at(9, 10, 0);
322
326
assert_eq!(describe(at(9, 15, 30), now), "today 15:30");
323
327
assert_eq!(describe(at(12, 8, 15), now), "Mon 08:15");
324
assert_eq!(describe(at(16, 8, 15), now), "Fri 16 Oct 08:15");
328
assert_eq!(describe(at(16, 8, 15), now), "Fri, Oct 16 08:15");
325
329
}
326
330
}
@@ -131,7 +131,7 @@ pub fn day_choices(today: NaiveDate) -> Vec<DayChoice> {131
let date = today + Duration::days(offset);131
let date = today + Duration::days(offset);132
DayChoice {132
DayChoice {133
date,133
date,134
label: date.format("%a %-d %b").to_string(),134
label: crate::format::weekday_date_label(date),135
}135
}136
})136
})137
.collect()137
.collect()@@ -174,13 +174,13 @@ pub fn format_time(time: NaiveTime) -> String {174
174
175
pub fn describe(at: DateTime<Local>, now: DateTime<Local>) -> String {175
pub fn describe(at: DateTime<Local>, now: DateTime<Local>) -> String {176
let days_ahead = (at.date_naive() - now.date_naive()).num_days();176
let days_ahead = (at.date_naive() - now.date_naive()).num_days();177
let clock = at.format(crate::format::clock_format()).to_string();177
match days_ahead {178
match days_ahead {178
0 => format!("today {}", at.format(crate::format::clock_format())),179
0 => crate::ui_locale::tr_with("regional.today_clock", &[("clock", &clock)]),179
1..=6 => weekday_clock(at),180
1..=6 => weekday_clock(at),180
_ => format!(181
_ => format!(181
"{} {}",182
"{} {clock}",182
at.format("%a %-d %b"),183
crate::format::weekday_date_label(at.date_naive())183
at.format(crate::format::clock_format())184
),184
),185
}185
}186
}186
}@@ -188,7 +188,7 @@ pub fn describe(at: DateTime<Local>, now: DateTime<Local>) -> String {188
fn weekday_clock(at: DateTime<Local>) -> String {188
fn weekday_clock(at: DateTime<Local>) -> String {189
format!(189
format!(190
"{} {}",190
"{} {}",191
at.format("%a"),191
crate::format::weekday_name(at.weekday(), crate::format::WeekdayWidth::Short),192
at.format(crate::format::clock_format())192
at.format(crate::format::clock_format())193
)193
)194
}194
}@@ -226,6 +226,7 @@ mod tests {226
226
227
#[test]227
#[test]228
fn midweek_offers_tomorrow_and_next_monday() {228
fn midweek_offers_tomorrow_and_next_monday() {229
let _guard = crate::ui_locale::locale_test_lock();229
let found = presets(at(8, 9, 0));230
let found = presets(at(8, 9, 0));230
let labels: Vec<_> = found.iter().map(|preset| preset.label).collect();231
let labels: Vec<_> = found.iter().map(|preset| preset.label).collect();231
assert_eq!(232
assert_eq!(@@ -250,6 +251,7 @@ mod tests {250
251
251
#[test]252
#[test]252
fn sunday_shows_tomorrow_only_because_monday_would_duplicate_it() {253
fn sunday_shows_tomorrow_only_because_monday_would_duplicate_it() {254
let _guard = crate::ui_locale::locale_test_lock();253
let found = presets(at(11, 21, 0));255
let found = presets(at(11, 21, 0));254
assert_eq!(found.len(), 1);256
assert_eq!(found.len(), 1);255
assert_eq!(found[0].kind, PresetKind::TomorrowMorning);257
assert_eq!(found[0].kind, PresetKind::TomorrowMorning);@@ -285,10 +287,11 @@ mod tests {285
287
286
#[test]288
#[test]287
fn day_choices_run_from_today_for_seven_days() {289
fn day_choices_run_from_today_for_seven_days() {290
let _guard = crate::ui_locale::locale_test_lock();288
let choices = day_choices(at(9, 12, 0).date_naive());291
let choices = day_choices(at(9, 12, 0).date_naive());289
assert_eq!(choices.len(), 7);292
assert_eq!(choices.len(), 7);290
assert_eq!(choices[0].label, "Fri 9 Oct");293
assert_eq!(choices[0].label, "Fri, Oct 9");291
assert_eq!(choices[6].label, "Thu 15 Oct");294
assert_eq!(choices[6].label, "Thu, Oct 15");292
}295
}293
296
294
#[test]297
#[test]@@ -318,9 +321,10 @@ mod tests {318
321
319
#[test]322
#[test]320
fn describing_a_time_names_today_or_the_weekday() {323
fn describing_a_time_names_today_or_the_weekday() {324
let _guard = crate::ui_locale::locale_test_lock();321
let now = at(9, 10, 0);325
let now = at(9, 10, 0);322
assert_eq!(describe(at(9, 15, 30), now), "today 15:30");326
assert_eq!(describe(at(9, 15, 30), now), "today 15:30");323
assert_eq!(describe(at(12, 8, 15), now), "Mon 08:15");327
assert_eq!(describe(at(12, 8, 15), now), "Mon 08:15");324
assert_eq!(describe(at(16, 8, 15), now), "Fri 16 Oct 08:15");328
assert_eq!(describe(at(16, 8, 15), now), "Fri, Oct 16 08:15");325
}329
}326
}330
}@@ -277,9 +277,15 @@ pub fn format_bytes(size: u64) -> String {
277
277
const KB: u64 = 1024;
278
278
const MB: u64 = KB * 1024;
279
279
if size >= MB {
280
format!("{:.1} MB", size as f64 / MB as f64)
280
format!(
281
"{} MB",
282
crate::format::decimal_label(size as f64 / MB as f64, 1)
283
)
281
284
} else if size >= KB {
282
format!("{:.1} KB", size as f64 / KB as f64)
285
format!(
286
"{} KB",
287
crate::format::decimal_label(size as f64 / KB as f64, 1)
288
)
283
289
} else {
284
290
format!("{size} B")
285
291
}
@@ -277,9 +277,15 @@ pub fn format_bytes(size: u64) -> String {277
const KB: u64 = 1024;277
const KB: u64 = 1024;278
const MB: u64 = KB * 1024;278
const MB: u64 = KB * 1024;279
if size >= MB {279
if size >= MB {280
format!("{:.1} MB", size as f64 / MB as f64)280
format!(281
"{} MB",282
crate::format::decimal_label(size as f64 / MB as f64, 1)283
)281
} else if size >= KB {284
} else if size >= KB {282
format!("{:.1} KB", size as f64 / KB as f64)285
format!(286
"{} KB",287
crate::format::decimal_label(size as f64 / KB as f64, 1)288
)283
} else {289
} else {284
format!("{size} B")290
format!("{size} B")285
}291
}@@ -103,6 +103,15 @@ pub fn tr_args(key: &str, args: &HashMap<String, String>) -> String {
103
103
rust_i18n::replace_patterns(&tr(key), &patterns, &values)
104
104
}
105
105
106
/// `tr_with("regional.until", &[("time", "14:30")])` for a pattern with `%{time}`.
107
pub fn tr_with(key: &str, args: &[(&str, &str)]) -> String {
108
let (patterns, values): (Vec<&str>, Vec<String>) = args
109
.iter()
110
.map(|(name, value)| (*name, (*value).to_owned()))
111
.unzip();
112
rust_i18n::replace_patterns(&tr(key), &patterns, &values)
113
}
114
106
115
/// Separator between an i18n key and a detail payload in `CallUpdate::Notice`.
107
116
pub const NOTICE_DETAIL_SEP: char = '\u{1f}';
108
117
@@ -103,6 +103,15 @@ pub fn tr_args(key: &str, args: &HashMap<String, String>) -> String {103
rust_i18n::replace_patterns(&tr(key), &patterns, &values)103
rust_i18n::replace_patterns(&tr(key), &patterns, &values)104
}104
}105
105
106
/// `tr_with("regional.until", &[("time", "14:30")])` for a pattern with `%{time}`.107
pub fn tr_with(key: &str, args: &[(&str, &str)]) -> String {108
let (patterns, values): (Vec<&str>, Vec<String>) = args109
.iter()110
.map(|(name, value)| (*name, (*value).to_owned()))111
.unzip();112
rust_i18n::replace_patterns(&tr(key), &patterns, &values)113
}114
106
/// Separator between an i18n key and a detail payload in `CallUpdate::Notice`.115
/// Separator between an i18n key and a detail payload in `CallUpdate::Notice`.107
pub const NOTICE_DETAIL_SEP: char = '\u{1f}';116
pub const NOTICE_DETAIL_SEP: char = '\u{1f}';108
117
@@ -59,11 +59,11 @@ pub fn response_label(response: ResponseType) -> &'static str {
59
59
60
60
pub fn day_heading(day: NaiveDate, today: NaiveDate) -> String {
61
61
if day == today {
62
"Today".to_owned()
62
app_base::ui_locale::tr("regional.today")
63
63
} else if today.succ_opt() == Some(day) {
64
"Tomorrow".to_owned()
64
app_base::ui_locale::tr("regional.tomorrow")
65
65
} else {
66
day.format("%a, %b %-d").to_string()
66
app_base::format::weekday_date_label(day)
67
67
}
68
68
}
69
69
@@ -59,11 +59,11 @@ pub fn response_label(response: ResponseType) -> &'static str {59
59
60
pub fn day_heading(day: NaiveDate, today: NaiveDate) -> String {60
pub fn day_heading(day: NaiveDate, today: NaiveDate) -> String {61
if day == today {61
if day == today {62
"Today".to_owned()62
app_base::ui_locale::tr("regional.today")63
} else if today.succ_opt() == Some(day) {63
} else if today.succ_opt() == Some(day) {64
"Tomorrow".to_owned()64
app_base::ui_locale::tr("regional.tomorrow")65
} else {65
} else {66
day.format("%a, %b %-d").to_string()66
app_base::format::weekday_date_label(day)67
}67
}68
}68
}69
69
@@ -126,8 +126,6 @@ impl WorkHours {
126
126
pub struct CalendarPrefs {
127
127
pub default_view: DefaultView,
128
128
pub last_span: CalendarSpan,
129
/// `None` follows the regional format.
130
pub first_day: Option<Weekday>,
131
129
pub time_scale: TimeScale,
132
130
pub weekend_work_week: WeekendWorkWeek,
133
131
pub pane_hidden: bool,
@@ -143,14 +141,10 @@ impl CalendarPrefs {
143
141
self.default_view.span().unwrap_or(self.last_span)
144
142
}
145
143
146
pub fn first_day_or(&self, regional: Weekday) -> Weekday {
147
self.first_day.unwrap_or(regional)
148
}
149
150
/// Week layout for the grid; `regional` is the regional format's first day.
151
pub fn layout(&self, regional: Weekday) -> WeekLayout {
144
/// Week layout for the grid; the first day comes from the regional format.
145
pub fn layout(&self, first_day: Weekday) -> WeekLayout {
152
146
WeekLayout {
153
first_day: self.first_day_or(regional),
147
first_day,
154
148
work_days: self.work_hours.days.clone(),
155
149
weekend: self.weekend_work_week,
156
150
}
@@ -172,6 +166,12 @@ impl CalendarPrefs {
172
166
serde_json::from_str(text).unwrap_or_default()
173
167
}
174
168
169
/// The first day of week this record kept before it moved to the regional format.
170
pub fn legacy_first_day(json: &str) -> Option<Weekday> {
171
let value: serde_json::Value = serde_json::from_str(json).ok()?;
172
serde_json::from_value(value.get("first_day")?.clone()).ok()
173
}
174
175
175
pub fn to_json(&self) -> String {
176
176
serde_json::to_string(self).unwrap_or_default()
177
177
}
@@ -227,7 +227,6 @@ mod tests {
227
227
let store = Store::open_in_memory().unwrap();
228
228
let mut prefs = CalendarPrefs {
229
229
default_view: DefaultView::Month,
230
first_day: Some(Weekday::Sun),
231
230
time_scale: TimeScale::Min15,
232
231
pane_hidden: true,
233
232
..CalendarPrefs::default()
@@ -238,6 +237,20 @@ mod tests {
238
237
assert_eq!(load_calendar_prefs(&store), prefs);
239
238
}
240
239
240
#[test]
241
fn the_old_first_day_is_read_once_it_left_the_struct() {
242
let json = r#"{"default_view":"month","first_day":"Sun"}"#;
243
assert_eq!(CalendarPrefs::legacy_first_day(json), Some(Weekday::Sun));
244
assert_eq!(
245
CalendarPrefs::legacy_first_day(r#"{"first_day":null}"#),
246
None
247
);
248
assert_eq!(
249
CalendarPrefs::from_json(json).default_view,
250
DefaultView::Month
251
);
252
}
253
241
254
#[test]
242
255
fn missing_fields_take_defaults_and_broken_json_resets() {
243
256
let partial = CalendarPrefs::from_json(r#"{"default_view":"month"}"#);
@@ -126,8 +126,6 @@ impl WorkHours {126
pub struct CalendarPrefs {126
pub struct CalendarPrefs {127
pub default_view: DefaultView,127
pub default_view: DefaultView,128
pub last_span: CalendarSpan,128
pub last_span: CalendarSpan,129
/// `None` follows the regional format.130
pub first_day: Option<Weekday>,131
pub time_scale: TimeScale,129
pub time_scale: TimeScale,132
pub weekend_work_week: WeekendWorkWeek,130
pub weekend_work_week: WeekendWorkWeek,133
pub pane_hidden: bool,131
pub pane_hidden: bool,@@ -143,14 +141,10 @@ impl CalendarPrefs {143
self.default_view.span().unwrap_or(self.last_span)141
self.default_view.span().unwrap_or(self.last_span)144
}142
}145
143
146
pub fn first_day_or(&self, regional: Weekday) -> Weekday {144
/// Week layout for the grid; the first day comes from the regional format.147
self.first_day.unwrap_or(regional)145
pub fn layout(&self, first_day: Weekday) -> WeekLayout {148
}149
150
/// Week layout for the grid; `regional` is the regional format's first day.151
pub fn layout(&self, regional: Weekday) -> WeekLayout {152
WeekLayout {146
WeekLayout {153
first_day: self.first_day_or(regional),147
first_day,154
work_days: self.work_hours.days.clone(),148
work_days: self.work_hours.days.clone(),155
weekend: self.weekend_work_week,149
weekend: self.weekend_work_week,156
}150
}@@ -172,6 +166,12 @@ impl CalendarPrefs {172
serde_json::from_str(text).unwrap_or_default()166
serde_json::from_str(text).unwrap_or_default()173
}167
}174
168
169
/// The first day of week this record kept before it moved to the regional format.170
pub fn legacy_first_day(json: &str) -> Option<Weekday> {171
let value: serde_json::Value = serde_json::from_str(json).ok()?;172
serde_json::from_value(value.get("first_day")?.clone()).ok()173
}174
175
pub fn to_json(&self) -> String {175
pub fn to_json(&self) -> String {176
serde_json::to_string(self).unwrap_or_default()176
serde_json::to_string(self).unwrap_or_default()177
}177
}@@ -227,7 +227,6 @@ mod tests {227
let store = Store::open_in_memory().unwrap();227
let store = Store::open_in_memory().unwrap();228
let mut prefs = CalendarPrefs {228
let mut prefs = CalendarPrefs {229
default_view: DefaultView::Month,229
default_view: DefaultView::Month,230
first_day: Some(Weekday::Sun),231
time_scale: TimeScale::Min15,230
time_scale: TimeScale::Min15,232
pane_hidden: true,231
pane_hidden: true,233
..CalendarPrefs::default()232
..CalendarPrefs::default()@@ -238,6 +237,20 @@ mod tests {238
assert_eq!(load_calendar_prefs(&store), prefs);237
assert_eq!(load_calendar_prefs(&store), prefs);239
}238
}240
239
240
#[test]241
fn the_old_first_day_is_read_once_it_left_the_struct() {242
let json = r#"{"default_view":"month","first_day":"Sun"}"#;243
assert_eq!(CalendarPrefs::legacy_first_day(json), Some(Weekday::Sun));244
assert_eq!(245
CalendarPrefs::legacy_first_day(r#"{"first_day":null}"#),246
None247
);248
assert_eq!(249
CalendarPrefs::from_json(json).default_view,250
DefaultView::Month251
);252
}253
241
#[test]254
#[test]242
fn missing_fields_take_defaults_and_broken_json_resets() {255
fn missing_fields_take_defaults_and_broken_json_resets() {243
let partial = CalendarPrefs::from_json(r#"{"default_view":"month"}"#);256
let partial = CalendarPrefs::from_json(r#"{"default_view":"month"}"#);@@ -71,7 +71,10 @@ pub fn level_text(level: NetworkLevel) -> &'static str {
71
71
72
72
fn rate_text(kilobits_per_second: f64) -> String {
73
73
if kilobits_per_second >= 1000. {
74
format!("{:.1} Mbps", kilobits_per_second / 1000.)
74
format!(
75
"{} Mbps",
76
app_base::format::decimal_label(kilobits_per_second / 1000., 1)
77
)
75
78
} else {
76
79
format!("{kilobits_per_second:.0} kbps")
77
80
}
@@ -79,7 +82,13 @@ fn rate_text(kilobits_per_second: f64) -> String {
79
82
80
83
pub fn network_rows(sample: &HealthSample) -> Vec<(&'static str, String)> {
81
84
vec![
82
("Packet loss", format!("{:.1}%", sample.loss_percent)),
85
(
86
"Packet loss",
87
format!(
88
"{}%",
89
app_base::format::decimal_label(sample.loss_percent, 1)
90
),
91
),
83
92
("Round trip", format!("{:.0} ms", sample.round_trip_ms)),
84
93
("Jitter", format!("{:.0} ms", sample.jitter_ms)),
85
94
("Sent", rate_text(sample.sent_kbps)),
@@ -71,7 +71,10 @@ pub fn level_text(level: NetworkLevel) -> &'static str {71
71
72
fn rate_text(kilobits_per_second: f64) -> String {72
fn rate_text(kilobits_per_second: f64) -> String {73
if kilobits_per_second >= 1000. {73
if kilobits_per_second >= 1000. {74
format!("{:.1} Mbps", kilobits_per_second / 1000.)74
format!(75
"{} Mbps",76
app_base::format::decimal_label(kilobits_per_second / 1000., 1)77
)75
} else {78
} else {76
format!("{kilobits_per_second:.0} kbps")79
format!("{kilobits_per_second:.0} kbps")77
}80
}@@ -79,7 +82,13 @@ fn rate_text(kilobits_per_second: f64) -> String {79
82
80
pub fn network_rows(sample: &HealthSample) -> Vec<(&'static str, String)> {83
pub fn network_rows(sample: &HealthSample) -> Vec<(&'static str, String)> {81
vec![84
vec![82
("Packet loss", format!("{:.1}%", sample.loss_percent)),85
(86
"Packet loss",87
format!(88
"{}%",89
app_base::format::decimal_label(sample.loss_percent, 1)90
),91
),83
("Round trip", format!("{:.0} ms", sample.round_trip_ms)),92
("Round trip", format!("{:.0} ms", sample.round_trip_ms)),84
("Jitter", format!("{:.0} ms", sample.jitter_ms)),93
("Jitter", format!("{:.0} ms", sample.jitter_ms)),85
("Sent", rate_text(sample.sent_kbps)),94
("Sent", rate_text(sample.sent_kbps)),@@ -2,7 +2,7 @@ use std::collections::HashSet;
2
2
use std::path::{Path, PathBuf};
3
3
4
4
use agents::{DesktopSession, Environment, RunningSession};
5
use chrono::{DateTime, Local, Utc};
5
use chrono::{DateTime, Datelike, Local, Utc};
6
6
use mcp::install::{Homes, Location};
7
7
8
8
use super::message_context;
@@ -34,9 +34,10 @@ pub fn relative_age(now: DateTime<Utc>, then: DateTime<Utc>) -> String {
34
34
} else if age.num_days() < 1 {
35
35
format!("{}h", age.num_hours())
36
36
} else if age.num_days() < WEEK_DAYS {
37
then.with_timezone(&Local).format("%a").to_string()
37
let weekday = then.with_timezone(&Local).weekday();
38
crate::format::weekday_name(weekday, crate::format::WeekdayWidth::Short)
38
39
} else {
39
then.with_timezone(&Local).format("%b %-d").to_string()
40
crate::format::day_month_label(then.with_timezone(&Local).date_naive())
40
41
}
41
42
}
42
43
@@ -2,7 +2,7 @@ use std::collections::HashSet;2
use std::path::{Path, PathBuf};2
use std::path::{Path, PathBuf};3
3
4
use agents::{DesktopSession, Environment, RunningSession};4
use agents::{DesktopSession, Environment, RunningSession};5
use chrono::{DateTime, Local, Utc};5
use chrono::{DateTime, Datelike, Local, Utc};6
use mcp::install::{Homes, Location};6
use mcp::install::{Homes, Location};7
7
8
use super::message_context;8
use super::message_context;@@ -34,9 +34,10 @@ pub fn relative_age(now: DateTime<Utc>, then: DateTime<Utc>) -> String {34
} else if age.num_days() < 1 {34
} else if age.num_days() < 1 {35
format!("{}h", age.num_hours())35
format!("{}h", age.num_hours())36
} else if age.num_days() < WEEK_DAYS {36
} else if age.num_days() < WEEK_DAYS {37
then.with_timezone(&Local).format("%a").to_string()37
let weekday = then.with_timezone(&Local).weekday();38
crate::format::weekday_name(weekday, crate::format::WeekdayWidth::Short)38
} else {39
} else {39
then.with_timezone(&Local).format("%b %-d").to_string()40
crate::format::day_month_label(then.with_timezone(&Local).date_naive())40
}41
}41
}42
}42
43
@@ -225,6 +225,7 @@ pub struct AppState {
225
225
pub demo_meetings: Vec<chatsvc::CalendarEvent>,
226
226
pub calendar_week: crate::call::week::CalendarWeek,
227
227
pub calendar_prefs: crate::call::calendar_prefs::CalendarPrefs,
228
pub regional_prefs: crate::regional::RegionalPrefs,
228
229
/// Month the mini month shows after the user moved it; `None` follows the grid.
229
230
pub calendar_mini_month: Option<chrono::NaiveDate>,
230
231
/// Calendar list groups expanded with Show all (this session only).
@@ -296,6 +297,7 @@ impl AppState {
296
297
let actions_on_right_click =
297
298
crate::chat_settings_actions::stored_actions_on_right_click(&store);
298
299
let calendar_prefs = crate::call::calendar_prefs::load_calendar_prefs(&store);
300
let regional_prefs = crate::regional_format::load_regional_prefs(&store);
299
301
let mut state = AppState {
300
302
store,
301
303
engine: None,
@@ -404,6 +406,7 @@ impl AppState {
404
406
calendar_prefs.initial_span(),
405
407
),
406
408
calendar_prefs,
409
regional_prefs,
407
410
calendar_mini_month: None,
408
411
calendar_expanded_groups: Vec::new(),
409
412
mailbox_time_zone: None,
@@ -225,6 +225,7 @@ pub struct AppState {225
pub demo_meetings: Vec<chatsvc::CalendarEvent>,225
pub demo_meetings: Vec<chatsvc::CalendarEvent>,226
pub calendar_week: crate::call::week::CalendarWeek,226
pub calendar_week: crate::call::week::CalendarWeek,227
pub calendar_prefs: crate::call::calendar_prefs::CalendarPrefs,227
pub calendar_prefs: crate::call::calendar_prefs::CalendarPrefs,228
pub regional_prefs: crate::regional::RegionalPrefs,228
/// Month the mini month shows after the user moved it; `None` follows the grid.229
/// Month the mini month shows after the user moved it; `None` follows the grid.229
pub calendar_mini_month: Option<chrono::NaiveDate>,230
pub calendar_mini_month: Option<chrono::NaiveDate>,230
/// Calendar list groups expanded with Show all (this session only).231
/// Calendar list groups expanded with Show all (this session only).@@ -296,6 +297,7 @@ impl AppState {296
let actions_on_right_click =297
let actions_on_right_click =297
crate::chat_settings_actions::stored_actions_on_right_click(&store);298
crate::chat_settings_actions::stored_actions_on_right_click(&store);298
let calendar_prefs = crate::call::calendar_prefs::load_calendar_prefs(&store);299
let calendar_prefs = crate::call::calendar_prefs::load_calendar_prefs(&store);300
let regional_prefs = crate::regional_format::load_regional_prefs(&store);299
let mut state = AppState {301
let mut state = AppState {300
store,302
store,301
engine: None,303
engine: None,@@ -404,6 +406,7 @@ impl AppState {404
calendar_prefs.initial_span(),406
calendar_prefs.initial_span(),405
),407
),406
calendar_prefs,408
calendar_prefs,409
regional_prefs,407
calendar_mini_month: None,410
calendar_mini_month: None,408
calendar_expanded_groups: Vec::new(),411
calendar_expanded_groups: Vec::new(),409
mailbox_time_zone: None,412
mailbox_time_zone: None,@@ -14,16 +14,21 @@ impl AppState {
14
14
change: impl FnOnce(&mut CalendarPrefs),
15
15
cx: &mut Context<Self>,
16
16
) {
17
let anchor = self.calendar_week.start;
18
17
change(&mut self.calendar_prefs);
19
18
save_calendar_prefs(&self.store, &self.calendar_prefs);
20
if let Some(anchor) = anchor {
21
// Week start or work days may have moved: re-anchor on the same date.
19
// The mailbox language can move the first day of week.
20
self.apply_regional_format();
21
self.reanchor_calendar(cx);
22
cx.notify();
23
}
24
25
/// Week start or work days may have moved: show the range that holds the same date.
26
pub(crate) fn reanchor_calendar(&mut self, cx: &mut Context<Self>) {
27
if let Some(anchor) = self.calendar_week.start {
22
28
self.calendar_week.start = Some(self.calendar_span_start(anchor));
23
29
self.request_calendar_scroll_to_now(cx);
24
30
self.load_calendar_week(cx);
25
31
}
26
cx.notify();
27
32
}
28
33
29
34
/// Read the mailbox work hours once the session is there and cache them.
@@ -142,7 +147,11 @@ mod tests {
142
147
state
143
148
.update_calendar_prefs(|prefs| prefs.mailbox_locale = Some("en-CH".into()), cx);
144
149
assert_eq!(state.calendar_layout().first_day, Weekday::Mon);
145
state.update_calendar_prefs(|prefs| prefs.first_day = Some(Weekday::Sat), cx);
150
let prefs = crate::regional::RegionalPrefs {
151
first_day: Some(Weekday::Sat),
152
..state.regional_prefs
153
};
154
state.set_regional_prefs(prefs, cx);
146
155
assert_eq!(state.calendar_layout().first_day, Weekday::Sat);
147
156
})
148
157
});
@@ -14,16 +14,21 @@ impl AppState {14
change: impl FnOnce(&mut CalendarPrefs),14
change: impl FnOnce(&mut CalendarPrefs),15
cx: &mut Context<Self>,15
cx: &mut Context<Self>,16
) {16
) {17
let anchor = self.calendar_week.start;18
change(&mut self.calendar_prefs);17
change(&mut self.calendar_prefs);19
save_calendar_prefs(&self.store, &self.calendar_prefs);18
save_calendar_prefs(&self.store, &self.calendar_prefs);20
if let Some(anchor) = anchor {19
// The mailbox language can move the first day of week.21
// Week start or work days may have moved: re-anchor on the same date.20
self.apply_regional_format();21
self.reanchor_calendar(cx);22
cx.notify();23
}24
25
/// Week start or work days may have moved: show the range that holds the same date.26
pub(crate) fn reanchor_calendar(&mut self, cx: &mut Context<Self>) {27
if let Some(anchor) = self.calendar_week.start {22
self.calendar_week.start = Some(self.calendar_span_start(anchor));28
self.calendar_week.start = Some(self.calendar_span_start(anchor));23
self.request_calendar_scroll_to_now(cx);29
self.request_calendar_scroll_to_now(cx);24
self.load_calendar_week(cx);30
self.load_calendar_week(cx);25
}31
}26
cx.notify();27
}32
}28
33
29
/// Read the mailbox work hours once the session is there and cache them.34
/// Read the mailbox work hours once the session is there and cache them.@@ -142,7 +147,11 @@ mod tests {142
state147
state143
.update_calendar_prefs(|prefs| prefs.mailbox_locale = Some("en-CH".into()), cx);148
.update_calendar_prefs(|prefs| prefs.mailbox_locale = Some("en-CH".into()), cx);144
assert_eq!(state.calendar_layout().first_day, Weekday::Mon);149
assert_eq!(state.calendar_layout().first_day, Weekday::Mon);145
state.update_calendar_prefs(|prefs| prefs.first_day = Some(Weekday::Sat), cx);150
let prefs = crate::regional::RegionalPrefs {151
first_day: Some(Weekday::Sat),152
..state.regional_prefs153
};154
state.set_regional_prefs(prefs, cx);146
assert_eq!(state.calendar_layout().first_day, Weekday::Sat);155
assert_eq!(state.calendar_layout().first_day, Weekday::Sat);147
})156
})148
});157
});@@ -51,19 +51,10 @@ impl CalendarWeek {
51
51
}
52
52
53
53
impl AppState {
54
/// Week layout from the calendar settings and the regional first day.
54
/// Week layout from the calendar settings and the regional format's first day.
55
55
pub fn calendar_layout(&self) -> WeekLayout {
56
self.calendar_prefs.layout(self.default_first_day())
57
}
58
59
/// First day of week without an override: the mailbox language's region, as in
60
/// Outlook and Teams, else the regional format.
61
pub fn default_first_day(&self) -> Weekday {
62
56
self.calendar_prefs
63
.mailbox_locale
64
.as_deref()
65
.map(app_base::format::first_day_for_locale)
66
.unwrap_or_else(app_base::format::regional_first_day)
57
.layout(app_base::format::regional_first_day())
67
58
}
68
59
69
60
pub fn calendar_start(&self) -> NaiveDate {
@@ -51,19 +51,10 @@ impl CalendarWeek {51
}51
}52
52
53
impl AppState {53
impl AppState {54
/// Week layout from the calendar settings and the regional first day.54
/// Week layout from the calendar settings and the regional format's first day.55
pub fn calendar_layout(&self) -> WeekLayout {55
pub fn calendar_layout(&self) -> WeekLayout {56
self.calendar_prefs.layout(self.default_first_day())57
}58
59
/// First day of week without an override: the mailbox language's region, as in60
/// Outlook and Teams, else the regional format.61
pub fn default_first_day(&self) -> Weekday {62
self.calendar_prefs56
self.calendar_prefs63
.mailbox_locale57
.layout(app_base::format::regional_first_day())64
.as_deref()65
.map(app_base::format::first_day_for_locale)66
.unwrap_or_else(app_base::format::regional_first_day)67
}58
}68
59
69
pub fn calendar_start(&self) -> NaiveDate {60
pub fn calendar_start(&self) -> NaiveDate {@@ -1,7 +1,7 @@
1
1
use std::collections::{HashMap, HashSet};
2
2
3
3
use app_base::format::Zone;
4
use chrono::{DateTime, NaiveDate, Utc};
4
use chrono::{DateTime, Datelike, FixedOffset, NaiveDate, Utc};
5
5
use store::MessageRecord;
6
6
use teams_core::roster_event::RosterEvent;
7
7
use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};
@@ -10,7 +10,6 @@ use crate::format;
10
10
11
11
const MAX_AVATARS: usize = 4;
12
12
const RECAP_FALLBACK_TITLE: &str = "Meeting";
13
const RECAP_DATE_FORMAT: &str = "%A, %-d %B %Y";
14
13
const AUTO_STOP_SECONDS: i64 = 5;
15
14
const WEEKDAY_STAMP_DAYS: i64 = 6;
16
15
const OWN_NAME: &str = "You";
@@ -323,10 +322,7 @@ fn recap_date_line(
323
322
});
324
323
format!(
325
324
"{} - {}",
326
clock.offset.at(slot.start).format(&format!(
327
"{RECAP_DATE_FORMAT} {}",
328
app_base::format::clock_format()
329
)),
325
recap_start_label(clock.offset.at(slot.start)),
330
326
clock
331
327
.offset
332
328
.at(slot.end)
@@ -334,6 +330,16 @@ fn recap_date_line(
334
330
)
335
331
}
336
332
333
/// "Thursday, 16. November 2026 14:30" in the app language and regional format.
334
fn recap_start_label(start: DateTime<FixedOffset>) -> String {
335
format!(
336
"{}, {} {}",
337
format::weekday_name(start.weekday(), format::WeekdayWidth::Full),
338
format::long_date_label(start.date_naive()),
339
start.format(format::clock_format())
340
)
341
}
342
337
343
/// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.
338
344
fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
339
345
let local = clock.offset.at(time);
@@ -341,7 +347,7 @@ fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
341
347
if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {
342
348
format!(
343
349
"{} {}",
344
local.format("%A"),
350
format::weekday_name(local.weekday(), format::WeekdayWidth::Full),
345
351
local.format(app_base::format::clock_format())
346
352
)
347
353
} else {
@@ -723,6 +729,8 @@ mod tests {
723
729
724
730
#[test]
725
731
fn recap_date_prefers_the_calendar_occurrence() {
732
// Day first, as the regional format of the United Kingdom writes it.
733
format::set_date_locale(Some("en-GB"));
726
734
let started_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 46, 0).unwrap();
727
735
let ended_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 55, 0).unwrap();
728
736
let mut meeting = MeetingInfo::default();
@@ -1,7 +1,7 @@1
use std::collections::{HashMap, HashSet};1
use std::collections::{HashMap, HashSet};2
2
3
use app_base::format::Zone;3
use app_base::format::Zone;4
use chrono::{DateTime, NaiveDate, Utc};4
use chrono::{DateTime, Datelike, FixedOffset, NaiveDate, Utc};5
use store::MessageRecord;5
use store::MessageRecord;6
use teams_core::roster_event::RosterEvent;6
use teams_core::roster_event::RosterEvent;7
use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};7
use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};@@ -10,7 +10,6 @@ use crate::format;10
10
11
const MAX_AVATARS: usize = 4;11
const MAX_AVATARS: usize = 4;12
const RECAP_FALLBACK_TITLE: &str = "Meeting";12
const RECAP_FALLBACK_TITLE: &str = "Meeting";13
const RECAP_DATE_FORMAT: &str = "%A, %-d %B %Y";14
const AUTO_STOP_SECONDS: i64 = 5;13
const AUTO_STOP_SECONDS: i64 = 5;15
const WEEKDAY_STAMP_DAYS: i64 = 6;14
const WEEKDAY_STAMP_DAYS: i64 = 6;16
const OWN_NAME: &str = "You";15
const OWN_NAME: &str = "You";@@ -323,10 +322,7 @@ fn recap_date_line(323
});322
});324
format!(323
format!(325
"{} - {}",324
"{} - {}",326
clock.offset.at(slot.start).format(&format!(325
recap_start_label(clock.offset.at(slot.start)),327
"{RECAP_DATE_FORMAT} {}",328
app_base::format::clock_format()329
)),330
clock326
clock331
.offset327
.offset332
.at(slot.end)328
.at(slot.end)@@ -334,6 +330,16 @@ fn recap_date_line(334
)330
)335
}331
}336
332
333
/// "Thursday, 16. November 2026 14:30" in the app language and regional format.334
fn recap_start_label(start: DateTime<FixedOffset>) -> String {335
format!(336
"{}, {} {}",337
format::weekday_name(start.weekday(), format::WeekdayWidth::Full),338
format::long_date_label(start.date_naive()),339
start.format(format::clock_format())340
)341
}342
337
/// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.343
/// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.338
fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {344
fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {339
let local = clock.offset.at(time);345
let local = clock.offset.at(time);@@ -341,7 +347,7 @@ fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {341
if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {347
if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {342
format!(348
format!(343
"{} {}",349
"{} {}",344
local.format("%A"),350
format::weekday_name(local.weekday(), format::WeekdayWidth::Full),345
local.format(app_base::format::clock_format())351
local.format(app_base::format::clock_format())346
)352
)347
} else {353
} else {@@ -723,6 +729,8 @@ mod tests {723
729
724
#[test]730
#[test]725
fn recap_date_prefers_the_calendar_occurrence() {731
fn recap_date_prefers_the_calendar_occurrence() {732
// Day first, as the regional format of the United Kingdom writes it.733
format::set_date_locale(Some("en-GB"));726
let started_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 46, 0).unwrap();734
let started_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 46, 0).unwrap();727
let ended_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 55, 0).unwrap();735
let ended_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 55, 0).unwrap();728
let mut meeting = MeetingInfo::default();736
let mut meeting = MeetingInfo::default();@@ -1002,7 +1002,7 @@ pub fn seed_directory(state: &mut AppState) {
1002
1002
state.own_email = DEMO_USER_EMAIL.to_owned();
1003
1003
state.own_time_zone = Some(DEMO_TIME_ZONE.to_owned());
1004
1004
state.translation.settings = Some(language_settings());
1005
state.apply_date_locale();
1005
state.apply_regional_format();
1006
1006
state.translation.languages = language_list();
1007
1007
let directory = &mut state.directory;
1008
1008
directory.me = Some(Person {
@@ -1002,7 +1002,7 @@ pub fn seed_directory(state: &mut AppState) {1002
state.own_email = DEMO_USER_EMAIL.to_owned();1002
state.own_email = DEMO_USER_EMAIL.to_owned();1003
state.own_time_zone = Some(DEMO_TIME_ZONE.to_owned());1003
state.own_time_zone = Some(DEMO_TIME_ZONE.to_owned());1004
state.translation.settings = Some(language_settings());1004
state.translation.settings = Some(language_settings());1005
state.apply_date_locale();1005
state.apply_regional_format();1006
state.translation.languages = language_list();1006
state.translation.languages = language_list();1007
let directory = &mut state.directory;1007
let directory = &mut state.directory;1008
directory.me = Some(Person {1008
directory.me = Some(Person {@@ -250,7 +250,7 @@ pub fn month_label(date: NaiveDate, today: NaiveDate) -> String {
250
250
match months(today) - months(date) {
251
251
0 => THIS_MONTH.to_owned(),
252
252
1 => LAST_MONTH.to_owned(),
253
_ => date.format("%B %Y").to_string(),
253
_ => crate::format::month_year_label(date),
254
254
}
255
255
}
256
256
@@ -250,7 +250,7 @@ pub fn month_label(date: NaiveDate, today: NaiveDate) -> String {250
match months(today) - months(date) {250
match months(today) - months(date) {251
0 => THIS_MONTH.to_owned(),251
0 => THIS_MONTH.to_owned(),252
1 => LAST_MONTH.to_owned(),252
1 => LAST_MONTH.to_owned(),253
_ => date.format("%B %Y").to_string(),253
_ => crate::format::month_year_label(date),254
}254
}255
}255
}256
256
@@ -51,6 +51,7 @@ pub mod presence_follow;
51
51
pub mod profile_model;
52
52
pub mod profile_state;
53
53
pub mod reaction_model;
54
pub mod regional_format;
54
55
pub mod restorable_deletes;
55
56
pub mod rows;
56
57
pub mod scheduled;
@@ -75,7 +76,7 @@ pub use app_base::{
75
76
APP_NAME, appearance, autostart, avatar_image, channel_files, crash_log, demo_cards,
76
77
demo_chart_cards, demo_gifs, demo_input_cards, demo_library, demo_recap, diagnostics,
77
78
downloads, emoticons, format, frame_log, fuzzy, image_clipboard, image_view_math, inline_image,
78
presence_link, read_state, recap, remote_image, runtime, schedule_time, single_instance,
79
stickers, support, theme, translation, updater, user_activity, zoom,
79
presence_link, read_state, recap, regional, remote_image, runtime, schedule_time,
80
single_instance, stickers, support, theme, translation, updater, user_activity, zoom,
80
81
};
81
82
pub use app_ui_kit::render;
@@ -51,6 +51,7 @@ pub mod presence_follow;51
pub mod profile_model;51
pub mod profile_model;52
pub mod profile_state;52
pub mod profile_state;53
pub mod reaction_model;53
pub mod reaction_model;54
pub mod regional_format;54
pub mod restorable_deletes;55
pub mod restorable_deletes;55
pub mod rows;56
pub mod rows;56
pub mod scheduled;57
pub mod scheduled;@@ -75,7 +76,7 @@ pub use app_base::{75
APP_NAME, appearance, autostart, avatar_image, channel_files, crash_log, demo_cards,76
APP_NAME, appearance, autostart, avatar_image, channel_files, crash_log, demo_cards,76
demo_chart_cards, demo_gifs, demo_input_cards, demo_library, demo_recap, diagnostics,77
demo_chart_cards, demo_gifs, demo_input_cards, demo_library, demo_recap, diagnostics,77
downloads, emoticons, format, frame_log, fuzzy, image_clipboard, image_view_math, inline_image,78
downloads, emoticons, format, frame_log, fuzzy, image_clipboard, image_view_math, inline_image,78
presence_link, read_state, recap, remote_image, runtime, schedule_time, single_instance,79
presence_link, read_state, recap, regional, remote_image, runtime, schedule_time,79
stickers, support, theme, translation, updater, user_activity, zoom,80
single_instance, stickers, support, theme, translation, updater, user_activity, zoom,80
};81
};81
pub use app_ui_kit::render;82
pub use app_ui_kit::render;@@ -5,7 +5,7 @@ pub use app_base::status_choice::{
5
5
STATUS_CHOICES, STATUS_DURATIONS, StatusDuration, choice_label, end_of_day, end_of_week,
6
6
state_label,
7
7
};
8
use chrono::{DateTime, Duration, TimeZone, Utc};
8
use chrono::{DateTime, Datelike, Duration, TimeZone, Utc};
9
9
use gpui_kit::*;
10
10
use teams_core::{
11
11
ForcedAvailability, ForcedKind, PresenceStatus, StatusNote, WorkLocation, WorkLocationKind,
@@ -74,15 +74,15 @@ where
74
74
Zone::Offset: std::fmt::Display,
75
75
{
76
76
let local = expires_at.with_timezone(&now.timezone());
77
if local.date_naive() == now.date_naive() {
78
format!("until {}", local.format(app_base::format::clock_format()))
77
let clock = local.format(app_base::format::clock_format()).to_string();
78
let time = if local.date_naive() == now.date_naive() {
79
clock
79
80
} else {
80
format!(
81
"until {} {}",
82
local.format("%a"),
83
local.format(app_base::format::clock_format())
84
)
85
}
81
let weekday =
82
app_base::format::weekday_name(local.weekday(), app_base::format::WeekdayWidth::Short);
83
format!("{weekday} {clock}")
84
};
85
app_base::ui_locale::tr_with("regional.until", &[("time", &time)])
86
86
}
87
87
88
88
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -5,7 +5,7 @@ pub use app_base::status_choice::{5
STATUS_CHOICES, STATUS_DURATIONS, StatusDuration, choice_label, end_of_day, end_of_week,5
STATUS_CHOICES, STATUS_DURATIONS, StatusDuration, choice_label, end_of_day, end_of_week,6
state_label,6
state_label,7
};7
};8
use chrono::{DateTime, Duration, TimeZone, Utc};8
use chrono::{DateTime, Datelike, Duration, TimeZone, Utc};9
use gpui_kit::*;9
use gpui_kit::*;10
use teams_core::{10
use teams_core::{11
ForcedAvailability, ForcedKind, PresenceStatus, StatusNote, WorkLocation, WorkLocationKind,11
ForcedAvailability, ForcedKind, PresenceStatus, StatusNote, WorkLocation, WorkLocationKind,@@ -74,15 +74,15 @@ where74
Zone::Offset: std::fmt::Display,74
Zone::Offset: std::fmt::Display,75
{75
{76
let local = expires_at.with_timezone(&now.timezone());76
let local = expires_at.with_timezone(&now.timezone());77
if local.date_naive() == now.date_naive() {77
let clock = local.format(app_base::format::clock_format()).to_string();78
format!("until {}", local.format(app_base::format::clock_format()))78
let time = if local.date_naive() == now.date_naive() {79
clock79
} else {80
} else {80
format!(81
let weekday =81
"until {} {}",82
app_base::format::weekday_name(local.weekday(), app_base::format::WeekdayWidth::Short);82
local.format("%a"),83
format!("{weekday} {clock}")83
local.format(app_base::format::clock_format())84
};84
)85
app_base::ui_locale::tr_with("regional.until", &[("time", &time)])85
}86
}86
}87
87
88
#[derive(Debug, Clone, PartialEq, Eq)]88
#[derive(Debug, Clone, PartialEq, Eq)]@@ -1,5 +1,6 @@
1
1
use std::fmt::Display;
2
2
3
use app_base::ui_locale::tr_with;
3
4
use chrono::{DateTime, Datelike, TimeZone, Utc};
4
5
5
6
use crate::rows::ReactionChip;
@@ -67,15 +68,19 @@ where
67
68
let local = time.with_timezone(&now.timezone());
68
69
let day = local.date_naive();
69
70
let today = now.date_naive();
70
let clock = local.format(app_base::format::clock_format());
71
let clock = local.format(app_base::format::clock_format()).to_string();
72
let clock = ("clock", clock.as_str());
71
73
if day == today {
72
format!("today at {clock}")
74
tr_with("regional.today_at", &[clock])
73
75
} else if today.pred_opt() == Some(day) {
74
format!("yesterday at {clock}")
75
} else if day.year() == today.year() {
76
format!("{} at {clock}", local.format("%b %-d"))
76
tr_with("regional.yesterday_at", &[clock])
77
77
} else {
78
format!("{} at {clock}", local.format("%b %-d, %Y"))
78
let date = if day.year() == today.year() {
79
app_base::format::day_month_label(day)
80
} else {
81
app_base::format::date_label(day)
82
};
83
tr_with("regional.date_at", &[("date", &date), clock])
79
84
}
80
85
}
81
86
@@ -1,5 +1,6 @@1
use std::fmt::Display;1
use std::fmt::Display;2
2
3
use app_base::ui_locale::tr_with;3
use chrono::{DateTime, Datelike, TimeZone, Utc};4
use chrono::{DateTime, Datelike, TimeZone, Utc};4
5
5
use crate::rows::ReactionChip;6
use crate::rows::ReactionChip;@@ -67,15 +68,19 @@ where67
let local = time.with_timezone(&now.timezone());68
let local = time.with_timezone(&now.timezone());68
let day = local.date_naive();69
let day = local.date_naive();69
let today = now.date_naive();70
let today = now.date_naive();70
let clock = local.format(app_base::format::clock_format());71
let clock = local.format(app_base::format::clock_format()).to_string();72
let clock = ("clock", clock.as_str());71
if day == today {73
if day == today {72
format!("today at {clock}")74
tr_with("regional.today_at", &[clock])73
} else if today.pred_opt() == Some(day) {75
} else if today.pred_opt() == Some(day) {74
format!("yesterday at {clock}")76
tr_with("regional.yesterday_at", &[clock])75
} else if day.year() == today.year() {76
format!("{} at {clock}", local.format("%b %-d"))77
} else {77
} else {78
format!("{} at {clock}", local.format("%b %-d, %Y"))78
let date = if day.year() == today.year() {79
app_base::format::day_month_label(day)80
} else {81
app_base::format::date_label(day)82
};83
tr_with("regional.date_at", &[("date", &date), clock])79
}84
}80
}85
}81
86
@@ -0,0 +1,84 @@
1
//! Regional format on `AppState`: the saved choice and the date style every label reads.
2
3
use app_base::regional::{self, FormatSources, RegionalPrefs, SystemFormat};
4
use gpui_kit::Context;
5
use store::Store;
6
7
use crate::app_state::AppState;
8
use crate::call::calendar_prefs::{CALENDAR_PREFS_KEY, CalendarPrefs};
9
use crate::format::{self, DateStyle};
10
11
/// The saved choice. Before the first save, a first day set in the calendar settings carries over.
12
pub(crate) fn load_regional_prefs(store: &Store) -> RegionalPrefs {
13
if let Some(prefs) = regional::load(store) {
14
return prefs;
15
}
16
let first_day = store
17
.meta(CALENDAR_PREFS_KEY)
18
.ok()
19
.flatten()
20
.as_deref()
21
.and_then(CalendarPrefs::legacy_first_day);
22
let prefs = RegionalPrefs {
23
first_day,
24
..RegionalPrefs::default()
25
};
26
if first_day.is_some() {
27
regional::save(store, &prefs);
28
}
29
prefs
30
}
31
32
impl AppState {
33
/// The style `prefs` resolve to with the OS, account and mailbox as they are now.
34
pub fn regional_style(&self, prefs: &RegionalPrefs, system: &SystemFormat) -> DateStyle {
35
let display_locale = self
36
.translation
37
.settings
38
.as_ref()
39
.and_then(|settings| settings.display_locale.as_deref());
40
regional::resolve(
41
prefs,
42
FormatSources {
43
system,
44
display_locale,
45
mailbox_locale: self.calendar_prefs.mailbox_locale.as_deref(),
46
},
47
)
48
}
49
50
/// Set the date style that labels read; call after any of its sources changed.
51
pub fn apply_regional_format(&self) {
52
let style = self.regional_style(&self.regional_prefs, &SystemFormat::read());
53
format::set_date_style(Some(style));
54
}
55
56
pub fn set_regional_prefs(&mut self, prefs: RegionalPrefs, cx: &mut Context<Self>) {
57
if prefs == self.regional_prefs {
58
return;
59
}
60
self.regional_prefs = prefs;
61
regional::save(&self.store, &prefs);
62
self.apply_regional_format();
63
self.reanchor_calendar(cx);
64
cx.notify();
65
}
66
}
67
68
#[cfg(test)]
69
mod tests {
70
use chrono::Weekday;
71
72
use super::*;
73
74
#[test]
75
fn the_calendar_first_day_carries_over_once() {
76
let store = Store::open_in_memory().unwrap();
77
store
78
.set_meta(CALENDAR_PREFS_KEY, r#"{"first_day":"Sat"}"#)
79
.unwrap();
80
assert_eq!(load_regional_prefs(&store).first_day, Some(Weekday::Sat));
81
store.set_meta(CALENDAR_PREFS_KEY, "{}").unwrap();
82
assert_eq!(load_regional_prefs(&store).first_day, Some(Weekday::Sat));
83
}
84
}
@@ -0,0 +1,84 @@1
//! Regional format on `AppState`: the saved choice and the date style every label reads.2
3
use app_base::regional::{self, FormatSources, RegionalPrefs, SystemFormat};4
use gpui_kit::Context;5
use store::Store;6
7
use crate::app_state::AppState;8
use crate::call::calendar_prefs::{CALENDAR_PREFS_KEY, CalendarPrefs};9
use crate::format::{self, DateStyle};10
11
/// The saved choice. Before the first save, a first day set in the calendar settings carries over.12
pub(crate) fn load_regional_prefs(store: &Store) -> RegionalPrefs {13
if let Some(prefs) = regional::load(store) {14
return prefs;15
}16
let first_day = store17
.meta(CALENDAR_PREFS_KEY)18
.ok()19
.flatten()20
.as_deref()21
.and_then(CalendarPrefs::legacy_first_day);22
let prefs = RegionalPrefs {23
first_day,24
..RegionalPrefs::default()25
};26
if first_day.is_some() {27
regional::save(store, &prefs);28
}29
prefs30
}31
32
impl AppState {33
/// The style `prefs` resolve to with the OS, account and mailbox as they are now.34
pub fn regional_style(&self, prefs: &RegionalPrefs, system: &SystemFormat) -> DateStyle {35
let display_locale = self36
.translation37
.settings38
.as_ref()39
.and_then(|settings| settings.display_locale.as_deref());40
regional::resolve(41
prefs,42
FormatSources {43
system,44
display_locale,45
mailbox_locale: self.calendar_prefs.mailbox_locale.as_deref(),46
},47
)48
}49
50
/// Set the date style that labels read; call after any of its sources changed.51
pub fn apply_regional_format(&self) {52
let style = self.regional_style(&self.regional_prefs, &SystemFormat::read());53
format::set_date_style(Some(style));54
}55
56
pub fn set_regional_prefs(&mut self, prefs: RegionalPrefs, cx: &mut Context<Self>) {57
if prefs == self.regional_prefs {58
return;59
}60
self.regional_prefs = prefs;61
regional::save(&self.store, &prefs);62
self.apply_regional_format();63
self.reanchor_calendar(cx);64
cx.notify();65
}66
}67
68
#[cfg(test)]69
mod tests {70
use chrono::Weekday;71
72
use super::*;73
74
#[test]75
fn the_calendar_first_day_carries_over_once() {76
let store = Store::open_in_memory().unwrap();77
store78
.set_meta(CALENDAR_PREFS_KEY, r#"{"first_day":"Sat"}"#)79
.unwrap();80
assert_eq!(load_regional_prefs(&store).first_day, Some(Weekday::Sat));81
store.set_meta(CALENDAR_PREFS_KEY, "{}").unwrap();82
assert_eq!(load_regional_prefs(&store).first_day, Some(Weekday::Sat));83
}84
}@@ -27,16 +27,6 @@ const META_USER_ID: &str = "me_user_id";
27
27
type TranslationOutcome = Result<Vec<Translation>, String>;
28
28
29
29
impl AppState {
30
pub fn apply_date_locale(&self) {
31
let regional = crate::format::os_regional_locale();
32
let display = self
33
.translation
34
.settings
35
.as_ref()
36
.and_then(|settings| settings.display_locale.as_deref());
37
crate::format::set_date_locale(regional.as_deref().or(display));
38
}
39
40
30
pub fn load_cached_translation_settings(&mut self) {
41
31
self.translation.settings = self
42
32
.store
@@ -45,7 +35,7 @@ impl AppState {
45
35
.flatten()
46
36
.and_then(|text| serde_json::from_str::<Value>(&text).ok())
47
37
.and_then(|value| parse_language_settings(&value).ok());
48
self.apply_date_locale();
38
self.apply_regional_format();
49
39
self.translation.languages = self
50
40
.store
51
41
.meta(LANGUAGES_META_KEY)
@@ -130,7 +120,7 @@ impl AppState {
130
120
this.update(cx, |state, cx| {
131
121
if let Ok(settings) = settings {
132
122
state.translation.settings = Some(settings);
133
state.apply_date_locale();
123
state.apply_regional_format();
134
124
state.save_translation_settings();
135
125
}
136
126
if let Some(languages) = languages.filter(|languages| !languages.is_empty()) {
@@ -27,16 +27,6 @@ const META_USER_ID: &str = "me_user_id";27
type TranslationOutcome = Result<Vec<Translation>, String>;27
type TranslationOutcome = Result<Vec<Translation>, String>;28
28
29
impl AppState {29
impl AppState {30
pub fn apply_date_locale(&self) {31
let regional = crate::format::os_regional_locale();32
let display = self33
.translation34
.settings35
.as_ref()36
.and_then(|settings| settings.display_locale.as_deref());37
crate::format::set_date_locale(regional.as_deref().or(display));38
}39
40
pub fn load_cached_translation_settings(&mut self) {30
pub fn load_cached_translation_settings(&mut self) {41
self.translation.settings = self31
self.translation.settings = self42
.store32
.store@@ -45,7 +35,7 @@ impl AppState {45
.flatten()35
.flatten()46
.and_then(|text| serde_json::from_str::<Value>(&text).ok())36
.and_then(|text| serde_json::from_str::<Value>(&text).ok())47
.and_then(|value| parse_language_settings(&value).ok());37
.and_then(|value| parse_language_settings(&value).ok());48
self.apply_date_locale();38
self.apply_regional_format();49
self.translation.languages = self39
self.translation.languages = self50
.store40
.store51
.meta(LANGUAGES_META_KEY)41
.meta(LANGUAGES_META_KEY)@@ -130,7 +120,7 @@ impl AppState {130
this.update(cx, |state, cx| {120
this.update(cx, |state, cx| {131
if let Ok(settings) = settings {121
if let Ok(settings) = settings {132
state.translation.settings = Some(settings);122
state.translation.settings = Some(settings);133
state.apply_date_locale();123
state.apply_regional_format();134
state.save_translation_settings();124
state.save_translation_settings();135
}125
}136
if let Some(languages) = languages.filter(|languages| !languages.is_empty()) {126
if let Some(languages) = languages.filter(|languages| !languages.is_empty()) {@@ -105,6 +105,8 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
105
105
language_choices,
106
106
),
107
107
))
108
.child(caption(tr("settings.caption.regional_format")))
109
.children(super::regional::rows(app, cx))
108
110
.child(caption(tr("settings.caption.theme")))
109
111
.child(control_row(
110
112
tr("settings.appearance.theme"),
@@ -105,6 +105,8 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {105
language_choices,105
language_choices,106
),106
),107
))107
))108
.child(caption(tr("settings.caption.regional_format")))109
.children(super::regional::rows(app, cx))108
.child(caption(tr("settings.caption.theme")))110
.child(caption(tr("settings.caption.theme")))109
.child(control_row(111
.child(control_row(110
tr("settings.appearance.theme"),112
tr("settings.appearance.theme"),@@ -25,7 +25,11 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
25
25
let mut body = v_flex()
26
26
.w_full()
27
27
.child(caption(tr("settings.calendar.section_view")))
28
.children(view_rows(app, &prefs, app.read(cx).default_first_day()))
28
.children(view_rows(
29
app,
30
&prefs,
31
app.read(cx).calendar_layout().first_day,
32
))
29
33
.child(caption(tr("settings.calendar.section_google")))
30
34
.child(connect_row(app, accounts.has_google(), pending));
31
35
for account in &accounts.google_accounts {
@@ -247,16 +251,11 @@ fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> D
247
251
choices
248
252
}
249
253
250
const FIRST_DAY_CHOICES: [Weekday; 3] = [Weekday::Mon, Weekday::Sun, Weekday::Sat];
251
254
const CHIP_SIZE: f32 = 32.;
252
255
const TIME_SELECT_WIDTH: f32 = 104.;
253
256
254
/// Default view, first day, work days and hours, time scale, weekend Work week.
255
fn view_rows(
256
app: &Entity<AppState>,
257
prefs: &CalendarPrefs,
258
default_first_day: Weekday,
259
) -> Vec<Div> {
257
/// Default view, work days and hours, time scale, weekend Work week.
258
fn view_rows(app: &Entity<AppState>, prefs: &CalendarPrefs, first_day: Weekday) -> Vec<Div> {
260
259
vec![
261
260
control_row(
262
261
tr("settings.calendar.default_view"),
@@ -278,30 +277,10 @@ fn view_rows(
278
277
.collect(),
279
278
),
280
279
),
281
control_row(
282
tr("settings.calendar.first_day"),
283
tr("settings.calendar.first_day_detail"),
284
select(
285
"settings-calendar-first-day",
286
first_day_label(prefs.first_day, default_first_day),
287
false,
288
std::iter::once(None)
289
.chain(FIRST_DAY_CHOICES.into_iter().map(Some))
290
.map(|day| {
291
prefs_choice(
292
app,
293
first_day_label(day, default_first_day),
294
prefs.first_day == day,
295
move |prefs| prefs.first_day = day,
296
)
297
})
298
.collect(),
299
),
300
),
301
280
control_row(
302
281
tr("settings.calendar.work_days"),
303
282
tr("settings.calendar.mailbox_detail"),
304
work_day_chips(app, prefs, default_first_day),
283
work_day_chips(app, prefs, first_day),
305
284
),
306
285
control_row(
307
286
tr("settings.calendar.work_hours"),
@@ -375,20 +354,6 @@ fn default_view_label(view: DefaultView) -> String {
375
354
.map_or_else(|| tr("settings.calendar.last_used"), |span| span.label())
376
355
}
377
356
378
fn first_day_label(day: Option<Weekday>, default_first_day: Weekday) -> String {
379
match day {
380
Some(day) => weekday_name(day, WeekdayWidth::Full),
381
None => {
382
let mut args = HashMap::new();
383
args.insert(
384
"day".to_owned(),
385
weekday_name(default_first_day, WeekdayWidth::Full),
386
);
387
crate::i18n::tr_args("settings.calendar.first_day_regional", &args)
388
}
389
}
390
}
391
392
357
fn time_scale_label(scale: TimeScale) -> String {
393
358
let mut args = HashMap::new();
394
359
args.insert("count".to_owned(), scale.minutes().to_string());
@@ -403,12 +368,8 @@ fn weekend_label(rule: WeekendWorkWeek) -> String {
403
368
}
404
369
405
370
/// Seven day chips from the first day of week; the last work day cannot be turned off.
406
fn work_day_chips(
407
app: &Entity<AppState>,
408
prefs: &CalendarPrefs,
409
default_first_day: Weekday,
410
) -> Div {
411
let layout = prefs.layout(default_first_day);
371
fn work_day_chips(app: &Entity<AppState>, prefs: &CalendarPrefs, first_day: Weekday) -> Div {
372
let layout = prefs.layout(first_day);
412
373
h_flex()
413
374
.gap(px(4.))
414
375
.children(layout.weekdays().into_iter().map(|day| {
@@ -25,7 +25,11 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {25
let mut body = v_flex()25
let mut body = v_flex()26
.w_full()26
.w_full()27
.child(caption(tr("settings.calendar.section_view")))27
.child(caption(tr("settings.calendar.section_view")))28
.children(view_rows(app, &prefs, app.read(cx).default_first_day()))28
.children(view_rows(29
app,30
&prefs,31
app.read(cx).calendar_layout().first_day,32
))29
.child(caption(tr("settings.calendar.section_google")))33
.child(caption(tr("settings.calendar.section_google")))30
.child(connect_row(app, accounts.has_google(), pending));34
.child(connect_row(app, accounts.has_google(), pending));31
for account in &accounts.google_accounts {35
for account in &accounts.google_accounts {@@ -247,16 +251,11 @@ fn home_choices(app: &Entity<AppState>, accounts: &store::CalendarAccounts) -> D247
choices251
choices248
}252
}249
253
250
const FIRST_DAY_CHOICES: [Weekday; 3] = [Weekday::Mon, Weekday::Sun, Weekday::Sat];251
const CHIP_SIZE: f32 = 32.;254
const CHIP_SIZE: f32 = 32.;252
const TIME_SELECT_WIDTH: f32 = 104.;255
const TIME_SELECT_WIDTH: f32 = 104.;253
256
254
/// Default view, first day, work days and hours, time scale, weekend Work week.257
/// Default view, work days and hours, time scale, weekend Work week.255
fn view_rows(258
fn view_rows(app: &Entity<AppState>, prefs: &CalendarPrefs, first_day: Weekday) -> Vec<Div> {256
app: &Entity<AppState>,257
prefs: &CalendarPrefs,258
default_first_day: Weekday,259
) -> Vec<Div> {260
vec![259
vec![261
control_row(260
control_row(262
tr("settings.calendar.default_view"),261
tr("settings.calendar.default_view"),@@ -278,30 +277,10 @@ fn view_rows(278
.collect(),277
.collect(),279
),278
),280
),279
),281
control_row(282
tr("settings.calendar.first_day"),283
tr("settings.calendar.first_day_detail"),284
select(285
"settings-calendar-first-day",286
first_day_label(prefs.first_day, default_first_day),287
false,288
std::iter::once(None)289
.chain(FIRST_DAY_CHOICES.into_iter().map(Some))290
.map(|day| {291
prefs_choice(292
app,293
first_day_label(day, default_first_day),294
prefs.first_day == day,295
move |prefs| prefs.first_day = day,296
)297
})298
.collect(),299
),300
),301
control_row(280
control_row(302
tr("settings.calendar.work_days"),281
tr("settings.calendar.work_days"),303
tr("settings.calendar.mailbox_detail"),282
tr("settings.calendar.mailbox_detail"),304
work_day_chips(app, prefs, default_first_day),283
work_day_chips(app, prefs, first_day),305
),284
),306
control_row(285
control_row(307
tr("settings.calendar.work_hours"),286
tr("settings.calendar.work_hours"),@@ -375,20 +354,6 @@ fn default_view_label(view: DefaultView) -> String {375
.map_or_else(|| tr("settings.calendar.last_used"), |span| span.label())354
.map_or_else(|| tr("settings.calendar.last_used"), |span| span.label())376
}355
}377
356
378
fn first_day_label(day: Option<Weekday>, default_first_day: Weekday) -> String {379
match day {380
Some(day) => weekday_name(day, WeekdayWidth::Full),381
None => {382
let mut args = HashMap::new();383
args.insert(384
"day".to_owned(),385
weekday_name(default_first_day, WeekdayWidth::Full),386
);387
crate::i18n::tr_args("settings.calendar.first_day_regional", &args)388
}389
}390
}391
392
fn time_scale_label(scale: TimeScale) -> String {357
fn time_scale_label(scale: TimeScale) -> String {393
let mut args = HashMap::new();358
let mut args = HashMap::new();394
args.insert("count".to_owned(), scale.minutes().to_string());359
args.insert("count".to_owned(), scale.minutes().to_string());@@ -403,12 +368,8 @@ fn weekend_label(rule: WeekendWorkWeek) -> String {403
}368
}404
369
405
/// Seven day chips from the first day of week; the last work day cannot be turned off.370
/// Seven day chips from the first day of week; the last work day cannot be turned off.406
fn work_day_chips(371
fn work_day_chips(app: &Entity<AppState>, prefs: &CalendarPrefs, first_day: Weekday) -> Div {407
app: &Entity<AppState>,372
let layout = prefs.layout(first_day);408
prefs: &CalendarPrefs,409
default_first_day: Weekday,410
) -> Div {411
let layout = prefs.layout(default_first_day);412
h_flex()373
h_flex()413
.gap(px(4.))374
.gap(px(4.))414
.children(layout.weekdays().into_iter().map(|day| {375
.children(layout.weekdays().into_iter().map(|day| {@@ -11,6 +11,7 @@ mod help;
11
11
mod mcp;
12
12
mod nav;
13
13
mod notifications;
14
mod regional;
14
15
mod rows;
15
16
16
17
#[cfg(test)]
@@ -11,6 +11,7 @@ mod help;11
mod mcp;11
mod mcp;12
mod nav;12
mod nav;13
mod notifications;13
mod notifications;14
mod regional;14
mod rows;15
mod rows;15
16
16
#[cfg(test)]17
#[cfg(test)]@@ -0,0 +1,149 @@
1
//! Regional format rows: region, time format and first day of week.
2
3
use app_base::format::{DateStyle, WeekdayWidth, weekday_name};
4
use app_base::regional::{ClockPreference, Region, RegionalPrefs, SystemFormat};
5
use app_base::ui_locale::tr_with;
6
use chrono::{NaiveTime, Weekday};
7
use gpui_kit::*;
8
9
use super::rows::{Choice, control_row, select_with_width};
10
use crate::app_state::AppState;
11
use crate::i18n::tr;
12
13
const SELECT_WIDTH: f32 = 240.;
14
const FIRST_DAY_CHOICES: [Weekday; 3] = [Weekday::Mon, Weekday::Sun, Weekday::Sat];
15
16
pub fn rows(app: &Entity<AppState>, cx: &App) -> Vec<Div> {
17
let state = app.read(cx);
18
let prefs = state.regional_prefs;
19
let system = SystemFormat::read();
20
let automatic =
21
|change: fn(RegionalPrefs) -> RegionalPrefs| state.regional_style(&change(prefs), &system);
22
let auto_clock = automatic(|prefs| RegionalPrefs {
23
clock: ClockPreference::Auto,
24
..prefs
25
});
26
let auto_first_day = automatic(|prefs| RegionalPrefs {
27
first_day: None,
28
..prefs
29
})
30
.first_day();
31
let system_region = system
32
.region()
33
.map(Region::label)
34
.or(system.locale.clone())
35
.unwrap_or_default();
36
let region_label = |region: Option<Region>| match region {
37
Some(region) => region.label(),
38
None => tr_with(
39
"settings.appearance.region.follow_system",
40
&[("region", &system_region)],
41
),
42
};
43
let mut regions = Region::ALL.to_vec();
44
regions.sort_by_cached_key(|region| region.label());
45
46
vec![
47
control_row(
48
tr("settings.appearance.region.title"),
49
tr("settings.appearance.region.detail"),
50
select_with_width(
51
"settings-region",
52
region_label(prefs.region),
53
SELECT_WIDTH,
54
false,
55
std::iter::once(None)
56
.chain(regions.into_iter().map(Some))
57
.map(|region| {
58
choice(
59
app,
60
region_label(region),
61
prefs.region == region,
62
RegionalPrefs { region, ..prefs },
63
)
64
})
65
.collect(),
66
),
67
),
68
control_row(
69
tr("settings.appearance.clock.title"),
70
tr("settings.appearance.clock.detail"),
71
select_with_width(
72
"settings-clock",
73
clock_label(prefs.clock, auto_clock),
74
SELECT_WIDTH,
75
false,
76
ClockPreference::ALL
77
.into_iter()
78
.map(|clock| {
79
choice(
80
app,
81
clock_label(clock, auto_clock),
82
prefs.clock == clock,
83
RegionalPrefs { clock, ..prefs },
84
)
85
})
86
.collect(),
87
),
88
),
89
control_row(
90
tr("settings.appearance.first_day.title"),
91
tr("settings.appearance.first_day.detail"),
92
select_with_width(
93
"settings-first-day",
94
first_day_label(prefs.first_day, auto_first_day),
95
SELECT_WIDTH,
96
false,
97
std::iter::once(None)
98
.chain(FIRST_DAY_CHOICES.into_iter().map(Some))
99
.map(|first_day| {
100
choice(
101
app,
102
first_day_label(first_day, auto_first_day),
103
prefs.first_day == first_day,
104
RegionalPrefs { first_day, ..prefs },
105
)
106
})
107
.collect(),
108
),
109
),
110
]
111
}
112
113
fn choice(app: &Entity<AppState>, label: String, checked: bool, prefs: RegionalPrefs) -> Choice {
114
let app = app.clone();
115
Choice::new(label, checked, move |cx| {
116
app.update(cx, |state, cx| state.set_regional_prefs(prefs, cx));
117
cx.refresh_windows();
118
})
119
}
120
121
/// Each choice names its example time: "24-hour (14:30)".
122
fn clock_label(clock: ClockPreference, automatic: DateStyle) -> String {
123
let (key, style) = match clock {
124
ClockPreference::Auto => ("settings.appearance.clock.auto", automatic),
125
ClockPreference::Hours24 => (
126
"settings.appearance.clock.hours_24",
127
automatic.with_twelve_hour(false),
128
),
129
ClockPreference::Hours12 => (
130
"settings.appearance.clock.hours_12",
131
automatic.with_twelve_hour(true),
132
),
133
};
134
let example = NaiveTime::from_hms_opt(14, 30, 0)
135
.unwrap_or_default()
136
.format(style.clock())
137
.to_string();
138
tr_with(key, &[("example", &example)])
139
}
140
141
fn first_day_label(first_day: Option<Weekday>, automatic: Weekday) -> String {
142
match first_day {
143
Some(day) => weekday_name(day, WeekdayWidth::Full),
144
None => tr_with(
145
"settings.appearance.first_day.auto",
146
&[("day", &weekday_name(automatic, WeekdayWidth::Full))],
147
),
148
}
149
}
@@ -0,0 +1,149 @@1
//! Regional format rows: region, time format and first day of week.2
3
use app_base::format::{DateStyle, WeekdayWidth, weekday_name};4
use app_base::regional::{ClockPreference, Region, RegionalPrefs, SystemFormat};5
use app_base::ui_locale::tr_with;6
use chrono::{NaiveTime, Weekday};7
use gpui_kit::*;8
9
use super::rows::{Choice, control_row, select_with_width};10
use crate::app_state::AppState;11
use crate::i18n::tr;12
13
const SELECT_WIDTH: f32 = 240.;14
const FIRST_DAY_CHOICES: [Weekday; 3] = [Weekday::Mon, Weekday::Sun, Weekday::Sat];15
16
pub fn rows(app: &Entity<AppState>, cx: &App) -> Vec<Div> {17
let state = app.read(cx);18
let prefs = state.regional_prefs;19
let system = SystemFormat::read();20
let automatic =21
|change: fn(RegionalPrefs) -> RegionalPrefs| state.regional_style(&change(prefs), &system);22
let auto_clock = automatic(|prefs| RegionalPrefs {23
clock: ClockPreference::Auto,24
..prefs25
});26
let auto_first_day = automatic(|prefs| RegionalPrefs {27
first_day: None,28
..prefs29
})30
.first_day();31
let system_region = system32
.region()33
.map(Region::label)34
.or(system.locale.clone())35
.unwrap_or_default();36
let region_label = |region: Option<Region>| match region {37
Some(region) => region.label(),38
None => tr_with(39
"settings.appearance.region.follow_system",40
&[("region", &system_region)],41
),42
};43
let mut regions = Region::ALL.to_vec();44
regions.sort_by_cached_key(|region| region.label());45
46
vec![47
control_row(48
tr("settings.appearance.region.title"),49
tr("settings.appearance.region.detail"),50
select_with_width(51
"settings-region",52
region_label(prefs.region),53
SELECT_WIDTH,54
false,55
std::iter::once(None)56
.chain(regions.into_iter().map(Some))57
.map(|region| {58
choice(59
app,60
region_label(region),61
prefs.region == region,62
RegionalPrefs { region, ..prefs },63
)64
})65
.collect(),66
),67
),68
control_row(69
tr("settings.appearance.clock.title"),70
tr("settings.appearance.clock.detail"),71
select_with_width(72
"settings-clock",73
clock_label(prefs.clock, auto_clock),74
SELECT_WIDTH,75
false,76
ClockPreference::ALL77
.into_iter()78
.map(|clock| {79
choice(80
app,81
clock_label(clock, auto_clock),82
prefs.clock == clock,83
RegionalPrefs { clock, ..prefs },84
)85
})86
.collect(),87
),88
),89
control_row(90
tr("settings.appearance.first_day.title"),91
tr("settings.appearance.first_day.detail"),92
select_with_width(93
"settings-first-day",94
first_day_label(prefs.first_day, auto_first_day),95
SELECT_WIDTH,96
false,97
std::iter::once(None)98
.chain(FIRST_DAY_CHOICES.into_iter().map(Some))99
.map(|first_day| {100
choice(101
app,102
first_day_label(first_day, auto_first_day),103
prefs.first_day == first_day,104
RegionalPrefs { first_day, ..prefs },105
)106
})107
.collect(),108
),109
),110
]111
}112
113
fn choice(app: &Entity<AppState>, label: String, checked: bool, prefs: RegionalPrefs) -> Choice {114
let app = app.clone();115
Choice::new(label, checked, move |cx| {116
app.update(cx, |state, cx| state.set_regional_prefs(prefs, cx));117
cx.refresh_windows();118
})119
}120
121
/// Each choice names its example time: "24-hour (14:30)".122
fn clock_label(clock: ClockPreference, automatic: DateStyle) -> String {123
let (key, style) = match clock {124
ClockPreference::Auto => ("settings.appearance.clock.auto", automatic),125
ClockPreference::Hours24 => (126
"settings.appearance.clock.hours_24",127
automatic.with_twelve_hour(false),128
),129
ClockPreference::Hours12 => (130
"settings.appearance.clock.hours_12",131
automatic.with_twelve_hour(true),132
),133
};134
let example = NaiveTime::from_hms_opt(14, 30, 0)135
.unwrap_or_default()136
.format(style.clock())137
.to_string();138
tr_with(key, &[("example", &example)])139
}140
141
fn first_day_label(first_day: Option<Weekday>, automatic: Weekday) -> String {142
match first_day {143
Some(day) => weekday_name(day, WeekdayWidth::Full),144
None => tr_with(145
"settings.appearance.first_day.auto",146
&[("day", &weekday_name(automatic, WeekdayWidth::Full))],147
),148
}149
}@@ -1,13 +1,13 @@
1
1
use std::collections::HashMap;
2
2
3
use app_base::format::Zone;
3
use app_base::format::{WeekdayWidth, Zone, weekday_name};
4
4
use app_ui_kit::layout::{COMFY_RUNWAY_WIDTH, SIDEBAR_WIDTH};
5
5
use app_ui_kit::render::hooks::open_link;
6
6
use app_ui_kit::render::{Block, layout_blocks, render_blocks, strip_image_placeholders};
7
7
use chatsvc::{
8
8
CalendarEvent, CalendarSource, DialIn, EventAttendee, Reply, ResponseType, join_info_text,
9
9
};
10
use chrono::{Datelike, Weekday};
10
use chrono::Datelike;
11
11
use gpui_kit::assets::IconName;
12
12
use gpui_kit::component::Sizable as _;
13
13
use gpui_kit::component::button::{Button, ButtonVariants as _};
@@ -1026,8 +1026,8 @@ fn peek_when_label(event: &CalendarEvent) -> String {
1026
1026
let day_label = |date: chrono::NaiveDate| {
1027
1027
format!(
1028
1028
"{} {}",
1029
localized_weekday(date.weekday()),
1030
format_peek_date(date)
1029
weekday_name(date.weekday(), WeekdayWidth::Short),
1030
app_base::format::date_label(date)
1031
1031
)
1032
1032
};
1033
1033
let (start, end) = (start.date_naive(), end.date_naive());
@@ -1041,8 +1041,8 @@ fn peek_when_label(event: &CalendarEvent) -> String {
1041
1041
}
1042
1042
return format!("{} · {}", tr("calendar.peek.all_day"), day_label(start));
1043
1043
}
1044
let weekday = localized_weekday(start.weekday());
1045
let date = format_peek_date(start.date_naive());
1044
let weekday = weekday_name(start.weekday(), WeekdayWidth::Short);
1045
let date = app_base::format::date_label(start.date_naive());
1046
1046
let clock = app_base::format::clock_format();
1047
1047
if start.date_naive() == end.date_naive() {
1048
1048
format!(
@@ -1055,7 +1055,7 @@ fn peek_when_label(event: &CalendarEvent) -> String {
1055
1055
format!(
1056
1056
"{weekday} {date}, {} – {}, {}",
1057
1057
start.format(clock),
1058
format_peek_date(end.date_naive()),
1058
app_base::format::date_label(end.date_naive()),
1059
1059
end.format(clock)
1060
1060
)
1061
1061
}
@@ -1101,38 +1101,6 @@ fn reminder_label(minutes: u32) -> String {
1101
1101
)
1102
1102
}
1103
1103
1104
fn ui_is_german() -> bool {
1105
gpui_kit::component::locale().starts_with("de")
1106
}
1107
1108
fn format_peek_date(date: chrono::NaiveDate) -> String {
1109
if ui_is_german() {
1110
date.format("%d.%m.%Y").to_string()
1111
} else {
1112
date.format("%-m/%-d/%Y").to_string()
1113
}
1114
}
1115
1116
fn localized_weekday(weekday: Weekday) -> &'static str {
1117
let de = ui_is_german();
1118
match (de, weekday) {
1119
(true, Weekday::Mon) => "Mo",
1120
(true, Weekday::Tue) => "Di",
1121
(true, Weekday::Wed) => "Mi",
1122
(true, Weekday::Thu) => "Do",
1123
(true, Weekday::Fri) => "Fr",
1124
(true, Weekday::Sat) => "Sa",
1125
(true, Weekday::Sun) => "So",
1126
(false, Weekday::Mon) => "Mon",
1127
(false, Weekday::Tue) => "Tue",
1128
(false, Weekday::Wed) => "Wed",
1129
(false, Weekday::Thu) => "Thu",
1130
(false, Weekday::Fri) => "Fri",
1131
(false, Weekday::Sat) => "Sat",
1132
(false, Weekday::Sun) => "Sun",
1133
}
1134
}
1135
1136
1104
fn location_label(event: &CalendarEvent) -> String {
1137
1105
if let Some(location) = event.location.clone().filter(|value| !value.is_empty()) {
1138
1106
return location;
@@ -1,13 +1,13 @@1
use std::collections::HashMap;1
use std::collections::HashMap;2
2
3
use app_base::format::Zone;3
use app_base::format::{WeekdayWidth, Zone, weekday_name};4
use app_ui_kit::layout::{COMFY_RUNWAY_WIDTH, SIDEBAR_WIDTH};4
use app_ui_kit::layout::{COMFY_RUNWAY_WIDTH, SIDEBAR_WIDTH};5
use app_ui_kit::render::hooks::open_link;5
use app_ui_kit::render::hooks::open_link;6
use app_ui_kit::render::{Block, layout_blocks, render_blocks, strip_image_placeholders};6
use app_ui_kit::render::{Block, layout_blocks, render_blocks, strip_image_placeholders};7
use chatsvc::{7
use chatsvc::{8
CalendarEvent, CalendarSource, DialIn, EventAttendee, Reply, ResponseType, join_info_text,8
CalendarEvent, CalendarSource, DialIn, EventAttendee, Reply, ResponseType, join_info_text,9
};9
};10
use chrono::{Datelike, Weekday};10
use chrono::Datelike;11
use gpui_kit::assets::IconName;11
use gpui_kit::assets::IconName;12
use gpui_kit::component::Sizable as _;12
use gpui_kit::component::Sizable as _;13
use gpui_kit::component::button::{Button, ButtonVariants as _};13
use gpui_kit::component::button::{Button, ButtonVariants as _};@@ -1026,8 +1026,8 @@ fn peek_when_label(event: &CalendarEvent) -> String {1026
let day_label = |date: chrono::NaiveDate| {1026
let day_label = |date: chrono::NaiveDate| {1027
format!(1027
format!(1028
"{} {}",1028
"{} {}",1029
localized_weekday(date.weekday()),1029
weekday_name(date.weekday(), WeekdayWidth::Short),1030
format_peek_date(date)1030
app_base::format::date_label(date)1031
)1031
)1032
};1032
};1033
let (start, end) = (start.date_naive(), end.date_naive());1033
let (start, end) = (start.date_naive(), end.date_naive());@@ -1041,8 +1041,8 @@ fn peek_when_label(event: &CalendarEvent) -> String {1041
}1041
}1042
return format!("{} · {}", tr("calendar.peek.all_day"), day_label(start));1042
return format!("{} · {}", tr("calendar.peek.all_day"), day_label(start));1043
}1043
}1044
let weekday = localized_weekday(start.weekday());1044
let weekday = weekday_name(start.weekday(), WeekdayWidth::Short);1045
let date = format_peek_date(start.date_naive());1045
let date = app_base::format::date_label(start.date_naive());1046
let clock = app_base::format::clock_format();1046
let clock = app_base::format::clock_format();1047
if start.date_naive() == end.date_naive() {1047
if start.date_naive() == end.date_naive() {1048
format!(1048
format!(@@ -1055,7 +1055,7 @@ fn peek_when_label(event: &CalendarEvent) -> String {1055
format!(1055
format!(1056
"{weekday} {date}, {} – {}, {}",1056
"{weekday} {date}, {} – {}, {}",1057
start.format(clock),1057
start.format(clock),1058
format_peek_date(end.date_naive()),1058
app_base::format::date_label(end.date_naive()),1059
end.format(clock)1059
end.format(clock)1060
)1060
)1061
}1061
}@@ -1101,38 +1101,6 @@ fn reminder_label(minutes: u32) -> String {1101
)1101
)1102
}1102
}1103
1103
1104
fn ui_is_german() -> bool {1105
gpui_kit::component::locale().starts_with("de")1106
}1107
1108
fn format_peek_date(date: chrono::NaiveDate) -> String {1109
if ui_is_german() {1110
date.format("%d.%m.%Y").to_string()1111
} else {1112
date.format("%-m/%-d/%Y").to_string()1113
}1114
}1115
1116
fn localized_weekday(weekday: Weekday) -> &'static str {1117
let de = ui_is_german();1118
match (de, weekday) {1119
(true, Weekday::Mon) => "Mo",1120
(true, Weekday::Tue) => "Di",1121
(true, Weekday::Wed) => "Mi",1122
(true, Weekday::Thu) => "Do",1123
(true, Weekday::Fri) => "Fr",1124
(true, Weekday::Sat) => "Sa",1125
(true, Weekday::Sun) => "So",1126
(false, Weekday::Mon) => "Mon",1127
(false, Weekday::Tue) => "Tue",1128
(false, Weekday::Wed) => "Wed",1129
(false, Weekday::Thu) => "Thu",1130
(false, Weekday::Fri) => "Fri",1131
(false, Weekday::Sat) => "Sat",1132
(false, Weekday::Sun) => "Sun",1133
}1134
}1135
1136
fn location_label(event: &CalendarEvent) -> String {1104
fn location_label(event: &CalendarEvent) -> String {1137
if let Some(location) = event.location.clone().filter(|value| !value.is_empty()) {1105
if let Some(location) = event.location.clone().filter(|value| !value.is_empty()) {1138
return location;1106
return location;@@ -19,16 +19,13 @@ const DESCRIPTION_LINES: usize = 3;
19
19
pub fn when_label(start: DateTime<Utc>, end: DateTime<Utc>) -> String {
20
20
let (start, end) = (start.with_timezone(&Local), end.with_timezone(&Local));
21
21
let clock = crate::format::clock_format();
22
let day = |time: DateTime<Local>| crate::format::weekday_date_label(time.date_naive());
22
23
let end_text = if end.date_naive() == start.date_naive() {
23
24
end.format(clock).to_string()
24
25
} else {
25
format!("{} {}", end.format("%a %-d %b,"), end.format(clock))
26
format!("{} {}", day(end), end.format(clock))
26
27
};
27
format!(
28
"{} {} - {end_text}",
29
start.format("%a %-d %b,"),
30
start.format(clock)
31
)
28
format!("{} {} - {end_text}", day(start), start.format(clock))
32
29
}
33
30
34
31
fn description_excerpt(description: &str) -> Option<String> {
@@ -19,16 +19,13 @@ const DESCRIPTION_LINES: usize = 3;19
pub fn when_label(start: DateTime<Utc>, end: DateTime<Utc>) -> String {19
pub fn when_label(start: DateTime<Utc>, end: DateTime<Utc>) -> String {20
let (start, end) = (start.with_timezone(&Local), end.with_timezone(&Local));20
let (start, end) = (start.with_timezone(&Local), end.with_timezone(&Local));21
let clock = crate::format::clock_format();21
let clock = crate::format::clock_format();22
let day = |time: DateTime<Local>| crate::format::weekday_date_label(time.date_naive());22
let end_text = if end.date_naive() == start.date_naive() {23
let end_text = if end.date_naive() == start.date_naive() {23
end.format(clock).to_string()24
end.format(clock).to_string()24
} else {25
} else {25
format!("{} {}", end.format("%a %-d %b,"), end.format(clock))26
format!("{} {}", day(end), end.format(clock))26
};27
};27
format!(28
format!("{} {} - {end_text}", day(start), start.format(clock))28
"{} {} - {end_text}",29
start.format("%a %-d %b,"),30
start.format(clock)31
)32
}29
}33
30
34
fn description_excerpt(description: &str) -> Option<String> {31
fn description_excerpt(description: &str) -> Option<String> {@@ -0,0 +1,28 @@
1
---
2
status: proposed
3
date: 2026-11-16
4
superseded-by:
5
---
6
7
# ADR 0018: Regional format is separate from the app language
8
9
## Context
10
11
Dates and times followed what `sys_locale` returns. That is the preferred UI language on every OS, not the regional format: `CFLocaleCopyPreferredLanguages` on macOS, `GetUserPreferredUILanguages` on Windows, `LC_MESSAGES` and `LANG` on Linux. An English UI in Austria (`en_US@rg=atzzzz` on macOS) got a 12-hour clock, `11/16/2026` and Sunday as the first day. Several labels also used chrono's English `%a` and `%b` in a German UI.
12
13
Teams desktop formats with the OS regional format and has no account setting for it. ADR 0016 put a first-day override in the calendar settings, but date pickers and other weeks did not read it.
14
15
The options were: keep following the language, read the OS regional format only, or read it and let the user override it in the app.
16
17
## Decision
18
19
- The regional format is read from the OS: `AppleLocale` with its `rg` override, `AppleICUForce24HourTime`/`AppleICUForce12HourTime` and `AppleFirstWeekday` on macOS, `GetUserDefaultLocaleName` and `GetLocaleInfoEx` on Windows, `LC_ALL`/`LC_TIME`/`LANG` on Linux.
20
- Settings > Appearance > Regional format offers region (follow system or one of a curated list), time format (automatic, 24-hour, 12-hour) and first day of week (automatic, Monday, Sunday, Saturday). The choice is local, as Teams has no account setting for it.
21
- The region decides the patterns and decimal separator. The app language decides the words. Weekday and month names always come from the locale catalog.
22
- First day of week: the choice, else the mailbox language as ADR 0016 says, else the region. This replaces the first-day bullet of ADR 0016 and its calendar setting; work hours and time scale stay as 0016 decided. A first day saved in the calendar settings carries over once.
23
24
## Consequences
25
26
- One first-day value drives the calendar grid, mini month and date pickers.
27
- The region list only holds regions whose patterns `format::date_style` knows. A new region needs its patterns there first.
28
- Custom date patterns from the OS (macOS `AppleICUDateFormatStrings`, Windows short date) are not read.
@@ -0,0 +1,28 @@1
---2
status: proposed3
date: 2026-11-164
superseded-by:5
---6
7
# ADR 0018: Regional format is separate from the app language8
9
## Context10
11
Dates and times followed what `sys_locale` returns. That is the preferred UI language on every OS, not the regional format: `CFLocaleCopyPreferredLanguages` on macOS, `GetUserPreferredUILanguages` on Windows, `LC_MESSAGES` and `LANG` on Linux. An English UI in Austria (`en_US@rg=atzzzz` on macOS) got a 12-hour clock, `11/16/2026` and Sunday as the first day. Several labels also used chrono's English `%a` and `%b` in a German UI.12
13
Teams desktop formats with the OS regional format and has no account setting for it. ADR 0016 put a first-day override in the calendar settings, but date pickers and other weeks did not read it.14
15
The options were: keep following the language, read the OS regional format only, or read it and let the user override it in the app.16
17
## Decision18
19
- The regional format is read from the OS: `AppleLocale` with its `rg` override, `AppleICUForce24HourTime`/`AppleICUForce12HourTime` and `AppleFirstWeekday` on macOS, `GetUserDefaultLocaleName` and `GetLocaleInfoEx` on Windows, `LC_ALL`/`LC_TIME`/`LANG` on Linux.20
- Settings > Appearance > Regional format offers region (follow system or one of a curated list), time format (automatic, 24-hour, 12-hour) and first day of week (automatic, Monday, Sunday, Saturday). The choice is local, as Teams has no account setting for it.21
- The region decides the patterns and decimal separator. The app language decides the words. Weekday and month names always come from the locale catalog.22
- First day of week: the choice, else the mailbox language as ADR 0016 says, else the region. This replaces the first-day bullet of ADR 0016 and its calendar setting; work hours and time scale stay as 0016 decided. A first day saved in the calendar settings carries over once.23
24
## Consequences25
26
- One first-day value drives the calendar grid, mini month and date pickers.27
- The region list only holds regions whose patterns `format::date_style` knows. A new region needs its patterns there first.28
- Custom date patterns from the OS (macOS `AppleICUDateFormatStrings`, Windows short date) are not read.@@ -33,5 +33,6 @@ Statuses: `proposed`, `accepted`, `superseded`.
33
33
| [0015](0015-linux-desktop-toasts-use-freedesktop-notifications.md) | Linux desktop toasts use freedesktop Notifications |
34
34
| [0016](0016-calendar-week-start-and-time-scale-stay-local.md) | Calendar work hours go to the mailbox, week start and time scale stay local |
35
35
| [0017](0017-guest-orgs-switch-by-restart.md) | Guest orgs, one org per window, switch by restart |
36
| [0018](0018-regional-format-is-separate-from-the-app-language.md) | Regional format is separate from the app language |
36
37
37
38
Records `0001` to `0017` are the decisions already shipped. `0001` follows Daniel's call-window note in `GUARDRAILS.md`.
@@ -33,5 +33,6 @@ Statuses: `proposed`, `accepted`, `superseded`.33
| [0015](0015-linux-desktop-toasts-use-freedesktop-notifications.md) | Linux desktop toasts use freedesktop Notifications |33
| [0015](0015-linux-desktop-toasts-use-freedesktop-notifications.md) | Linux desktop toasts use freedesktop Notifications |34
| [0016](0016-calendar-week-start-and-time-scale-stay-local.md) | Calendar work hours go to the mailbox, week start and time scale stay local |34
| [0016](0016-calendar-week-start-and-time-scale-stay-local.md) | Calendar work hours go to the mailbox, week start and time scale stay local |35
| [0017](0017-guest-orgs-switch-by-restart.md) | Guest orgs, one org per window, switch by restart |35
| [0017](0017-guest-orgs-switch-by-restart.md) | Guest orgs, one org per window, switch by restart |36
| [0018](0018-regional-format-is-separate-from-the-app-language.md) | Regional format is separate from the app language |36
37
37
Records `0001` to `0017` are the decisions already shipped. `0001` follows Daniel's call-window note in `GUARDRAILS.md`.38
Records `0001` to `0017` are the decisions already shipped. `0001` follows Daniel's call-window note in `GUARDRAILS.md`.