@@ -18,7 +18,7 @@ use std::fmt::{Debug, Display, Formatter};
18
18
use std:: str:: FromStr ;
19
19
use std:: time:: Duration ;
20
20
21
- use humantime :: { format_duration , parse_duration } ;
21
+ use jiff :: SignedDuration ;
22
22
use reqwest:: header:: HeaderValue ;
23
23
24
24
use crate :: { Error , Result } ;
@@ -87,10 +87,12 @@ impl Parse for bool {
87
87
88
88
impl Parse for Duration {
89
89
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
+ } )
94
96
}
95
97
}
96
98
@@ -123,7 +125,12 @@ impl Parse for HeaderValue {
123
125
124
126
pub ( crate ) fn fmt_duration ( duration : & ConfigValue < Duration > ) -> String {
125
127
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
+ }
127
134
ConfigValue :: Deferred ( v) => v. clone ( ) ,
128
135
}
129
136
}
@@ -140,4 +147,13 @@ mod tests {
140
147
assert_eq ! ( Duration :: parse( "60 s" ) . unwrap( ) , duration) ;
141
148
assert_eq ! ( Duration :: parse( "60s" ) . unwrap( ) , duration)
142
149
}
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
+ }
143
159
}
0 commit comments