@@ -570,6 +570,38 @@ pub fn format_relative_time(time: Time) -> String {
570570 }
571571}
572572
573+ /// Format a time as a relative time string (e.g., "21 hours ago", "4 days ago")
574+ pub fn format_relative_time ( time : Time ) -> String {
575+ let commit_time =
576+ Local :: from_offset ( & FixedOffset :: east ( time. offset_minutes ( ) ) ) . timestamp ( time. seconds ( ) , 0 ) ;
577+ let now = Local :: now ( ) ;
578+ let duration = now. signed_duration_since ( commit_time) ;
579+
580+ let seconds = duration. num_seconds ( ) ;
581+ let minutes = duration. num_minutes ( ) ;
582+ let hours = duration. num_hours ( ) ;
583+ let days = duration. num_hours ( ) / 24 ;
584+ let weeks = days / 7 ;
585+ let months = days / 30 ;
586+ let years = days / 365 ;
587+
588+ if seconds < 60 {
589+ format ! ( "{} seconds ago" , seconds)
590+ } else if minutes < 60 {
591+ format ! ( "{} minutes ago" , minutes)
592+ } else if hours < 24 {
593+ format ! ( "{} hours ago" , hours)
594+ } else if days < 7 {
595+ format ! ( "{} days ago" , days)
596+ } else if weeks < 4 {
597+ format ! ( "{} weeks ago" , weeks)
598+ } else if months < 12 {
599+ format ! ( "{} months ago" , months)
600+ } else {
601+ format ! ( "{} years ago" , years)
602+ }
603+ }
604+
573605fn append_wrapped ( vec : & mut Vec < String > , str : String , wrapping : & Option < Options > ) {
574606 if str. is_empty ( ) {
575607 vec. push ( str) ;
0 commit comments