mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 00:48:35 +00:00
Fix 682 smarter times in log (#683)
This commit is contained in:
parent
dfc6496f27
commit
4cebb41cf4
3 changed files with 35 additions and 4 deletions
|
|
@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
## Added
|
||||
- warning if commit subject line gets too long ([#478](https://github.com/extrawurst/gitui/issues/478))
|
||||
|
||||
## Changed
|
||||
- smarter log timestamps ([#682](https://github.com/extrawurst/gitui/issues/682))
|
||||
|
||||
## [0.15.0] - 2020-04-27
|
||||
|
||||
**file blame**
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use crate::{
|
|||
};
|
||||
use anyhow::Result;
|
||||
use asyncgit::sync::Tags;
|
||||
use chrono::{DateTime, Local};
|
||||
use crossterm::event::Event;
|
||||
use std::{
|
||||
borrow::Cow, cell::Cell, cmp, convert::TryFrom, time::Instant,
|
||||
|
|
@ -193,6 +194,7 @@ impl CommitList {
|
|||
tags: Option<String>,
|
||||
theme: &Theme,
|
||||
width: usize,
|
||||
now: DateTime<Local>,
|
||||
) -> Spans<'a> {
|
||||
let mut txt: Vec<Span> = Vec::new();
|
||||
txt.reserve(ELEMENTS_PER_LINE);
|
||||
|
|
@ -211,7 +213,7 @@ impl CommitList {
|
|||
|
||||
// commit timestamp
|
||||
txt.push(Span::styled(
|
||||
Cow::from(e.time.as_str()),
|
||||
Cow::from(e.time_to_string(now)),
|
||||
theme.commit_time(selected),
|
||||
));
|
||||
|
||||
|
|
@ -254,6 +256,8 @@ impl CommitList {
|
|||
|
||||
let mut txt: Vec<Spans> = Vec::with_capacity(height);
|
||||
|
||||
let now = Local::now();
|
||||
|
||||
for (idx, e) in self
|
||||
.items
|
||||
.iter()
|
||||
|
|
@ -272,6 +276,7 @@ impl CommitList {
|
|||
tags,
|
||||
&self.theme,
|
||||
width,
|
||||
now,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use super::time_to_string;
|
||||
use asyncgit::sync::{CommitId, CommitInfo};
|
||||
use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc};
|
||||
use std::slice::Iter;
|
||||
|
||||
static SLICE_OFFSET_RELOAD_THRESHOLD: usize = 100;
|
||||
|
||||
pub struct LogEntry {
|
||||
pub time: String,
|
||||
pub time: DateTime<Local>,
|
||||
pub author: String,
|
||||
pub msg: String,
|
||||
pub hash_short: String,
|
||||
|
|
@ -14,16 +14,39 @@ pub struct LogEntry {
|
|||
|
||||
impl From<CommitInfo> for LogEntry {
|
||||
fn from(c: CommitInfo) -> Self {
|
||||
let time =
|
||||
DateTime::<Local>::from(DateTime::<Utc>::from_utc(
|
||||
NaiveDateTime::from_timestamp(c.time, 0),
|
||||
Utc,
|
||||
));
|
||||
Self {
|
||||
author: c.author,
|
||||
msg: c.message,
|
||||
time: time_to_string(c.time, true),
|
||||
time,
|
||||
hash_short: c.id.get_short_string(),
|
||||
id: c.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LogEntry {
|
||||
pub fn time_to_string(&self, now: DateTime<Local>) -> String {
|
||||
let delta = now - self.time;
|
||||
if delta < Duration::minutes(30) {
|
||||
let delta_str = if delta < Duration::minutes(1) {
|
||||
"<1m ago".to_string()
|
||||
} else {
|
||||
format!("{:0>2}m ago", delta.num_minutes())
|
||||
};
|
||||
format!("{: <10}", delta_str)
|
||||
} else if self.time.date() == now.date() {
|
||||
self.time.format("%T ").to_string()
|
||||
} else {
|
||||
self.time.format("%Y-%m-%d").to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Default)]
|
||||
pub struct ItemBatch {
|
||||
|
|
|
|||
Loading…
Reference in a new issue