cli: Improve timestamp format function
This commit is contained in:
parent
5cb4ad4622
commit
bf64fde8a1
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue