@@ -755,6 +755,61 @@ impl DateTime<Utc> {
755755 Some ( date. and_time ( time) . and_utc ( ) )
756756 }
757757
758+ /// Makes a new `DateTime<Utc>` from the number of non-leap seconds
759+ /// since January 1, 1970 0:00:00 UTC (aka "UNIX timestamp").
760+ ///
761+ /// This is a convenience wrapper around [`DateTime::from_timestamp`],
762+ /// which is useful in functions like [`Iterator::map`] to avoid a closure.
763+ ///
764+ /// This is guaranteed to round-trip with regard to [`timestamp`](DateTime::timestamp).
765+ ///
766+ /// If you need to create a `DateTime` with a [`TimeZone`] different from [`Utc`], use
767+ /// [`TimeZone::timestamp_opt`] or [`DateTime::with_timezone`]; if you need to create a
768+ /// `DateTime` with more precision, use [`DateTime::from_timestamp_micros`],
769+ /// [`DateTime::from_timestamp_millis`], or [`DateTime::from_timestamp_nanos`].
770+ ///
771+ /// # Errors
772+ ///
773+ /// Returns `None` on out-of-range number of seconds,
774+ /// otherwise returns `Some(DateTime {...})`.
775+ ///
776+ /// # Examples
777+ ///
778+ /// Using [`Option::and_then`]:
779+ ///
780+ /// ```
781+ /// # use chrono::DateTime;
782+ /// let maybe_timestamp: Option<i64> = Some(1431648000);
783+ /// let maybe_dt = maybe_timestamp.and_then(DateTime::from_timestamp_secs);
784+ ///
785+ /// assert!(maybe_dt.is_some());
786+ /// assert_eq!(maybe_dt.unwrap().to_string(), "2015-05-15 00:00:00 UTC");
787+ /// ```
788+ ///
789+ /// Using [`Iterator::map`]:
790+ ///
791+ /// ```
792+ /// # use chrono::{DateTime, Utc};
793+ /// let v = vec![i64::MIN, 1_000_000_000, 1_234_567_890, i64::MAX];
794+ /// let timestamps: Vec<Option<DateTime<Utc>>> = v
795+ /// .into_iter()
796+ /// .map(DateTime::from_timestamp_secs)
797+ /// .collect();
798+ ///
799+ /// assert_eq!(vec![
800+ /// None,
801+ /// Some(DateTime::parse_from_rfc3339("2001-09-09 01:46:40Z").unwrap().to_utc()),
802+ /// Some(DateTime::parse_from_rfc3339("2009-02-13 23:31:30Z").unwrap().to_utc()),
803+ /// None,
804+ /// ], timestamps);
805+ /// ```
806+ ///
807+ #[ inline]
808+ #[ must_use]
809+ pub const fn from_timestamp_secs ( secs : i64 ) -> Option < Self > {
810+ Self :: from_timestamp ( secs, 0 )
811+ }
812+
758813 /// Makes a new `DateTime<Utc>` from the number of non-leap milliseconds
759814 /// since January 1, 1970 0:00:00.000 UTC (aka "UNIX timestamp").
760815 ///
0 commit comments