Format timestamps more tersely in the notification panel

Co-authored-by: Piotr <piotr@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-10-23 14:34:38 +02:00
parent 8766e5f0d0
commit 2f0eaafc39
3 changed files with 53 additions and 29 deletions

View file

@ -1,6 +1,5 @@
use crate::{
channel_view::ChannelView, format_timestamp, is_channels_feature_enabled, render_avatar,
ChatPanelSettings,
channel_view::ChannelView, is_channels_feature_enabled, render_avatar, ChatPanelSettings,
};
use anyhow::Result;
use call::ActiveCall;
@ -874,6 +873,31 @@ impl Panel for ChatPanel {
}
}
fn format_timestamp(
mut timestamp: OffsetDateTime,
mut now: OffsetDateTime,
local_timezone: UtcOffset,
) -> String {
timestamp = timestamp.to_offset(local_timezone);
now = now.to_offset(local_timezone);
let today = now.date();
let date = timestamp.date();
let mut hour = timestamp.hour();
let mut part = "am";
if hour > 12 {
hour -= 12;
part = "pm";
}
if date == today {
format!("{:02}:{:02}{}", hour, timestamp.minute(), part)
} else if date.next_day() == Some(today) {
format!("yesterday at {:02}:{:02}{}", hour, timestamp.minute(), part)
} else {
format!("{:02}/{}/{}", date.month() as u32, date.day(), date.year())
}
}
fn render_icon_button<V: View>(style: &IconButton, svg_path: &'static str) -> impl Element<V> {
Svg::new(svg_path)
.with_color(style.color)