@@ -18,7 +18,7 @@ use std::fmt::{Debug, Display, Formatter};
1818use std:: str:: FromStr ;
1919use std:: time:: Duration ;
2020
21- use humantime :: { format_duration , parse_duration } ;
21+ use jiff :: SignedDuration ;
2222use reqwest:: header:: HeaderValue ;
2323
2424use crate :: { Error , Result } ;
@@ -87,10 +87,12 @@ impl Parse for bool {
8787
8888impl Parse for Duration {
8989 fn parse ( v : & str ) -> Result < Self > {
90- parse_duration ( v) . map_err ( |_| Error :: Generic {
91- store : "Config" ,
92- source : format ! ( "failed to parse \" {v}\" as Duration" ) . into ( ) ,
93- } )
90+ SignedDuration :: from_str ( v)
91+ . and_then ( Self :: try_from)
92+ . map_err ( |_| Error :: Generic {
93+ store : "Config" ,
94+ source : format ! ( "failed to parse \" {v}\" as Duration" ) . into ( ) ,
95+ } )
9496 }
9597}
9698
@@ -123,7 +125,12 @@ impl Parse for HeaderValue {
123125
124126pub ( crate ) fn fmt_duration ( duration : & ConfigValue < Duration > ) -> String {
125127 match duration {
126- ConfigValue :: Parsed ( v) => format_duration ( * v) . to_string ( ) ,
128+ ConfigValue :: Parsed ( v) => {
129+ // Should only fail if `Duration` has more seconds than what fits
130+ // into i64.
131+ let d = SignedDuration :: try_from ( * v) . unwrap ( ) ;
132+ format ! ( "{:#}" , d)
133+ }
127134 ConfigValue :: Deferred ( v) => v. clone ( ) ,
128135 }
129136}
@@ -140,4 +147,13 @@ mod tests {
140147 assert_eq ! ( Duration :: parse( "60 s" ) . unwrap( ) , duration) ;
141148 assert_eq ! ( Duration :: parse( "60s" ) . unwrap( ) , duration)
142149 }
150+
151+ #[ test]
152+ fn test_fmt_duration ( ) {
153+ let dur = ConfigValue :: Parsed ( Duration :: new ( 9420 , 0 ) ) ;
154+ assert_eq ! ( "2h 37m" , fmt_duration( & dur) ) ;
155+
156+ let dur = ConfigValue :: Parsed ( Duration :: new ( 0 , 32_000_000 ) ) ;
157+ assert_eq ! ( "32ms" , fmt_duration( & dur) ) ;
158+ }
143159}
0 commit comments