@@ -139,11 +139,11 @@ impl RelativeDuration {
139
139
/// use chronoutil::RelativeDuration;
140
140
///
141
141
/// assert_eq!(
142
- /// RelativeDuration::from_iso_8601 ("P1Y").unwrap(),
142
+ /// RelativeDuration::parse_from_iso8601 ("P1Y").unwrap(),
143
143
/// RelativeDuration::years(1),
144
144
/// );
145
145
/// ```
146
- pub fn from_iso_8601 ( input : & str ) -> Result < RelativeDuration , String > {
146
+ pub fn parse_from_iso8601 ( input : & str ) -> Result < RelativeDuration , String > {
147
147
let input = input
148
148
. strip_prefix ( 'P' )
149
149
. ok_or_else ( || "duration was not prefixed with P" . to_string ( ) ) ?;
@@ -174,11 +174,11 @@ impl RelativeDuration {
174
174
/// use chronoutil::RelativeDuration;
175
175
///
176
176
/// assert_eq!(
177
- /// RelativeDuration::years(1).to_iso_8601 (),
177
+ /// RelativeDuration::years(1).format_to_iso8601 (),
178
178
/// "P1Y",
179
179
/// );
180
180
/// ```
181
- pub fn to_iso_8601 ( & self ) -> String {
181
+ pub fn format_to_iso8601 ( & self ) -> String {
182
182
let years = self . months as i64 / 12 ;
183
183
let months = self . months as i64 % 12 ;
184
184
@@ -301,7 +301,10 @@ mod tests {
301
301
]
302
302
. iter ( )
303
303
. for_each ( |( input, expected) | {
304
- assert_eq ! ( RelativeDuration :: from_iso_8601( input) . unwrap( ) , * expected)
304
+ assert_eq ! (
305
+ RelativeDuration :: parse_from_iso8601( input) . unwrap( ) ,
306
+ * expected
307
+ )
305
308
} )
306
309
}
307
310
@@ -333,7 +336,7 @@ mod tests {
333
336
) ,
334
337
]
335
338
. iter ( )
336
- . for_each ( |( input, expected) | assert_eq ! ( input. to_iso_8601 ( ) , * expected) )
339
+ . for_each ( |( input, expected) | assert_eq ! ( input. format_to_iso8601 ( ) , * expected) )
337
340
}
338
341
339
342
proptest ! {
@@ -344,19 +347,19 @@ mod tests {
344
347
nanos in 0u32 ..1_000_000_000
345
348
) {
346
349
let d = RelativeDuration :: months( months) . with_duration( Duration :: new( secs, nanos) . unwrap( ) ) ;
347
- prop_assert_eq!( d, RelativeDuration :: from_iso_8601 ( & ( d. to_iso_8601 ( ) ) ) . unwrap( ) ) ;
350
+ prop_assert_eq!( d, RelativeDuration :: parse_from_iso8601 ( & ( d. format_to_iso8601 ( ) ) ) . unwrap( ) ) ;
348
351
}
349
352
350
353
#[ test]
351
354
fn proptest_parse_and_back(
352
355
s in r"P(?:[1-9][0-9]{0,7}Y)?(?:(?:[1-9]|1[0-1])M)?(?:(?:[1-9]|[1-2][0-9])D)?(?:T(?:(?:[1-9]|1[0-9]|2[0-3])H)(?:(?:[1-9]|[1-5][0-9])M)(?:(?:(?:[1-9]|[1-5][0-9])|(?:(?:[0-9]|[1-5][0-9])\.[0-9]{0,8}[1-9]))S))?" ,
353
356
) {
354
- prop_assert_eq!( s. clone( ) , RelativeDuration :: from_iso_8601 ( & s) . unwrap( ) . to_iso_8601 ( ) ) ;
357
+ prop_assert_eq!( s. clone( ) , RelativeDuration :: parse_from_iso8601 ( & s) . unwrap( ) . format_to_iso8601 ( ) ) ;
355
358
}
356
359
357
360
#[ test]
358
361
fn proptest_parse_doesnt_panic( s in r"//PC*" ) {
359
- let _ = RelativeDuration :: from_iso_8601 ( & s) ;
362
+ let _ = RelativeDuration :: parse_from_iso8601 ( & s) ;
360
363
}
361
364
}
362
365
}
0 commit comments