@@ -66,33 +66,52 @@ impl Timestamp {
66
66
Timestamp ( nanos)
67
67
}
68
68
69
+ /// Subtracts the given amount of days from the timestamp and
70
+ /// returns the result. The original value remains unchanged.
71
+ ///
72
+ /// Panics if the result is not >= 0. I.e. times before epoch cannot be represented.
69
73
#[ must_use = "this returns the result of the operation, without modifying the original" ]
70
74
#[ inline]
71
75
pub const fn minus_days ( & self , subtrahend : u64 ) -> Timestamp {
72
76
self . minus_hours ( subtrahend * 24 )
73
77
}
74
78
79
+ /// Subtracts the given amount of hours from the timestamp and
80
+ /// returns the result. The original value remains unchanged.
81
+ ///
82
+ /// Panics if the result is not >= 0. I.e. times before epoch cannot be represented.
75
83
#[ must_use = "this returns the result of the operation, without modifying the original" ]
76
84
#[ inline]
77
85
pub const fn minus_hours ( & self , subtrahend : u64 ) -> Timestamp {
78
86
self . minus_minutes ( subtrahend * 60 )
79
87
}
80
88
89
+ /// Subtracts the given amount of minutes from the timestamp and
90
+ /// returns the result. The original value remains unchanged.
91
+ ///
92
+ /// Panics if the result is not >= 0. I.e. times before epoch cannot be represented.
81
93
#[ must_use = "this returns the result of the operation, without modifying the original" ]
82
94
#[ inline]
83
95
pub const fn minus_minutes ( & self , subtrahend : u64 ) -> Timestamp {
84
96
self . minus_seconds ( subtrahend * 60 )
85
97
}
86
98
99
+ /// Subtracts the given amount of seconds from the timestamp and
100
+ /// returns the result. The original value remains unchanged.
101
+ ///
102
+ /// Panics if the result is not >= 0. I.e. times before epoch cannot be represented.
87
103
#[ must_use = "this returns the result of the operation, without modifying the original" ]
88
104
pub const fn minus_seconds ( & self , subtrahend : u64 ) -> Timestamp {
89
105
self . minus_nanos ( subtrahend * 1_000_000_000 )
90
106
}
91
107
108
+ /// Subtracts the given amount of nanoseconds from the timestamp and
109
+ /// returns the result. The original value remains unchanged.
110
+ ///
111
+ /// Panics if the result is not >= 0. I.e. times before epoch cannot be represented.
92
112
#[ must_use = "this returns the result of the operation, without modifying the original" ]
93
113
pub const fn minus_nanos ( & self , subtrahend : u64 ) -> Timestamp {
94
- let nanos = Uint64 :: new ( self . 0 . u64 ( ) - subtrahend) ;
95
- Timestamp ( nanos)
114
+ Timestamp ( self . 0 . panicking_sub ( Uint64 :: new ( subtrahend) ) )
96
115
}
97
116
98
117
/// Returns nanoseconds since epoch
0 commit comments