File tree Expand file tree Collapse file tree 7 files changed +24
-17
lines changed Expand file tree Collapse file tree 7 files changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ fn run(args: Args) -> anyhow::Result<()> {
150150 commit_ref. author . actor ( ) . write_to ( & mut buf) ?;
151151 buf. into ( )
152152 } ,
153- time : commit_ref. author . time ( ) ?. format_or_raw ( format:: DEFAULT ) ,
153+ time : commit_ref. author . time ( ) ?. format_or_unix ( format:: DEFAULT ) ,
154154 message : commit_ref. message . to_owned ( ) ,
155155 } )
156156 } ) ,
Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ mod trace_path {
180180 out,
181181 "{}| {} | {} {} {} ➡ {}" ,
182182 self . diff. unwrap_or_default( ) . format( max_diff_lines) ,
183- self . commit_time. format_or_raw ( gix:: date:: time:: format:: SHORT ) ,
183+ self . commit_time. format_or_unix ( gix:: date:: time:: format:: SHORT ) ,
184184 id. shorten_or_id( ) ,
185185 self . mode. as_str( ) ,
186186 path_by_id[ & source_id] ,
@@ -192,7 +192,7 @@ mod trace_path {
192192 out,
193193 "{}| {} | {} {} {}" ,
194194 self . diff. unwrap_or_default( ) . format( max_diff_lines) ,
195- self . commit_time. format_or_raw ( gix:: date:: time:: format:: SHORT ) ,
195+ self . commit_time. format_or_unix ( gix:: date:: time:: format:: SHORT ) ,
196196 id. shorten_or_id( ) ,
197197 self . mode. as_str( ) ,
198198 path_by_id[ & self . file_id]
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ impl delegate::Revision for Explain<'_> {
8888 ReflogLookup :: Date ( time) => writeln ! (
8989 self . out,
9090 "Find entry closest to time {} in reflog of '{}' reference" ,
91- time. format_or_raw ( gix:: date:: time:: format:: ISO8601 ) ,
91+ time. format_or_unix ( gix:: date:: time:: format:: ISO8601 ) ,
9292 ref_name
9393 )
9494 . ok ( ) ,
Original file line number Diff line number Diff line change @@ -42,10 +42,11 @@ impl Time {
4242 self . format_inner ( format. into ( ) )
4343 }
4444
45- /// Like [`Self::format()`], but on time conversion error, produce the [RAW] format instead to make it
46- /// infallible.
47- pub fn format_or_raw ( & self , format : impl Into < Format > ) -> String {
48- self . format_inner ( format. into ( ) ) . unwrap_or_else ( |_| self . to_string ( ) )
45+ /// Like [`Self::format()`], but on time conversion error, produce the [UNIX] format instead
46+ /// to make it infallible.
47+ pub fn format_or_unix ( & self , format : impl Into < Format > ) -> String {
48+ self . format_inner ( format. into ( ) )
49+ . unwrap_or_else ( |_| self . seconds . to_string ( ) )
4950 }
5051
5152 fn format_inner ( & self , format : Format ) -> Result < String , jiff:: Error > {
Original file line number Diff line number Diff line change @@ -66,15 +66,21 @@ fn git_rfc2822() -> gix_testtools::Result {
6666
6767#[ test]
6868fn default ( ) -> gix_testtools:: Result {
69+ assert_eq ! ( time( ) . format( format:: GITOXIDE ) ?, "Fri Nov 30 1973 00:03:09 +0230" ) ;
70+ assert_eq ! ( time_dec1( ) . format( format:: GITOXIDE ) ?, "Sat Dec 01 1973 00:03:09 +0230" ) ;
71+ Ok ( ( ) )
72+ }
73+
74+ #[ test]
75+ fn format_or_unix ( ) {
6976 assert_eq ! (
70- time ( ) . format ( gix_date :: time :: format :: GITOXIDE ) ? ,
71- "Fri Nov 30 1973 00:03:09 +0230"
72- ) ;
73- assert_eq ! (
74- time_dec1 ( ) . format ( gix_date :: time :: format:: GITOXIDE ) ? ,
75- "Sat Dec 01 1973 00:03:09 +0230 "
77+ Time {
78+ seconds : 42 ,
79+ offset : 7200 * 60
80+ }
81+ . format_or_unix ( format:: GITOXIDE ) ,
82+ "42 "
7683 ) ;
77- Ok ( ( ) )
7884}
7985
8086#[ test]
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ impl Personas {
140140 . and_then ( |date| gix_date:: parse ( date, Some ( SystemTime :: now ( ) ) ) . ok ( ) )
141141 } )
142142 . or_else ( || Some ( gix_date:: Time :: now_local_or_utc ( ) ) )
143- . map ( |time| time. format_or_raw ( gix_date:: time:: Format :: Raw ) )
143+ . map ( |time| time. format_or_unix ( gix_date:: time:: Format :: Raw ) )
144144 } ;
145145
146146 let fallback = (
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ impl std::fmt::Display for CandidateInfo {
4444 "commit {} {title:?}" ,
4545 gix_date:: parse_header( date)
4646 . unwrap_or_default( )
47- . format_or_raw ( gix_date:: time:: format:: SHORT )
47+ . format_or_unix ( gix_date:: time:: format:: SHORT )
4848 )
4949 }
5050 }
You can’t perform that action at this time.
0 commit comments