Skip to content

Commit 6ceb13f

Browse files
committed
#526 Remove chrono as dependency and swiched out with time-rs and time-humanize, refactored code to display creaton of repo time
1 parent 689a0ab commit 6ceb13f

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

Diff for: Cargo.lock

+22-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ anyhow = "1.0"
3030
askalono = "0.4.3"
3131
byte-unit = "4.0.12"
3232
bytecount = "0.6.2"
33-
chrono = "0.4"
34-
chrono-humanize = "0.2.1"
33+
time-humanize = {version="0.1.2", features = ["time"]}
34+
time = { version = "0.3.5", features = ["formatting"]}
3535
clap = {version = "2.33.3", features = ["wrap_help"]}
3636
color_quant = "1.1.0"
3737
colored = "2.0.0"

Diff for: src/info/repo.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use crate::info::author::Author;
22
use crate::info::head_refs::HeadRefs;
33
use anyhow::{Context, Result};
44
use byte_unit::Byte;
5-
use chrono::{FixedOffset, TimeZone};
6-
use chrono_humanize::HumanTime;
75
use git2::Time;
86
use git2::{
97
BranchType, Commit, Repository, RepositoryOpenFlags, Signature, Status, StatusOptions,
@@ -12,6 +10,10 @@ use git2::{
1210
use regex::Regex;
1311
use std::collections::HashMap;
1412
use std::path::Path;
13+
use time::format_description::well_known::Rfc3339;
14+
use time::OffsetDateTime;
15+
16+
use time_humanize::HumanTime;
1517

1618
pub struct Repo<'a> {
1719
repo: &'a Repository,
@@ -337,23 +339,21 @@ fn bytes_to_human_readable(bytes: u128) -> String {
337339
}
338340

339341
fn git_time_to_formatted_time(time: &Time, iso_time: bool) -> String {
340-
let (offset, _) = match time.offset_minutes() {
341-
n if n < 0 => (-n, '-'),
342-
n => (n, '+'),
343-
};
344-
345-
let offset = FixedOffset::west(offset);
346-
let dt_with_tz = offset.timestamp(time.seconds(), 0);
347342
if iso_time {
348-
dt_with_tz
349-
.with_timezone(&chrono::Utc)
350-
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
343+
to_rfc3339(HumanTime::from(time.seconds()))
351344
} else {
352-
let ht = HumanTime::from(dt_with_tz);
345+
let ht = HumanTime::from_duration_since_timestamp(time.seconds().unsigned_abs());
353346
format!("{}", ht)
354347
}
355348
}
356349

350+
fn to_rfc3339<T>(dt: T) -> String
351+
where
352+
T: Into<OffsetDateTime>,
353+
{
354+
dt.into().format(&Rfc3339).unwrap()
355+
}
356+
357357
pub fn is_valid(repo_path: &str) -> Result<bool> {
358358
let repo = Repository::open_ext(repo_path, RepositoryOpenFlags::empty(), Vec::<&Path>::new());
359359
Ok(repo.is_ok() && !repo?.is_bare())

0 commit comments

Comments
 (0)