diff --git a/src/ui.rs b/src/ui.rs index 294c8f6..f3bbd04 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,10 +1,12 @@ +use std::rc::Rc; + +use chrono::{self, DateTime}; use ratatui::backend::Backend; use ratatui::layout::{Constraint, Direction, Layout, Rect}; use ratatui::style::{Color, Modifier, Style}; use ratatui::text::{Span, Text}; use ratatui::widgets::{Block, Borders, LineGauge, List, ListItem, Paragraph, Wrap}; use ratatui::Frame; -use std::rc::Rc; use crate::app::AppImpl; use crate::modes::{Mode, ReadMode, Selected}; @@ -12,6 +14,9 @@ use crate::rss::EntryMeta; const PINK: Color = Color::Rgb(255, 150, 167); +/// Date format used that is YY-MM-DD HH:MM:SS. +const DATETIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S"; + pub fn predraw(f: &Frame) -> Rc<[Rect]> { Layout::default() .constraints([Constraint::Percentage(30), Constraint::Percentage(70)].as_ref()) @@ -241,7 +246,7 @@ where .current_feed .as_ref() .and_then(|feed| feed.refreshed_at) - .map(|timestamp| timestamp.to_string()) + .map(|timestamp| format_time(×tamp)) .or_else(|| Some("Never refreshed".to_string())) { text.push_str("Refreshed at: "); @@ -511,6 +516,11 @@ where } } +/// Format the given time in local timezone with seconds precision. +fn format_time(t: &DateTime) -> String { + t.with_timezone(&chrono::Local).format(DATETIME_FORMAT).to_string() +} + fn error_text(errors: &[anyhow::Error]) -> String { errors .iter()