BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-base / src / format.rs

format.rs

format.rs 21.1 KiB Download Raw
1use std::cell::Cell;
2
3use chrono::{DateTime, Datelike, FixedOffset, Local, NaiveDate, Utc, Weekday};
4
5use crate::theme;
6
7/// `Local` follows the daylight saving rules at the given instant, a fixed offset is the same all year.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum Zone {
10 Local,
11 Fixed(FixedOffset),
12}
13
14impl Zone {
15 pub fn at(self, time: DateTime<Utc>) -> DateTime<FixedOffset> {
16 match self {
17 Zone::Local => time.with_timezone(&Local).fixed_offset(),
18 Zone::Fixed(offset) => time.with_timezone(&offset),
19 }
20 }
21}
22
23impl From<FixedOffset> for Zone {
24 fn from(offset: FixedOffset) -> Self {
25 Zone::Fixed(offset)
26 }
27}
28
29const BADGE_CAP: u32 = 99;
30const WEEKDAY_WINDOW_DAYS: i64 = 6;
31const TWELVE_HOUR_LOCALES: [&str; 6] = ["en-us", "en-ca", "en-ph", "en-au", "en-nz", "en-in"];
32const DOTTED_LOCALES: [&str; 7] = ["de", "da", "nb", "no", "fi", "cs", "sk"];
33const PADDED_DOT_LOCALES: [&str; 4] = ["ru", "pl", "tr", "uk"];
34/// Regions whose week starts on Sunday (CLDR first-day data for the common locales).
35const SUNDAY_FIRST_LOCALES: [&str; 13] = [
36 "en-us", "en-ca", "en-ph", "en-au", "en-nz", "en-in", "ja", "ko", "zh-tw", "he", "pt-br",
37 "es-mx", "zh-hk",
38];
39/// Arabic regions that start on Monday instead of Saturday.
40const ARABIC_MONDAY_LOCALES: [&str; 2] = ["ar-ma", "ar-tn"];
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub struct DateStyle {
44 day_month: &'static str,
45 day_month_year: &'static str,
46 clock: &'static str,
47 first_day: Weekday,
48}
49
50thread_local! {
51 static DATE_STYLE: Cell<Option<DateStyle>> = const { Cell::new(None) };
52}
53
54pub 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.
59pub fn os_regional_locale() -> Option<String> {
60 sys_locale::get_locale()
61 .as_deref()
62 .and_then(normalize_locale)
63}
64
65fn 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)
72}
73
74fn current_date_style() -> Option<DateStyle> {
75 DATE_STYLE.with(Cell::get)
76}
77
78/// First day of the week of the regional format; Monday when it is unknown.
79pub fn regional_first_day() -> Weekday {
80 current_date_style().map_or(Weekday::Mon, |style| style.first_day)
81}
82
83fn first_day_for(locale: &str, language: &str) -> Weekday {
84 if SUNDAY_FIRST_LOCALES.contains(&locale) || SUNDAY_FIRST_LOCALES.contains(&language) {
85 Weekday::Sun
86 } else if (language == "ar" && !ARABIC_MONDAY_LOCALES.contains(&locale)) || language == "fa" {
87 Weekday::Sat
88 } else {
89 Weekday::Mon
90 }
91}
92
93pub fn clock_format() -> &'static str {
94 current_date_style().map_or("%H:%M", |style| style.clock)
95}
96
97impl DateStyle {
98 fn month_first(&self) -> bool {
99 self.day_month.starts_with("%-m")
100 }
101
102 fn day_number(&self) -> &'static str {
103 if self.day_month.starts_with("%d") {
104 "%d"
105 } else {
106 "%-d"
107 }
108 }
109}
110
111pub fn calendar_day_number(date: NaiveDate) -> String {
112 date.format(current_date_style().map_or("%-d", |style| style.day_number()))
113 .to_string()
114}
115
116/// Month name in the app language (`calendar.month.mNN`), not chrono's English `%B`.
117pub fn month_name(date: NaiveDate) -> String {
118 crate::ui_locale::tr(&format!("calendar.month.m{:02}", date.month()))
119}
120
121/// "November 2026" / "November 2026" — month title of the month grid.
122pub fn month_year_label(date: NaiveDate) -> String {
123 format!("{} {}", month_name(date), date.year())
124}
125
126const WEEKDAY_KEYS: [&str; 7] = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
127
128#[derive(Debug, Clone, Copy, PartialEq, Eq)]
129pub enum WeekdayWidth {
130 /// "Monday" / "Montag"
131 Full,
132 /// "Mon" / "Mo"
133 Short,
134 /// "M" / "M"
135 Letter,
136}
137
138/// Weekday name in the app language; chrono's `%A`/`%a` are always English.
139pub fn weekday_name(day: Weekday, width: WeekdayWidth) -> String {
140 let key = WEEKDAY_KEYS[day.num_days_from_monday() as usize];
141 match width {
142 WeekdayWidth::Full => crate::ui_locale::tr(&format!("calendar.weekday.{key}")),
143 WeekdayWidth::Short => crate::ui_locale::tr(&format!("calendar.weekday_short.{key}")),
144 WeekdayWidth::Letter => crate::ui_locale::tr(&format!("calendar.weekday_short.{key}"))
145 .chars()
146 .next()
147 .map(String::from)
148 .unwrap_or_default(),
149 }
150}
151
152pub fn calendar_range_label(start: NaiveDate, end: NaiveDate) -> String {
153 let style = current_date_style();
154 let day = |date: NaiveDate| {
155 date.format(style.map_or("%-d", |style| style.day_number()))
156 .to_string()
157 };
158 let (start_month, end_month) = (month_name(start), month_name(end));
159 if style.is_none_or(|style| style.month_first()) {
160 let to = format!("{end_month} {}, {}", day(end), end.year());
161 return if start == end {
162 to
163 } else if start.year() != end.year() {
164 format!("{start_month} {}, {} - {to}", day(start), start.year())
165 } else if start.month() != end.month() {
166 format!("{start_month} {} - {to}", day(start))
167 } else {
168 format!("{start_month} {}-{}, {}", day(start), day(end), end.year())
169 };
170 }
171 let to = format!("{} {end_month}, {}", day(end), end.year());
172 if start == end {
173 to
174 } else if start.year() != end.year() {
175 format!("{} {start_month}, {} - {to}", day(start), start.year())
176 } else if start.month() != end.month() {
177 format!("{} {start_month} - {to}", day(start))
178 } else {
179 format!("{}-{to}", day(start))
180 }
181}
182
183/// Numeric day and month in the order of the account's display language, as `Intl.DateTimeFormat` does in Teams.
184pub fn date_style(locale: &str) -> DateStyle {
185 let locale = locale.to_ascii_lowercase();
186 let language = locale.split(['-', '_']).next().unwrap_or_default();
187 let twelve_hour = TWELVE_HOUR_LOCALES.contains(&locale.as_str());
188 let clock = match language {
189 _ if !twelve_hour => "%H:%M",
190 _ if locale == "en-au" || locale == "en-nz" || locale == "en-in" => "%-I:%M %P",
191 _ => "%-I:%M %p",
192 };
193 let (day_month, day_month_year) = match language {
194 _ if locale == "en-us" || locale == "en-ph" || locale == "en-ca" => {
195 ("%-m/%-d", "%-m/%-d/%Y")
196 }
197 "ja" | "zh" => ("%-m/%-d", "%Y/%-m/%-d"),
198 "nl" => ("%-d-%-m", "%-d-%-m-%Y"),
199 "sv" => ("%-d/%-m", "%Y-%m-%d"),
200 language if DOTTED_LOCALES.contains(&language) => ("%-d.%-m.", "%-d.%-m.%Y"),
201 language if PADDED_DOT_LOCALES.contains(&language) => ("%d.%m", "%d.%m.%Y"),
202 _ => ("%d/%m", "%d/%m/%Y"),
203 };
204 DateStyle {
205 day_month,
206 day_month_year,
207 clock,
208 first_day: first_day_for(&locale, language),
209 }
210}
211
212pub fn palette_index(key: &str) -> usize {
213 let mut hash: u32 = 0x811c_9dc5;
214 for byte in key.bytes() {
215 hash ^= u32::from(byte);
216 hash = hash.wrapping_mul(0x0100_0193);
217 }
218 hash as usize % theme::avatar_palette_len()
219}
220
221pub fn initials(name: &str) -> String {
222 let words: Vec<&str> = name
223 .split(|character: char| !character.is_alphanumeric())
224 .filter(|word| !word.is_empty())
225 .collect();
226 let letters: Vec<char> = match words.as_slice() {
227 [] => return "?".to_owned(),
228 [single] => single.chars().take(2).collect(),
229 [first, .., last] => first.chars().take(1).chain(last.chars().take(1)).collect(),
230 };
231 letters.into_iter().flat_map(char::to_uppercase).collect()
232}
233
234/// Teams letters a team tile from the first and last word, split at spaces and underscores, in their own case.
235pub fn team_initials(name: &str) -> String {
236 let words: Vec<&str> = name
237 .split([' ', '_'])
238 .filter(|word| word.chars().next().is_some_and(char::is_alphanumeric))
239 .collect();
240 match words.as_slice() {
241 [] => "?".to_owned(),
242 [single] => single.chars().take(1).collect(),
243 [first, .., last] => first.chars().take(1).chain(last.chars().take(1)).collect(),
244 }
245}
246
247pub fn first_name(name: &str) -> &str {
248 name.split_whitespace().next().unwrap_or(name)
249}
250
251pub fn badge_text(count: u32) -> String {
252 if count > BADGE_CAP {
253 format!("{BADGE_CAP}+")
254 } else {
255 count.to_string()
256 }
257}
258
259fn weekday_label(weekday: Weekday) -> &'static str {
260 match weekday {
261 Weekday::Mon => "Mon",
262 Weekday::Tue => "Tue",
263 Weekday::Wed => "Wed",
264 Weekday::Thu => "Thu",
265 Weekday::Fri => "Fri",
266 Weekday::Sat => "Sat",
267 Weekday::Sun => "Sun",
268 }
269}
270
271pub fn file_size_label(bytes: u64) -> String {
272 const KIB: f64 = 1024.;
273 let value = bytes as f64;
274 if value < KIB {
275 format!("{bytes} B")
276 } else if value < KIB * KIB {
277 format!("{:.0} KB", value / KIB)
278 } else {
279 format!("{:.1} MB", value / (KIB * KIB))
280 }
281}
282
283pub fn short_version(build_id: &str, package_version: &str) -> String {
284 let commit = build_id.split('-').next().unwrap_or(build_id);
285 format!("v{package_version} ({commit})")
286}
287
288pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: impl Into<Zone>) -> String {
289 list_time_label_in(current_date_style(), time, today, offset)
290}
291
292pub fn list_time_label_in(
293 style: Option<DateStyle>,
294 time: DateTime<Utc>,
295 today: NaiveDate,
296 offset: impl Into<Zone>,
297) -> String {
298 let local = offset.into().at(time);
299 let day = local.date_naive();
300 let days_ago = (today - day).num_days();
301 if days_ago <= 0 {
302 local
303 .format(style.map_or("%H:%M", |style| style.clock))
304 .to_string()
305 } else if days_ago <= WEEKDAY_WINDOW_DAYS {
306 weekday_label(local.weekday()).to_owned()
307 } else {
308 local
309 .format(style.map_or("%b %-d", |style| style.day_month))
310 .to_string()
311 }
312}
313
314/// The last activity next to a channel name: the time today, else day and month, with the year once older.
315pub fn channel_time_label(
316 time: DateTime<Utc>,
317 today: NaiveDate,
318 offset: impl Into<Zone>,
319) -> String {
320 channel_time_label_in(current_date_style(), time, today, offset)
321}
322
323pub fn channel_time_label_in(
324 style: Option<DateStyle>,
325 time: DateTime<Utc>,
326 today: NaiveDate,
327 offset: impl Into<Zone>,
328) -> String {
329 let local = offset.into().at(time);
330 let pattern = if local.date_naive() >= today {
331 style.map_or("%H:%M", |style| style.clock)
332 } else if local.year() == today.year() {
333 style.map_or("%b %-d", |style| style.day_month)
334 } else {
335 style.map_or("%b %-d, %Y", |style| style.day_month_year)
336 };
337 local.format(pattern).to_string()
338}
339
340pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: impl Into<Zone>) -> String {
341 post_time_label_in(current_date_style(), time, today, offset)
342}
343
344pub fn post_time_label_in(
345 style: Option<DateStyle>,
346 time: DateTime<Utc>,
347 today: NaiveDate,
348 offset: impl Into<Zone>,
349) -> String {
350 let local = offset.into().at(time);
351 let day = local.date_naive();
352 let days_ago = (today - day).num_days();
353 let clock = local.format(style.map_or("%H:%M", |style| style.clock));
354 let same_year = day.year() == today.year();
355 if days_ago <= 0 {
356 clock.to_string()
357 } else if days_ago == 1 {
358 format!("Yesterday {clock}")
359 } else if days_ago <= WEEKDAY_WINDOW_DAYS {
360 format!("{} {clock}", weekday_label(local.weekday()))
361 } else if let Some(style) = style {
362 let date = if same_year {
363 style.day_month
364 } else {
365 style.day_month_year
366 };
367 format!("{} {clock}", local.format(date))
368 } else if same_year {
369 format!("{} {clock}", local.format("%b %-d"))
370 } else {
371 format!("{} {clock}", local.format("%b %-d, %Y"))
372 }
373}
374
375pub fn day_label(day: NaiveDate, today: NaiveDate) -> String {
376 if day == today {
377 "Today".to_owned()
378 } else if today.pred_opt() == Some(day) {
379 "Yesterday".to_owned()
380 } else {
381 format!(
382 "{}, {}",
383 weekday_label(day.weekday()),
384 day.format("%b %-d, %Y")
385 )
386 }
387}
388
389#[cfg(test)]
390mod tests {
391 use chrono::TimeZone;
392
393 use super::*;
394
395 #[test]
396 fn the_first_day_of_week_follows_the_region() {
397 let first = |locale| {
398 set_date_locale(Some(locale));
399 regional_first_day()
400 };
401 assert_eq!(first("en-US"), Weekday::Sun);
402 assert_eq!(first("de-CH"), Weekday::Mon);
403 assert_eq!(first("en-GB"), Weekday::Mon);
404 assert_eq!(first("ar-SA"), Weekday::Sat);
405 assert_eq!(first("ar-MA"), Weekday::Mon);
406 assert_eq!(first("ja-JP"), Weekday::Sun);
407 set_date_locale(None);
408 assert_eq!(regional_first_day(), Weekday::Mon);
409 }
410
411 #[test]
412 fn calendar_names_follow_the_app_language() {
413 let _guard = crate::ui_locale::locale_test_lock();
414 let date = NaiveDate::from_ymd_opt(2026, 11, 16).unwrap();
415 rust_i18n::set_locale("de");
416 assert_eq!(weekday_name(Weekday::Mon, WeekdayWidth::Full), "Montag");
417 assert_eq!(weekday_name(Weekday::Thu, WeekdayWidth::Short), "Do");
418 assert_eq!(weekday_name(Weekday::Sun, WeekdayWidth::Letter), "S");
419 assert_eq!(month_year_label(date), "November 2026");
420 assert_eq!(
421 month_name(NaiveDate::from_ymd_opt(2026, 3, 1).unwrap()),
422 "März"
423 );
424 rust_i18n::set_locale("en");
425 assert_eq!(weekday_name(Weekday::Mon, WeekdayWidth::Full), "Monday");
426 assert_eq!(weekday_name(Weekday::Thu, WeekdayWidth::Letter), "T");
427 }
428
429 #[test]
430 fn calendar_range_follows_the_account_locale() {
431 let _guard = crate::ui_locale::locale_test_lock();
432 rust_i18n::set_locale("en");
433 let date = |month, day| NaiveDate::from_ymd_opt(2026, month, day).unwrap();
434 set_date_locale(Some("en-GB"));
435 assert_eq!(
436 calendar_range_label(date(11, 9), date(11, 15)),
437 "09-15 November, 2026"
438 );
439 assert_eq!(
440 calendar_range_label(date(11, 30), date(12, 4)),
441 "30 November - 04 December, 2026"
442 );
443 assert_eq!(calendar_day_number(date(11, 9)), "09");
444 set_date_locale(Some("en-US"));
445 assert_eq!(
446 calendar_range_label(date(11, 9), date(11, 13)),
447 "November 9-13, 2026"
448 );
449 assert_eq!(calendar_day_number(date(11, 9)), "9");
450 set_date_locale(Some("de-DE"));
451 assert_eq!(
452 calendar_range_label(date(11, 9), date(11, 9)),
453 "9 November, 2026"
454 );
455 set_date_locale(None);
456 }
457
458 #[test]
459 fn team_tiles_letter_first_and_last_word_like_teams() {
460 assert_eq!(team_initials("e_IT-Support"), "eI");
461 assert_eq!(team_initials("e_ComponentLibrary"), "eC");
462 assert_eq!(team_initials("e_Human Resources"), "eR");
463 assert_eq!(team_initials("e_NLP / AI"), "eA");
464 assert_eq!(team_initials("Platform"), "P");
465 assert_eq!(team_initials(""), "?");
466 }
467
468 #[test]
469 fn os_locale_names_become_language_tags() {
470 assert_eq!(normalize_locale("en-GB").as_deref(), Some("en-GB"));
471 assert_eq!(normalize_locale("en_GB.UTF-8").as_deref(), Some("en-GB"));
472 assert_eq!(normalize_locale("de_DE@euro").as_deref(), Some("de-DE"));
473 assert_eq!(normalize_locale("C"), None);
474 assert_eq!(normalize_locale("POSIX"), None);
475 assert_eq!(normalize_locale(""), None);
476 }
477
478 #[test]
479 fn the_clock_follows_the_display_language() {
480 set_date_locale(Some("en-US"));
481 assert_eq!(clock_format(), "%-I:%M %p");
482 set_date_locale(Some("de-DE"));
483 assert_eq!(clock_format(), "%H:%M");
484 set_date_locale(None);
485 assert_eq!(clock_format(), "%H:%M");
486 }
487
488 fn utc(day: u32, hour: u32) -> DateTime<Utc> {
489 Utc.with_ymd_and_hms(2026, 10, day, hour, 5, 0).unwrap()
490 }
491
492 fn today() -> NaiveDate {
493 NaiveDate::from_ymd_opt(2026, 10, 7).unwrap()
494 }
495
496 fn zero() -> FixedOffset {
497 FixedOffset::east_opt(0).unwrap()
498 }
499
500 #[test]
501 fn channel_times_show_the_clock_today_then_day_and_month_then_the_year() {
502 let style = Some(date_style("en-gb"));
503 let label = |time| channel_time_label_in(style, time, today(), zero());
504 assert_eq!(label(utc(7, 8)), "08:05");
505 assert_eq!(label(utc(1, 8)), "01/10");
506 assert_eq!(
507 label(Utc.with_ymd_and_hms(2025, 10, 23, 8, 0, 0).unwrap()),
508 "23/10/2025"
509 );
510 }
511
512 #[test]
513 fn palette_index_is_stable_and_in_range() {
514 assert_eq!(palette_index("user-1"), palette_index("user-1"));
515 for key in [
516 "a",
517 "b",
518 "demo-ada",
519 "",
520 "00000000-0000-0000-0000-000000000001",
521 ] {
522 assert!(palette_index(key) < theme::avatar_palette_len());
523 }
524 }
525
526 #[test]
527 fn palette_index_spreads_over_several_colors() {
528 let used: std::collections::HashSet<usize> = (0..40)
529 .map(|number| palette_index(&format!("user-{number}")))
530 .collect();
531 assert!(used.len() >= 4);
532 }
533
534 #[test]
535 fn initials_use_first_and_last_word() {
536 assert_eq!(initials("Mara Lindqvist"), "ML");
537 assert_eq!(initials("Ada"), "AD");
538 assert_eq!(initials("anna maria von Berg"), "AB");
539 assert_eq!(initials(" "), "?");
540 assert_eq!(initials("Release planning"), "RP");
541 }
542
543 #[test]
544 fn first_name_takes_the_first_word() {
545 assert_eq!(first_name("Priya Nair"), "Priya");
546 assert_eq!(first_name("Priya"), "Priya");
547 }
548
549 #[test]
550 fn file_sizes_use_binary_units() {
551 assert_eq!(file_size_label(900), "900 B");
552 assert_eq!(file_size_label(48_213), "47 KB");
553 assert_eq!(file_size_label(5 * 1024 * 1024 + 300_000), "5.3 MB");
554 }
555
556 #[test]
557 fn badge_caps_at_99_plus() {
558 assert_eq!(badge_text(1), "1");
559 assert_eq!(badge_text(99), "99");
560 assert_eq!(badge_text(100), "99+");
561 assert_eq!(badge_text(4000), "99+");
562 }
563
564 #[test]
565 fn list_time_is_clock_today_weekday_this_week_date_before() {
566 assert_eq!(list_time_label(utc(7, 13), today(), zero()), "13:05");
567 assert_eq!(list_time_label(utc(5, 13), today(), zero()), "Mon");
568 assert_eq!(list_time_label(utc(6, 9), today(), zero()), "Tue");
569 assert_eq!(list_time_label(utc(1, 13), today(), zero()), "Thu");
570 let september = Utc.with_ymd_and_hms(2026, 9, 30, 13, 0, 0).unwrap();
571 assert_eq!(list_time_label(september, today(), zero()), "Sep 30");
572 }
573
574 #[test]
575 fn list_time_respects_the_offset_for_the_day_boundary() {
576 let plus_two = FixedOffset::east_opt(2 * 3600).unwrap();
577 assert_eq!(list_time_label(utc(6, 23), today(), plus_two), "01:05");
578 }
579
580 #[test]
581 fn short_version_keeps_the_commit_only() {
582 assert_eq!(
583 short_version("687e2dc-20261007T124355Z", "0.1.0"),
584 "v0.1.0 (687e2dc)"
585 );
586 assert_eq!(short_version("dev", "0.1.0"), "v0.1.0 (dev)");
587 }
588
589 #[test]
590 fn post_time_adds_the_day_when_not_today() {
591 assert_eq!(post_time_label(utc(7, 13), today(), zero()), "13:05");
592 assert_eq!(
593 post_time_label(utc(6, 9), today(), zero()),
594 "Yesterday 09:05"
595 );
596 assert_eq!(post_time_label(utc(5, 13), today(), zero()), "Mon 13:05");
597 let september = Utc.with_ymd_and_hms(2026, 9, 30, 8, 42, 0).unwrap();
598 assert_eq!(post_time_label(september, today(), zero()), "Sep 30 08:42");
599 let last_year = Utc.with_ymd_and_hms(2020, 5, 22, 8, 42, 0).unwrap();
600 assert_eq!(
601 post_time_label(last_year, today(), zero()),
602 "May 22, 2020 08:42"
603 );
604 }
605
606 #[test]
607 fn post_time_follows_the_display_language_like_teams() {
608 let september = Utc.with_ymd_and_hms(2026, 9, 24, 20, 54, 0).unwrap();
609 let label =
610 |locale: &str| post_time_label_in(Some(date_style(locale)), september, today(), zero());
611 assert_eq!(label("en-GB"), "24/09 20:54");
612 assert_eq!(label("de-DE"), "24.9. 20:54");
613 assert_eq!(label("en-US"), "9/24 8:54 PM");
614 let last_year = Utc.with_ymd_and_hms(2020, 5, 2, 8, 42, 0).unwrap();
615 assert_eq!(
616 post_time_label_in(Some(date_style("en-GB")), last_year, today(), zero()),
617 "02/05/2020 08:42"
618 );
619 }
620
621 #[test]
622 fn list_time_follows_the_display_language_like_teams() {
623 let september = Utc.with_ymd_and_hms(2026, 9, 24, 20, 54, 0).unwrap();
624 let style = Some(date_style("en-GB"));
625 assert_eq!(
626 list_time_label_in(style, september, today(), zero()),
627 "24/09"
628 );
629 assert_eq!(
630 list_time_label_in(style, utc(7, 13), today(), zero()),
631 "13:05"
632 );
633 }
634
635 #[test]
636 fn day_labels() {
637 assert_eq!(day_label(today(), today()), "Today");
638 assert_eq!(day_label(today().pred_opt().unwrap(), today()), "Yesterday");
639 assert_eq!(
640 day_label(NaiveDate::from_ymd_opt(2026, 10, 1).unwrap(), today()),
641 "Thu, Oct 1, 2026"
642 );
643 }
644}