Replace chrono dependency by time

This commit is contained in:
Joscha 2022-07-24 17:12:22 +02:00
parent 4e014168b4
commit 8bc7af0d3f
11 changed files with 76 additions and 76 deletions

View file

@ -3,7 +3,7 @@
use std::collections::{vec_deque, VecDeque};
use std::iter;
use chrono::{DateTime, Utc};
use time::OffsetDateTime;
use toss::styled::Styled;
use crate::macros::some_or_return;
@ -50,7 +50,7 @@ pub enum BlockBody<I> {
#[derive(Debug, Clone)]
pub struct Block<I> {
pub line: i32,
pub time: Option<DateTime<Utc>>,
pub time: Option<OffsetDateTime>,
pub indent: usize,
pub body: BlockBody<I>,
}
@ -75,7 +75,7 @@ impl<I> Block<I> {
}
pub fn msg(
time: DateTime<Utc>,
time: OffsetDateTime,
indent: usize,
id: I,
nick: Styled,
@ -92,7 +92,7 @@ impl<I> Block<I> {
}
}
pub fn placeholder(time: Option<DateTime<Utc>>, indent: usize, id: I) -> Self {
pub fn placeholder(time: Option<OffsetDateTime>, indent: usize, id: I) -> Self {
Self {
line: 0,
time,

View file

@ -1,6 +1,6 @@
//! Rendering blocks to a [`Frame`].
use chrono::{DateTime, Utc};
use time::OffsetDateTime;
use toss::frame::{Frame, Pos};
use toss::styled::Styled;
@ -10,7 +10,7 @@ use super::blocks::{Block, BlockBody, MsgBlock, MsgContent};
use super::{util, InnerTreeViewState};
impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
fn render_time(frame: &mut Frame, line: i32, time: Option<DateTime<Utc>>, is_cursor: bool) {
fn render_time(frame: &mut Frame, line: i32, time: Option<OffsetDateTime>, is_cursor: bool) {
let pos = Pos::new(0, line);
let style = if is_cursor {
util::style_time_inverted()
@ -19,7 +19,9 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
};
if let Some(time) = time {
let time = format!("{}", time.format(util::TIME_FORMAT));
let time = time
.format(util::TIME_FORMAT)
.expect("time can be formatted");
frame.write(pos, (&time, style));
} else {
frame.write(pos, (util::TIME_EMPTY, style));
@ -51,7 +53,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
fn draw_msg_block(
frame: &mut Frame,
line: i32,
time: Option<DateTime<Utc>>,
time: Option<OffsetDateTime>,
indent: usize,
msg: &MsgBlock<M::Id>,
is_cursor: bool,

View file

@ -1,10 +1,13 @@
//! Constants and helper functions.
use crossterm::style::{ContentStyle, Stylize};
use time::format_description::FormatItem;
use time::macros::format_description;
use toss::frame::Frame;
use toss::styled::Styled;
pub const TIME_FORMAT: &str = "%F %R ";
pub const TIME_FORMAT: &[FormatItem<'_>] =
format_description!("[year]-[month]-[day] [hour]:[minute] ");
pub const TIME_EMPTY: &str = " ";
pub const TIME_WIDTH: usize = TIME_EMPTY.len();