fix(calendar): range title and day numbers follow the account locale
- en-GB like Teams: "09-15 November, 2026", day "09" - en-US: "November 9-13, 2026", day "9" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -33,6 +33,50 @@ pub fn clock_format() -> &'static str {
33
33
current_date_style().map_or("%H:%M", |style| style.clock)
34
34
}
35
35
36
impl DateStyle {
37
fn month_first(&self) -> bool {
38
self.day_month.starts_with("%-m")
39
}
40
41
fn day_number(&self) -> &'static str {
42
if self.day_month.starts_with("%d") { "%d" } else { "%-d" }
43
}
44
}
45
46
pub fn calendar_day_number(date: NaiveDate) -> String {
47
date.format(current_date_style().map_or("%-d", |style| style.day_number()))
48
.to_string()
49
}
50
51
pub fn calendar_range_label(start: NaiveDate, end: NaiveDate) -> String {
52
let style = current_date_style();
53
let day = style.map_or("%-d", |style| style.day_number());
54
if style.is_none_or(|style| style.month_first()) {
55
let from = start.format(&format!("%B {day}")).to_string();
56
let to = end.format(&format!("%B {day}, %Y")).to_string();
57
return if start == end {
58
to
59
} else if start.year() != end.year() {
60
format!("{} - {to}", start.format(&format!("%B {day}, %Y")))
61
} else if start.month() != end.month() {
62
format!("{from} - {to}")
63
} else {
64
format!("{from}-{}, {}", end.format(day), end.year())
65
};
66
}
67
let from = start.format(&format!("{day} %B")).to_string();
68
let to = end.format(&format!("{day} %B, %Y")).to_string();
69
if start == end {
70
to
71
} else if start.year() != end.year() {
72
format!("{} - {to}", start.format(&format!("{day} %B, %Y")))
73
} else if start.month() != end.month() {
74
format!("{from} - {to}")
75
} else {
76
format!("{}-{to}", start.format(day))
77
}
78
}
79
36
80
/// Numeric day and month in the order of the account's display language, as `Intl.DateTimeFormat` does in Teams.
37
81
pub fn date_style(locale: &str) -> DateStyle {
38
82
let locale = locale.to_ascii_lowercase();
@@ -236,6 +280,21 @@ mod tests {
236
280
237
281
use super::*;
238
282
283
#[test]
284
fn calendar_range_follows_the_account_locale() {
285
let date = |month, day| NaiveDate::from_ymd_opt(2026, month, day).unwrap();
286
set_date_locale(Some("en-GB"));
287
assert_eq!(calendar_range_label(date(11, 9), date(11, 15)), "09-15 November, 2026");
288
assert_eq!(calendar_range_label(date(11, 30), date(12, 4)), "30 November - 04 December, 2026");
289
assert_eq!(calendar_day_number(date(11, 9)), "09");
290
set_date_locale(Some("en-US"));
291
assert_eq!(calendar_range_label(date(11, 9), date(11, 13)), "November 9-13, 2026");
292
assert_eq!(calendar_day_number(date(11, 9)), "9");
293
set_date_locale(Some("de-DE"));
294
assert_eq!(calendar_range_label(date(11, 9), date(11, 9)), "9 November, 2026");
295
set_date_locale(None);
296
}
297
239
298
#[test]
240
299
fn team_tiles_letter_first_and_last_word_like_teams() {
241
300
assert_eq!(team_initials("e_IT-Support"), "eI");
@@ -33,6 +33,50 @@ pub fn clock_format() -> &'static str {33
current_date_style().map_or("%H:%M", |style| style.clock)33
current_date_style().map_or("%H:%M", |style| style.clock)34
}34
}35
35
36
impl DateStyle {37
fn month_first(&self) -> bool {38
self.day_month.starts_with("%-m")39
}40
41
fn day_number(&self) -> &'static str {42
if self.day_month.starts_with("%d") { "%d" } else { "%-d" }43
}44
}45
46
pub fn calendar_day_number(date: NaiveDate) -> String {47
date.format(current_date_style().map_or("%-d", |style| style.day_number()))48
.to_string()49
}50
51
pub fn calendar_range_label(start: NaiveDate, end: NaiveDate) -> String {52
let style = current_date_style();53
let day = style.map_or("%-d", |style| style.day_number());54
if style.is_none_or(|style| style.month_first()) {55
let from = start.format(&format!("%B {day}")).to_string();56
let to = end.format(&format!("%B {day}, %Y")).to_string();57
return if start == end {58
to59
} else if start.year() != end.year() {60
format!("{} - {to}", start.format(&format!("%B {day}, %Y")))61
} else if start.month() != end.month() {62
format!("{from} - {to}")63
} else {64
format!("{from}-{}, {}", end.format(day), end.year())65
};66
}67
let from = start.format(&format!("{day} %B")).to_string();68
let to = end.format(&format!("{day} %B, %Y")).to_string();69
if start == end {70
to71
} else if start.year() != end.year() {72
format!("{} - {to}", start.format(&format!("{day} %B, %Y")))73
} else if start.month() != end.month() {74
format!("{from} - {to}")75
} else {76
format!("{}-{to}", start.format(day))77
}78
}79
36
/// Numeric day and month in the order of the account's display language, as `Intl.DateTimeFormat` does in Teams.80
/// Numeric day and month in the order of the account's display language, as `Intl.DateTimeFormat` does in Teams.37
pub fn date_style(locale: &str) -> DateStyle {81
pub fn date_style(locale: &str) -> DateStyle {38
let locale = locale.to_ascii_lowercase();82
let locale = locale.to_ascii_lowercase();@@ -236,6 +280,21 @@ mod tests {236
280
237
use super::*;281
use super::*;238
282
283
#[test]284
fn calendar_range_follows_the_account_locale() {285
let date = |month, day| NaiveDate::from_ymd_opt(2026, month, day).unwrap();286
set_date_locale(Some("en-GB"));287
assert_eq!(calendar_range_label(date(11, 9), date(11, 15)), "09-15 November, 2026");288
assert_eq!(calendar_range_label(date(11, 30), date(12, 4)), "30 November - 04 December, 2026");289
assert_eq!(calendar_day_number(date(11, 9)), "09");290
set_date_locale(Some("en-US"));291
assert_eq!(calendar_range_label(date(11, 9), date(11, 13)), "November 9-13, 2026");292
assert_eq!(calendar_day_number(date(11, 9)), "9");293
set_date_locale(Some("de-DE"));294
assert_eq!(calendar_range_label(date(11, 9), date(11, 9)), "9 November, 2026");295
set_date_locale(None);296
}297
239
#[test]298
#[test]240
fn team_tiles_letter_first_and_last_word_like_teams() {299
fn team_tiles_letter_first_and_last_word_like_teams() {241
assert_eq!(team_initials("e_IT-Support"), "eI");300
assert_eq!(team_initials("e_IT-Support"), "eI");@@ -211,16 +211,7 @@ fn close_cluster(blocks: &mut [WeekBlock], lanes: usize) {
211
211
}
212
212
213
213
pub fn range_label(start: NaiveDate, days: i64) -> String {
214
let end = start + Duration::days(days - 1);
215
if start == end {
216
start.format("%B %-d, %Y").to_string()
217
} else if start.month() == end.month() {
218
format!("{} {}-{}, {}", start.format("%B"), start.day(), end.day(), end.year())
219
} else if start.year() == end.year() {
220
format!("{} - {}", start.format("%B %-d"), end.format("%B %-d, %Y"))
221
} else {
222
format!("{} - {}", start.format("%B %-d, %Y"), end.format("%B %-d, %Y"))
223
}
214
app_base::format::calendar_range_label(start, start + Duration::days(days - 1))
224
215
}
225
216
226
217
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -211,16 +211,7 @@ fn close_cluster(blocks: &mut [WeekBlock], lanes: usize) {211
}211
}212
212
213
pub fn range_label(start: NaiveDate, days: i64) -> String {213
pub fn range_label(start: NaiveDate, days: i64) -> String {214
let end = start + Duration::days(days - 1);214
app_base::format::calendar_range_label(start, start + Duration::days(days - 1))215
if start == end {216
start.format("%B %-d, %Y").to_string()217
} else if start.month() == end.month() {218
format!("{} {}-{}, {}", start.format("%B"), start.day(), end.day(), end.year())219
} else if start.year() == end.year() {220
format!("{} - {}", start.format("%B %-d"), end.format("%B %-d, %Y"))221
} else {222
format!("{} - {}", start.format("%B %-d, %Y"), end.format("%B %-d, %Y"))223
}224
}215
}225
216
226
#[derive(Debug, Clone, Copy, PartialEq, Eq)]217
#[derive(Debug, Clone, Copy, PartialEq, Eq)]@@ -1,4 +1,4 @@
1
use app_base::format::clock_format;
1
use app_base::format::{self, clock_format};
2
2
use chatsvc::{CalendarEvent, ResponseType, join_info_text};
3
3
use chrono::{DateTime, Datelike, Local, NaiveDate, Offset, Timelike, Utc};
4
4
use gpui_kit::assets::IconName;
@@ -225,7 +225,7 @@ impl CalendarView {
225
225
.text_size(px(20.))
226
226
.line_height(px(24.))
227
227
.text_color(color)
228
.child(day.date.day().to_string()),
228
.child(format::calendar_day_number(day.date)),
229
229
)
230
230
.child(
231
231
div()
@@ -1,4 +1,4 @@1
use app_base::format::clock_format;1
use app_base::format::{self, clock_format};2
use chatsvc::{CalendarEvent, ResponseType, join_info_text};2
use chatsvc::{CalendarEvent, ResponseType, join_info_text};3
use chrono::{DateTime, Datelike, Local, NaiveDate, Offset, Timelike, Utc};3
use chrono::{DateTime, Datelike, Local, NaiveDate, Offset, Timelike, Utc};4
use gpui_kit::assets::IconName;4
use gpui_kit::assets::IconName;@@ -225,7 +225,7 @@ impl CalendarView {225
.text_size(px(20.))225
.text_size(px(20.))226
.line_height(px(24.))226
.line_height(px(24.))227
.text_color(color)227
.text_color(color)228
.child(day.date.day().to_string()),228
.child(format::calendar_day_number(day.date)),229
)229
)230
.child(230
.child(231
div()231
div()