@@ -2,8 +2,6 @@ use crate::info::author::Author;
2
2
use crate :: info:: head_refs:: HeadRefs ;
3
3
use anyhow:: { Context , Result } ;
4
4
use byte_unit:: Byte ;
5
- use chrono:: { FixedOffset , TimeZone } ;
6
- use chrono_humanize:: HumanTime ;
7
5
use git2:: Time ;
8
6
use git2:: {
9
7
BranchType , Commit , Repository , RepositoryOpenFlags , Signature , Status , StatusOptions ,
@@ -12,6 +10,10 @@ use git2::{
12
10
use regex:: Regex ;
13
11
use std:: collections:: HashMap ;
14
12
use std:: path:: Path ;
13
+ use time:: format_description:: well_known:: Rfc3339 ;
14
+ use time:: OffsetDateTime ;
15
+
16
+ use time_humanize:: HumanTime ;
15
17
16
18
pub struct Repo < ' a > {
17
19
repo : & ' a Repository ,
@@ -337,23 +339,21 @@ fn bytes_to_human_readable(bytes: u128) -> String {
337
339
}
338
340
339
341
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 ) ;
347
342
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 ( ) ) )
351
344
} else {
352
- let ht = HumanTime :: from ( dt_with_tz ) ;
345
+ let ht = HumanTime :: from_duration_since_timestamp ( time . seconds ( ) . unsigned_abs ( ) ) ;
353
346
format ! ( "{}" , ht)
354
347
}
355
348
}
356
349
350
+ fn to_rfc3339 < T > ( dt : T ) -> String
351
+ where
352
+ T : Into < OffsetDateTime > ,
353
+ {
354
+ dt. into ( ) . format ( & Rfc3339 ) . unwrap ( )
355
+ }
356
+
357
357
pub fn is_valid ( repo_path : & str ) -> Result < bool > {
358
358
let repo = Repository :: open_ext ( repo_path, RepositoryOpenFlags :: empty ( ) , Vec :: < & Path > :: new ( ) ) ;
359
359
Ok ( repo. is_ok ( ) && !repo?. is_bare ( ) )
0 commit comments