@@ -88,7 +88,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
8888 DateTime { datetime, offset }
8989 }
9090
91- /// Retrieves the date without an associated timezone .
91+ /// Retrieves the date component .
9292 ///
9393 /// # Panics
9494 ///
@@ -135,7 +135,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
135135 /// ```
136136 #[ inline]
137137 #[ must_use]
138- pub fn timestamp ( & self ) -> i64 {
138+ pub const fn timestamp ( & self ) -> i64 {
139139 self . datetime . timestamp ( )
140140 }
141141
@@ -154,7 +154,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
154154 /// ```
155155 #[ inline]
156156 #[ must_use]
157- pub fn timestamp_millis ( & self ) -> i64 {
157+ pub const fn timestamp_millis ( & self ) -> i64 {
158158 self . datetime . timestamp_millis ( )
159159 }
160160
@@ -173,7 +173,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
173173 /// ```
174174 #[ inline]
175175 #[ must_use]
176- pub fn timestamp_micros ( & self ) -> i64 {
176+ pub const fn timestamp_micros ( & self ) -> i64 {
177177 self . datetime . timestamp_micros ( )
178178 }
179179
@@ -212,7 +212,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
212212 /// ```
213213 #[ inline]
214214 #[ must_use]
215- pub fn timestamp_nanos ( & self ) -> Option < i64 > {
215+ pub const fn timestamp_nanos ( & self ) -> Option < i64 > {
216216 self . datetime . timestamp_nanos ( )
217217 }
218218
@@ -221,7 +221,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
221221 /// In event of a leap second this may exceed 999.
222222 #[ inline]
223223 #[ must_use]
224- pub fn timestamp_subsec_millis ( & self ) -> u32 {
224+ pub const fn timestamp_subsec_millis ( & self ) -> u32 {
225225 self . datetime . timestamp_subsec_millis ( )
226226 }
227227
@@ -230,7 +230,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
230230 /// In event of a leap second this may exceed 999,999.
231231 #[ inline]
232232 #[ must_use]
233- pub fn timestamp_subsec_micros ( & self ) -> u32 {
233+ pub const fn timestamp_subsec_micros ( & self ) -> u32 {
234234 self . datetime . timestamp_subsec_micros ( )
235235 }
236236
@@ -239,14 +239,14 @@ impl<Tz: TimeZone> DateTime<Tz> {
239239 /// In event of a leap second this may exceed 999,999,999.
240240 #[ inline]
241241 #[ must_use]
242- pub fn timestamp_subsec_nanos ( & self ) -> u32 {
242+ pub const fn timestamp_subsec_nanos ( & self ) -> u32 {
243243 self . datetime . timestamp_subsec_nanos ( )
244244 }
245245
246246 /// Retrieves an associated offset from UTC.
247247 #[ inline]
248248 #[ must_use]
249- pub fn offset ( & self ) -> & Tz :: Offset {
249+ pub const fn offset ( & self ) -> & Tz :: Offset {
250250 & self . offset
251251 }
252252
@@ -278,11 +278,11 @@ impl<Tz: TimeZone> DateTime<Tz> {
278278 /// information.
279279 #[ inline]
280280 #[ must_use]
281- pub fn to_utc ( & self ) -> DateTime < Utc > {
281+ pub const fn to_utc ( & self ) -> DateTime < Utc > {
282282 DateTime { datetime : self . datetime , offset : Utc }
283283 }
284284
285- /// Adds given `Duration ` to the current date and time.
285+ /// Adds given `TimeDelta ` to the current date and time.
286286 ///
287287 /// # Errors
288288 ///
@@ -315,7 +315,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
315315 . single ( )
316316 }
317317
318- /// Subtracts given `Duration ` from the current date and time.
318+ /// Subtracts given `TimeDelta ` from the current date and time.
319319 ///
320320 /// # Errors
321321 ///
@@ -394,7 +394,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
394394 /// Returns a view to the naive UTC datetime.
395395 #[ inline]
396396 #[ must_use]
397- pub fn naive_utc ( & self ) -> NaiveDateTime {
397+ pub const fn naive_utc ( & self ) -> NaiveDateTime {
398398 self . datetime
399399 }
400400
@@ -571,8 +571,8 @@ impl DateTime<Utc> {
571571 /// ```
572572 #[ inline]
573573 #[ must_use]
574- pub fn from_timestamp_millis ( millis : i64 ) -> Option < Self > {
575- NaiveDateTime :: from_timestamp_millis ( millis) . as_ref ( ) . map ( NaiveDateTime :: and_utc)
574+ pub const fn from_timestamp_millis ( millis : i64 ) -> Option < Self > {
575+ Some ( try_opt ! ( NaiveDateTime :: from_timestamp_millis( millis) ) . and_utc ( ) )
576576 }
577577
578578 /// The Unix Epoch, 1970-01-01 00:00:00 UTC.
@@ -677,8 +677,7 @@ where
677677}
678678
679679impl DateTime < FixedOffset > {
680- /// Parses an RFC 2822 date and time string such as `Tue, 1 Jul 2003 10:52:37 +0200`,
681- /// then returns a new [`DateTime`] with a parsed [`FixedOffset`].
680+ /// Parses an RFC 2822 date-and-time string into a `DateTime<FixedOffset>` value.
682681 ///
683682 /// This parses valid RFC 2822 datetime strings (such as `Tue, 1 Jul 2003 10:52:37 +0200`)
684683 /// and returns a new [`DateTime`] instance with the parsed timezone as the [`FixedOffset`].
@@ -717,8 +716,7 @@ impl DateTime<FixedOffset> {
717716 parsed. to_datetime ( )
718717 }
719718
720- /// Parses an RFC 3339 and ISO 8601 date and time string such as `1996-12-19T16:39:57-08:00`,
721- /// then returns a new [`DateTime`] with a parsed [`FixedOffset`].
719+ /// Parses an RFC 3339 date-and-time string into a `DateTime<FixedOffset>` value.
722720 ///
723721 /// Parses all valid RFC 3339 values (as well as the subset of valid ISO 8601 values that are
724722 /// also valid RFC 3339 date-and-time values) and returns a new [`DateTime`] with a
@@ -740,8 +738,7 @@ impl DateTime<FixedOffset> {
740738 parsed. to_datetime ( )
741739 }
742740
743- /// Parses a string with the specified format string and returns a new
744- /// [`DateTime`] with a parsed [`FixedOffset`].
741+ /// Parses a string from a user-specified format into a `DateTime<FixedOffset>` value.
745742 ///
746743 /// Note that this method *requires a timezone* in the input string. See
747744 /// [`NaiveDateTime::parse_from_str`](./naive/struct.NaiveDateTime.html#method.parse_from_str)
@@ -1162,7 +1159,7 @@ impl<Tz: TimeZone> hash::Hash for DateTime<Tz> {
11621159 }
11631160}
11641161
1165- /// Add `chrono::Duration ` to `DateTime`.
1162+ /// Add `TimeDelta ` to `DateTime`.
11661163///
11671164/// As a part of Chrono's [leap second handling], the addition assumes that **there is no leap
11681165/// second ever**, except when the `NaiveDateTime` itself represents a leap second in which case
@@ -1177,7 +1174,7 @@ impl<Tz: TimeZone> Add<TimeDelta> for DateTime<Tz> {
11771174
11781175 #[ inline]
11791176 fn add ( self , rhs : TimeDelta ) -> DateTime < Tz > {
1180- self . checked_add_signed ( rhs) . expect ( "`DateTime + Duration ` overflowed" )
1177+ self . checked_add_signed ( rhs) . expect ( "`DateTime + TimeDelta ` overflowed" )
11811178 }
11821179}
11831180
@@ -1197,8 +1194,8 @@ impl<Tz: TimeZone> Add<Duration> for DateTime<Tz> {
11971194 #[ inline]
11981195 fn add ( self , rhs : Duration ) -> DateTime < Tz > {
11991196 let rhs = TimeDelta :: from_std ( rhs)
1200- . expect ( "overflow converting from core::time::Duration to chrono::Duration " ) ;
1201- self . checked_add_signed ( rhs) . expect ( "`DateTime + Duration ` overflowed" )
1197+ . expect ( "overflow converting from core::time::Duration to TimeDelta " ) ;
1198+ self . checked_add_signed ( rhs) . expect ( "`DateTime + TimeDelta ` overflowed" )
12021199 }
12031200}
12041201
@@ -1216,7 +1213,7 @@ impl<Tz: TimeZone> AddAssign<TimeDelta> for DateTime<Tz> {
12161213 #[ inline]
12171214 fn add_assign ( & mut self , rhs : TimeDelta ) {
12181215 let datetime =
1219- self . datetime . checked_add_signed ( rhs) . expect ( "`DateTime + Duration ` overflowed" ) ;
1216+ self . datetime . checked_add_signed ( rhs) . expect ( "`DateTime + TimeDelta ` overflowed" ) ;
12201217 let tz = self . timezone ( ) ;
12211218 * self = tz. from_utc_datetime ( & datetime) ;
12221219 }
@@ -1236,7 +1233,7 @@ impl<Tz: TimeZone> AddAssign<Duration> for DateTime<Tz> {
12361233 #[ inline]
12371234 fn add_assign ( & mut self , rhs : Duration ) {
12381235 let rhs = TimeDelta :: from_std ( rhs)
1239- . expect ( "overflow converting from core::time::Duration to chrono::Duration " ) ;
1236+ . expect ( "overflow converting from core::time::Duration to TimeDelta " ) ;
12401237 * self += rhs;
12411238 }
12421239}
@@ -1278,9 +1275,9 @@ impl<Tz: TimeZone> Add<Months> for DateTime<Tz> {
12781275 }
12791276}
12801277
1281- /// Subtract `chrono::Duration ` from `DateTime`.
1278+ /// Subtract `TimeDelta ` from `DateTime`.
12821279///
1283- /// This is the same as the addition with a negated `Duration `.
1280+ /// This is the same as the addition with a negated `TimeDelta `.
12841281///
12851282/// As a part of Chrono's [leap second handling] the subtraction assumes that **there is no leap
12861283/// second ever**, except when the `DateTime` itself represents a leap second in which case
@@ -1295,7 +1292,7 @@ impl<Tz: TimeZone> Sub<TimeDelta> for DateTime<Tz> {
12951292
12961293 #[ inline]
12971294 fn sub ( self , rhs : TimeDelta ) -> DateTime < Tz > {
1298- self . checked_sub_signed ( rhs) . expect ( "`DateTime - Duration ` overflowed" )
1295+ self . checked_sub_signed ( rhs) . expect ( "`DateTime - TimeDelta ` overflowed" )
12991296 }
13001297}
13011298
@@ -1315,14 +1312,14 @@ impl<Tz: TimeZone> Sub<Duration> for DateTime<Tz> {
13151312 #[ inline]
13161313 fn sub ( self , rhs : Duration ) -> DateTime < Tz > {
13171314 let rhs = TimeDelta :: from_std ( rhs)
1318- . expect ( "overflow converting from core::time::Duration to chrono::Duration " ) ;
1319- self . checked_sub_signed ( rhs) . expect ( "`DateTime - Duration ` overflowed" )
1315+ . expect ( "overflow converting from core::time::Duration to TimeDelta " ) ;
1316+ self . checked_sub_signed ( rhs) . expect ( "`DateTime - TimeDelta ` overflowed" )
13201317 }
13211318}
13221319
1323- /// Subtract-assign `chrono::Duration ` from `DateTime`.
1320+ /// Subtract-assign `TimeDelta ` from `DateTime`.
13241321///
1325- /// This is the same as the addition with a negated `Duration `.
1322+ /// This is the same as the addition with a negated `TimeDelta `.
13261323///
13271324/// As a part of Chrono's [leap second handling], the addition assumes that **there is no leap
13281325/// second ever**, except when the `DateTime` itself represents a leap second in which case
@@ -1336,7 +1333,7 @@ impl<Tz: TimeZone> SubAssign<TimeDelta> for DateTime<Tz> {
13361333 #[ inline]
13371334 fn sub_assign ( & mut self , rhs : TimeDelta ) {
13381335 let datetime =
1339- self . datetime . checked_sub_signed ( rhs) . expect ( "`DateTime - Duration ` overflowed" ) ;
1336+ self . datetime . checked_sub_signed ( rhs) . expect ( "`DateTime - TimeDelta ` overflowed" ) ;
13401337 let tz = self . timezone ( ) ;
13411338 * self = tz. from_utc_datetime ( & datetime)
13421339 }
@@ -1356,7 +1353,7 @@ impl<Tz: TimeZone> SubAssign<Duration> for DateTime<Tz> {
13561353 #[ inline]
13571354 fn sub_assign ( & mut self , rhs : Duration ) {
13581355 let rhs = TimeDelta :: from_std ( rhs)
1359- . expect ( "overflow converting from core::time::Duration to chrono::Duration " ) ;
1356+ . expect ( "overflow converting from core::time::Duration to TimeDelta " ) ;
13601357 * self -= rhs;
13611358 }
13621359}
0 commit comments