@@ -28,7 +28,7 @@ use crate::offset::Local;
2828use crate :: offset:: { FixedOffset , Offset , TimeZone , Utc } ;
2929#[ cfg( any( feature = "clock" , feature = "std" ) ) ]
3030use crate :: OutOfRange ;
31- use crate :: { ok , try_err, try_ok_or} ;
31+ use crate :: { try_err, try_ok_or} ;
3232use crate :: { Datelike , Error , Months , TimeDelta , Timelike , Weekday } ;
3333
3434#[ cfg( any( feature = "rkyv" , feature = "rkyv-16" , feature = "rkyv-32" , feature = "rkyv-64" ) ) ]
@@ -823,31 +823,29 @@ impl DateTime<Utc> {
823823 ///
824824 /// # Errors
825825 ///
826- /// Returns `None` if the number of microseconds would be out of range for a `NaiveDateTime`
827- /// (more than ca. 262,000 years away from common era)
826+ /// Returns [`Error::OutOfRange`] if the timestamp in microseconds is outside the range of a
827+ /// `DateTime` (more than ca. 262,000 years away from common era).
828828 ///
829829 /// # Example
830830 ///
831831 /// ```
832832 /// use chrono::DateTime;
833833 ///
834834 /// let timestamp_micros: i64 = 1662921288000000; // Sun, 11 Sep 2022 18:34:48 UTC
835- /// let dt = DateTime::from_timestamp_micros(timestamp_micros);
836- /// assert!(dt.is_some());
837- /// assert_eq!(timestamp_micros, dt.expect("invalid timestamp").timestamp_micros());
835+ /// let dt = DateTime::from_timestamp_micros(timestamp_micros)?;
836+ /// assert_eq!(timestamp_micros, dt.timestamp_micros());
838837 ///
839838 /// // Negative timestamps (before the UNIX epoch) are supported as well.
840839 /// let timestamp_micros: i64 = -2208936075000000; // Mon, 1 Jan 1900 14:38:45 UTC
841- /// let dt = DateTime::from_timestamp_micros(timestamp_micros);
842- /// assert!( dt.is_some ());
843- /// assert_eq!(timestamp_micros, dt.expect("invalid timestamp").timestamp_micros ());
840+ /// let dt = DateTime::from_timestamp_micros(timestamp_micros)? ;
841+ /// assert_eq!(timestamp_micros, dt.timestamp_micros ());
842+ /// # Ok::<(), chrono::Error>( ())
844843 /// ```
845844 #[ inline]
846- #[ must_use]
847- pub const fn from_timestamp_micros ( micros : i64 ) -> Option < Self > {
845+ pub const fn from_timestamp_micros ( micros : i64 ) -> Result < Self , Error > {
848846 let secs = micros. div_euclid ( 1_000_000 ) ;
849847 let nsecs = micros. rem_euclid ( 1_000_000 ) as u32 * 1000 ;
850- ok ! ( Self :: from_timestamp( secs, nsecs) )
848+ Self :: from_timestamp ( secs, nsecs)
851849 }
852850
853851 /// Creates a new [`DateTime<Utc>`] from the number of non-leap microseconds
0 commit comments