Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Improve timestamp format function
cloudhead committed 2 years ago
commit bf64fde8a143e0a419f7efbed72389e3dbe89f04
parent 5cb4ad4622a401fd686cd1c801175686ec4a5805
6 files changed +19 -10
modified radicle-cli/src/commands/id.rs
@@ -413,7 +413,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
                let title = term::label(r.title.to_string());
                let (alias, author) =
                    term::format::Author::new(r.author.public_key(), &profile).labels();
-
                let timestamp = term::format::timestamp(&r.timestamp).into();
+
                let timestamp = term::format::timestamp(r.timestamp).into();

                revisions.push([icon, id, title, alias, author, state, timestamp]);
            }
modified radicle-cli/src/commands/issue.rs
@@ -518,7 +518,7 @@ fn list<R: WriteRepository + cob::Store>(
            } else {
                term::format::primary(assigned.to_string()).dim().into()
            },
-
            term::format::timestamp(&issue.timestamp())
+
            term::format::timestamp(issue.timestamp())
                .dim()
                .italic()
                .into(),
modified radicle-cli/src/commands/patch/list.rs
@@ -111,7 +111,7 @@ pub fn row(
        term::format::secondary(term::format::oid(revision.head())).into(),
        term::format::positive(format!("+{}", stats.insertions())).into(),
        term::format::negative(format!("-{}", stats.deletions())).into(),
-
        term::format::timestamp(&patch.updated_at())
+
        term::format::timestamp(patch.updated_at())
            .dim()
            .italic()
            .into(),
@@ -220,7 +220,7 @@ pub fn timeline(
    let mut lines = Vec::new();
    for (time, mut line) in timeline.into_iter() {
        line.push(term::Label::space());
-
        line.push(term::format::dim(term::format::timestamp(&time)));
+
        line.push(term::format::dim(term::format::timestamp(time)));
        lines.push(line);
    }

modified radicle-cli/src/terminal/comment.rs
@@ -18,7 +18,7 @@ pub fn header(
        .child(term::Line::spaced([
            alias,
            nid,
-
            term::format::timestamp(&comment.timestamp()).dim().into(),
+
            term::format::timestamp(comment.timestamp()).dim().into(),
        ]))
        .child(term::Line::new(term::Label::space()))
        .child(term::Line::spaced([term::format::oid(*id)
modified radicle-cli/src/terminal/format.rs
@@ -1,4 +1,6 @@
-
use std::{fmt, time};
+
use std::fmt;
+

+
use localtime::LocalTime;

pub use radicle_term::format::*;
pub use radicle_term::{style, Paint};
@@ -61,12 +63,13 @@ pub fn visibility(v: &Visibility) -> Paint<&str> {
}

/// Format a timestamp.
-
pub fn timestamp(time: &Timestamp) -> Paint<String> {
+
pub fn timestamp(time: impl Into<LocalTime>) -> Paint<String> {
+
    let time: LocalTime = time.into();
+
    let now: LocalTime = Timestamp::now().into();
+
    let duration = now - time;
    let fmt = timeago::Formatter::new();
-
    let now = Timestamp::now();
-
    let duration = time::Duration::from_secs(now.as_secs() - time.as_secs());

-
    Paint::new(fmt.convert(duration))
+
    Paint::new(fmt.convert(duration.into()))
}

/// Identity formatter that takes a profile and displays it as
modified radicle/src/cob/common.rs
@@ -47,6 +47,12 @@ impl From<LocalTime> for Timestamp {
    }
}

+
impl From<Timestamp> for LocalTime {
+
    fn from(time: Timestamp) -> Self {
+
        time.0
+
    }
+
}
+

impl Deref for Timestamp {
    type Target = LocalTime;