@@ -50,25 +50,6 @@ pub static MAX: Duration = Duration { days: MAX_DAYS, secs: SECS_PER_DAY as u32
50
50
nanos : NANOS_PER_SEC as u32 - 1 } ;
51
51
52
52
impl Duration {
53
- /// Makes a new `Duration` with given number of days, seconds and nanoseconds.
54
- ///
55
- /// Fails when the duration is out of bounds.
56
- #[ inline]
57
- pub fn new ( days : i32 , secs : i32 , nanos : i32 ) -> Duration {
58
- Duration :: new_opt ( days, secs, nanos) . expect ( "Duration::new out of bounds" )
59
- }
60
-
61
- /// Makes a new `Duration` with given number of days, seconds and nanoseconds.
62
- ///
63
- /// Returns `None` when the duration is out of bounds.
64
- pub fn new_opt ( days : i32 , secs : i32 , nanos : i32 ) -> Option < Duration > {
65
- let ( secs_, nanos) = div_mod_floor ( nanos, NANOS_PER_SEC ) ;
66
- let secs = try_opt ! ( secs. checked_add( & secs_) ) ;
67
- let ( days_, secs) = div_mod_floor ( secs, SECS_PER_DAY ) ;
68
- let days = try_opt ! ( days. checked_add( & days_) . and_then( |v| v. to_i32( ) ) ) ;
69
- Some ( Duration { days : days, secs : secs as u32 , nanos : nanos as u32 } )
70
- }
71
-
72
53
/// Makes a new `Duration` with given number of weeks.
73
54
/// Equivalent to `Duration::new(weeks * 7, 0, 0)` with overflow checks.
74
55
///
@@ -138,14 +119,6 @@ impl Duration {
138
119
Duration { nanos : nanos as u32 , ..Duration :: seconds ( secs) }
139
120
}
140
121
141
- /// Returns a tuple of the number of days, (non-leap) seconds and nanoseconds in the duration.
142
- /// Note that the number of seconds and nanoseconds are always positive,
143
- /// so that for example `-Duration::seconds(3)` has -1 days and 86,397 seconds.
144
- #[ inline]
145
- pub fn to_tuple ( & self ) -> ( i32 , u32 , u32 ) {
146
- ( self . days , self . secs , self . nanos )
147
- }
148
-
149
122
/// Same as `to_tuple` but returns a tuple compatible to `to_negated_tuple`.
150
123
#[ inline]
151
124
fn to_tuple_64 ( & self ) -> ( i64 , u32 , u32 ) {
@@ -514,8 +487,6 @@ mod tests {
514
487
assert_eq ! ( Duration :: seconds( 86401 ) . num_days( ) , 1 ) ;
515
488
assert_eq ! ( Duration :: seconds( -86399 ) . num_days( ) , 0 ) ;
516
489
assert_eq ! ( Duration :: seconds( -86401 ) . num_days( ) , -1 ) ;
517
- assert_eq ! ( Duration :: new( 1 , 2 , 3_004_005 ) . num_days( ) , 1 ) ;
518
- assert_eq ! ( Duration :: new( -1 , -2 , -3_004_005 ) . num_days( ) , -1 ) ;
519
490
assert_eq ! ( Duration :: days( i32 :: MAX ) . num_days( ) , i32 :: MAX ) ;
520
491
assert_eq ! ( Duration :: days( i32 :: MIN ) . num_days( ) , i32 :: MIN ) ;
521
492
assert_eq ! ( MAX . num_days( ) , MAX_DAYS ) ;
@@ -532,8 +503,6 @@ mod tests {
532
503
assert_eq ! ( Duration :: milliseconds( 1001 ) . num_seconds( ) , 1 ) ;
533
504
assert_eq ! ( Duration :: milliseconds( -999 ) . num_seconds( ) , 0 ) ;
534
505
assert_eq ! ( Duration :: milliseconds( -1001 ) . num_seconds( ) , -1 ) ;
535
- assert_eq ! ( Duration :: new( 1 , 2 , 3_004_005 ) . num_seconds( ) , 86402 ) ;
536
- assert_eq ! ( Duration :: new( -1 , -2 , -3_004_005 ) . num_seconds( ) , -86402 ) ;
537
506
assert_eq ! ( Duration :: seconds( i32 :: MAX ) . num_seconds( ) , i32 :: MAX as i64 ) ;
538
507
assert_eq ! ( Duration :: seconds( i32 :: MIN ) . num_seconds( ) , i32 :: MIN as i64 ) ;
539
508
assert_eq ! ( MAX . num_seconds( ) , ( MAX_DAYS as i64 + 1 ) * 86400 - 1 ) ;
@@ -550,8 +519,6 @@ mod tests {
550
519
assert_eq ! ( Duration :: microseconds( 1001 ) . num_milliseconds( ) , 1 ) ;
551
520
assert_eq ! ( Duration :: microseconds( -999 ) . num_milliseconds( ) , 0 ) ;
552
521
assert_eq ! ( Duration :: microseconds( -1001 ) . num_milliseconds( ) , -1 ) ;
553
- assert_eq ! ( Duration :: new( 1 , 2 , 3_004_005 ) . num_milliseconds( ) , 86402_003 ) ;
554
- assert_eq ! ( Duration :: new( -1 , -2 , -3_004_005 ) . num_milliseconds( ) , -86402_003 ) ;
555
522
assert_eq ! ( Duration :: milliseconds( i32 :: MAX ) . num_milliseconds( ) , i32 :: MAX as i64 ) ;
556
523
assert_eq ! ( Duration :: milliseconds( i32 :: MIN ) . num_milliseconds( ) , i32 :: MIN as i64 ) ;
557
524
assert_eq ! ( MAX . num_milliseconds( ) , ( MAX_DAYS as i64 + 1 ) * 86400_000 - 1 ) ;
@@ -568,8 +535,6 @@ mod tests {
568
535
assert_eq ! ( Duration :: nanoseconds( 1001 ) . num_microseconds( ) , Some ( 1 ) ) ;
569
536
assert_eq ! ( Duration :: nanoseconds( -999 ) . num_microseconds( ) , Some ( 0 ) ) ;
570
537
assert_eq ! ( Duration :: nanoseconds( -1001 ) . num_microseconds( ) , Some ( -1 ) ) ;
571
- assert_eq ! ( Duration :: new( 1 , 2 , 3_004_005 ) . num_microseconds( ) , Some ( 86402_003_004 ) ) ;
572
- assert_eq ! ( Duration :: new( -1 , -2 , -3_004_005 ) . num_microseconds( ) , Some ( -86402_003_004 ) ) ;
573
538
assert_eq ! ( Duration :: microseconds( i32 :: MAX ) . num_microseconds( ) , Some ( i32 :: MAX as i64 ) ) ;
574
539
assert_eq ! ( Duration :: microseconds( i32 :: MIN ) . num_microseconds( ) , Some ( i32 :: MIN as i64 ) ) ;
575
540
assert_eq ! ( MAX . num_microseconds( ) , None ) ;
@@ -591,8 +556,6 @@ mod tests {
591
556
assert_eq ! ( d. num_nanoseconds( ) , Some ( 0 ) ) ;
592
557
assert_eq ! ( Duration :: nanoseconds( 1 ) . num_nanoseconds( ) , Some ( 1 ) ) ;
593
558
assert_eq ! ( Duration :: nanoseconds( -1 ) . num_nanoseconds( ) , Some ( -1 ) ) ;
594
- assert_eq ! ( Duration :: new( 1 , 2 , 3_004_005 ) . num_nanoseconds( ) , Some ( 86402_003_004_005 ) ) ;
595
- assert_eq ! ( Duration :: new( -1 , -2 , -3_004_005 ) . num_nanoseconds( ) , Some ( -86402_003_004_005 ) ) ;
596
559
assert_eq ! ( Duration :: nanoseconds( i32 :: MAX ) . num_nanoseconds( ) , Some ( i32 :: MAX as i64 ) ) ;
597
560
assert_eq ! ( Duration :: nanoseconds( i32 :: MIN ) . num_nanoseconds( ) , Some ( i32 :: MIN as i64 ) ) ;
598
561
assert_eq ! ( MAX . num_nanoseconds( ) , None ) ;
0 commit comments