Skip to content

Commit 45d850e

Browse files
committed
fix new clippy warnings
1 parent 5430a4d commit 45d850e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/components/utils/logitems.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ pub struct LogEntry {
2222

2323
impl From<CommitInfo> for LogEntry {
2424
fn from(c: CommitInfo) -> Self {
25-
let time =
25+
let hash_short = c.id.get_short_string().into();
26+
27+
let time = {
28+
let date = NaiveDateTime::from_timestamp_opt(c.time, 0);
29+
if date.is_none() {
30+
log::error!("error reading commit date: {hash_short} - timestamp: {}",c.time);
31+
}
2632
DateTime::<Local>::from(DateTime::<Utc>::from_utc(
27-
NaiveDateTime::from_timestamp(c.time, 0),
33+
date.unwrap_or_default(),
2834
Utc,
29-
));
35+
))
36+
};
3037

3138
let author = c.author;
3239
#[allow(unused_mut)]
@@ -40,7 +47,7 @@ impl From<CommitInfo> for LogEntry {
4047
author: author.into(),
4148
msg: msg.into(),
4249
time,
43-
hash_short: c.id.get_short_string().into(),
50+
hash_short,
4451
id: c.id,
4552
}
4653
}
@@ -56,7 +63,7 @@ impl LogEntry {
5663
format!("{:0>2}m ago", delta.num_minutes())
5764
};
5865
format!("{delta_str: <10}")
59-
} else if self.time.date() == now.date() {
66+
} else if self.time.date_naive() == now.date_naive() {
6067
self.time.format("%T ").to_string()
6168
} else {
6269
self.time.format("%Y-%m-%d").to_string()

src/components/utils/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ macro_rules! try_or_popup {
2626
/// helper func to convert unix time since epoch to formated time string in local timezone
2727
pub fn time_to_string(secs: i64, short: bool) -> String {
2828
let time = DateTime::<Local>::from(DateTime::<Utc>::from_utc(
29-
NaiveDateTime::from_timestamp(secs, 0),
29+
NaiveDateTime::from_timestamp_opt(secs, 0)
30+
.unwrap_or_default(),
3031
Utc,
3132
));
33+
3234
time.format(if short {
3335
"%Y-%m-%d"
3436
} else {

0 commit comments

Comments
 (0)