File tree Expand file tree Collapse file tree 2 files changed +18
-11
lines changed
Expand file tree Collapse file tree 2 files changed +18
-11
lines changed 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]
You can’t perform that action at this time.
0 commit comments