fix(calendar): date range title and day numbers like Teams
- title shows the shown range ("November 9-13, 2026"), across months and years too
- day headers without leading zero
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -212,12 +212,14 @@ fn close_cluster(blocks: &mut [WeekBlock], lanes: usize) {
212
212
213
213
pub fn range_label(start: NaiveDate, days: i64) -> String {
214
214
let end = start + Duration::days(days - 1);
215
if start.month() == end.month() {
216
start.format("%B %Y").to_string()
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())
217
219
} else if start.year() == end.year() {
218
format!("{} - {}", start.format("%B"), end.format("%B %Y"))
220
format!("{} - {}", start.format("%B %-d"), end.format("%B %-d, %Y"))
219
221
} else {
220
format!("{} - {}", start.format("%B %Y"), end.format("%B %Y"))
222
format!("{} - {}", start.format("%B %-d, %Y"), end.format("%B %-d, %Y"))
221
223
}
222
224
}
223
225
@@ -369,10 +371,18 @@ mod tests {
369
371
#[test]
370
372
fn labels_read_like_teams() {
371
373
let monday = NaiveDate::from_ymd_opt(2026, 11, 30).unwrap();
372
assert_eq!(range_label(monday, 5), "November - December 2026");
374
assert_eq!(range_label(monday, 5), "November 30 - December 4, 2026");
373
375
assert_eq!(
374
376
range_label(NaiveDate::from_ymd_opt(2026, 11, 9).unwrap(), 5),
375
"November 2026"
377
"November 9-13, 2026"
378
);
379
assert_eq!(
380
range_label(NaiveDate::from_ymd_opt(2026, 12, 28).unwrap(), 7),
381
"December 28, 2026 - January 3, 2027"
382
);
383
assert_eq!(
384
range_label(NaiveDate::from_ymd_opt(2026, 11, 9).unwrap(), 1),
385
"November 9, 2026"
376
386
);
377
387
assert_eq!(hour_label(0, true), "12 AM");
378
388
assert_eq!(hour_label(13, true), "1 PM");
@@ -212,12 +212,14 @@ fn close_cluster(blocks: &mut [WeekBlock], lanes: usize) {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
let end = start + Duration::days(days - 1);215
if start.month() == end.month() {215
if start == end {216
start.format("%B %Y").to_string()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())217
} else if start.year() == end.year() {219
} else if start.year() == end.year() {218
format!("{} - {}", start.format("%B"), end.format("%B %Y"))220
format!("{} - {}", start.format("%B %-d"), end.format("%B %-d, %Y"))219
} else {221
} else {220
format!("{} - {}", start.format("%B %Y"), end.format("%B %Y"))222
format!("{} - {}", start.format("%B %-d, %Y"), end.format("%B %-d, %Y"))221
}223
}222
}224
}223
225
@@ -369,10 +371,18 @@ mod tests {369
#[test]371
#[test]370
fn labels_read_like_teams() {372
fn labels_read_like_teams() {371
let monday = NaiveDate::from_ymd_opt(2026, 11, 30).unwrap();373
let monday = NaiveDate::from_ymd_opt(2026, 11, 30).unwrap();372
assert_eq!(range_label(monday, 5), "November - December 2026");374
assert_eq!(range_label(monday, 5), "November 30 - December 4, 2026");373
assert_eq!(375
assert_eq!(374
range_label(NaiveDate::from_ymd_opt(2026, 11, 9).unwrap(), 5),376
range_label(NaiveDate::from_ymd_opt(2026, 11, 9).unwrap(), 5),375
"November 2026"377
"November 9-13, 2026"378
);379
assert_eq!(380
range_label(NaiveDate::from_ymd_opt(2026, 12, 28).unwrap(), 7),381
"December 28, 2026 - January 3, 2027"382
);383
assert_eq!(384
range_label(NaiveDate::from_ymd_opt(2026, 11, 9).unwrap(), 1),385
"November 9, 2026"376
);386
);377
assert_eq!(hour_label(0, true), "12 AM");387
assert_eq!(hour_label(0, true), "12 AM");378
assert_eq!(hour_label(13, true), "1 PM");388
assert_eq!(hour_label(13, true), "1 PM");@@ -1,6 +1,6 @@
1
1
use app_base::format::clock_format;
2
2
use chatsvc::{CalendarEvent, ResponseType, join_info_text};
3
use chrono::{DateTime, Local, NaiveDate, Offset, Timelike, Utc};
3
use chrono::{DateTime, Datelike, Local, NaiveDate, Offset, Timelike, Utc};
4
4
use gpui_kit::assets::IconName;
5
5
use gpui_kit::component::Sizable as _;
6
6
use gpui_kit::component::button::{Button, ButtonVariants as _};
@@ -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.format("%d").to_string()),
228
.child(day.date.day().to_string()),
229
229
)
230
230
.child(
231
231
div()
@@ -1,6 +1,6 @@1
use app_base::format::clock_format;1
use app_base::format::clock_format;2
use chatsvc::{CalendarEvent, ResponseType, join_info_text};2
use chatsvc::{CalendarEvent, ResponseType, join_info_text};3
use chrono::{DateTime, 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;5
use gpui_kit::component::Sizable as _;5
use gpui_kit::component::Sizable as _;6
use gpui_kit::component::button::{Button, ButtonVariants as _};6
use gpui_kit::component::button::{Button, ButtonVariants as _};@@ -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.format("%d").to_string()),228
.child(day.date.day().to_string()),229
)229
)230
.child(230
.child(231
div()231
div()