@@ -56,13 +56,6 @@ pub struct DateTime<Tz: TimeZone> {
5656 offset : Tz :: Offset ,
5757}
5858
59- /// The minimum possible `DateTime<Utc>`.
60- #[ deprecated( since = "0.4.20" , note = "Use DateTime::MIN_UTC instead" ) ]
61- pub const MIN_DATETIME : DateTime < Utc > = DateTime :: < Utc > :: MIN_UTC ;
62- /// The maximum possible `DateTime<Utc>`.
63- #[ deprecated( since = "0.4.20" , note = "Use DateTime::MAX_UTC instead" ) ]
64- pub const MAX_DATETIME : DateTime < Utc > = DateTime :: < Utc > :: MAX_UTC ;
65-
6659impl < Tz : TimeZone > DateTime < Tz > {
6760 /// Makes a new `DateTime` from its components: a `NaiveDateTime` in UTC and an `Offset`.
6861 ///
@@ -95,37 +88,6 @@ impl<Tz: TimeZone> DateTime<Tz> {
9588 DateTime { datetime, offset }
9689 }
9790
98- /// Makes a new `DateTime` from its components: a `NaiveDateTime` in UTC and an `Offset`.
99- #[ inline]
100- #[ must_use]
101- #[ deprecated(
102- since = "0.4.27" ,
103- note = "Use TimeZone::from_utc_datetime() or DateTime::from_naive_utc_and_offset instead"
104- ) ]
105- pub fn from_utc ( datetime : NaiveDateTime , offset : Tz :: Offset ) -> DateTime < Tz > {
106- DateTime { datetime, offset }
107- }
108-
109- /// Makes a new `DateTime` from a `NaiveDateTime` in *local* time and an `Offset`.
110- ///
111- /// # Panics
112- ///
113- /// Panics if the local datetime can't be converted to UTC because it would be out of range.
114- ///
115- /// This can happen if `datetime` is near the end of the representable range of `NaiveDateTime`,
116- /// and the offset from UTC pushes it beyond that.
117- #[ inline]
118- #[ must_use]
119- #[ deprecated(
120- since = "0.4.27" ,
121- note = "Use TimeZone::from_local_datetime() or NaiveDateTime::and_local_timezone instead"
122- ) ]
123- pub fn from_local ( datetime : NaiveDateTime , offset : Tz :: Offset ) -> DateTime < Tz > {
124- let datetime_utc = datetime - offset. fix ( ) ;
125-
126- DateTime { datetime : datetime_utc, offset }
127- }
128-
12991 /// Retrieves the date without an associated timezone.
13092 ///
13193 /// # Panics
@@ -140,7 +102,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
140102 /// use chrono::prelude::*;
141103 ///
142104 /// let date: DateTime<Utc> = Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap();
143- /// let other: DateTime<FixedOffset> = FixedOffset::east_opt (23).unwrap().with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap();
105+ /// let other: DateTime<FixedOffset> = FixedOffset::east (23).unwrap().with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap();
144106 /// assert_eq!(date.date_naive(), other.date_naive());
145107 /// ```
146108 #[ inline]
@@ -161,7 +123,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
161123 /// (aka "UNIX timestamp").
162124 ///
163125 /// The reverse operation of creating a [`DateTime`] from a timestamp can be performed
164- /// using [`from_timestamp`](DateTime::from_timestamp) or [`TimeZone::timestamp_opt `].
126+ /// using [`from_timestamp`](DateTime::from_timestamp) or [`TimeZone::timestamp `].
165127 ///
166128 /// ```
167129 /// use chrono::{DateTime, TimeZone, Utc};
@@ -215,23 +177,6 @@ impl<Tz: TimeZone> DateTime<Tz> {
215177 self . datetime . timestamp_micros ( )
216178 }
217179
218- /// Returns the number of non-leap-nanoseconds since January 1, 1970 UTC.
219- ///
220- /// # Panics
221- ///
222- /// An `i64` with nanosecond precision can span a range of ~584 years. This function panics on
223- /// an out of range `DateTime`.
224- ///
225- /// The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192
226- /// and 2262-04-11T23:47:16.854775807.
227- #[ deprecated( since = "0.4.31" , note = "use `timestamp_nanos_opt()` instead" ) ]
228- #[ inline]
229- #[ must_use]
230- pub fn timestamp_nanos ( & self ) -> i64 {
231- self . timestamp_nanos_opt ( )
232- . expect ( "value can not be represented in a timestamp with nanosecond precision." )
233- }
234-
235180 /// Returns the number of non-leap-nanoseconds since January 1, 1970 UTC.
236181 ///
237182 /// # Errors
@@ -248,27 +193,27 @@ impl<Tz: TimeZone> DateTime<Tz> {
248193 /// use chrono::{Utc, NaiveDate};
249194 ///
250195 /// let dt = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_nano_opt(0, 0, 1, 444).unwrap().and_local_timezone(Utc).unwrap();
251- /// assert_eq!(dt.timestamp_nanos_opt (), Some(1_000_000_444));
196+ /// assert_eq!(dt.timestamp_nanos (), Some(1_000_000_444));
252197 ///
253198 /// let dt = NaiveDate::from_ymd_opt(2001, 9, 9).unwrap().and_hms_nano_opt(1, 46, 40, 555).unwrap().and_local_timezone(Utc).unwrap();
254- /// assert_eq!(dt.timestamp_nanos_opt (), Some(1_000_000_000_000_000_555));
199+ /// assert_eq!(dt.timestamp_nanos (), Some(1_000_000_000_000_000_555));
255200 ///
256201 /// let dt = NaiveDate::from_ymd_opt(1677, 9, 21).unwrap().and_hms_nano_opt(0, 12, 43, 145_224_192).unwrap().and_local_timezone(Utc).unwrap();
257- /// assert_eq!(dt.timestamp_nanos_opt (), Some(-9_223_372_036_854_775_808));
202+ /// assert_eq!(dt.timestamp_nanos (), Some(-9_223_372_036_854_775_808));
258203 ///
259204 /// let dt = NaiveDate::from_ymd_opt(2262, 4, 11).unwrap().and_hms_nano_opt(23, 47, 16, 854_775_807).unwrap().and_local_timezone(Utc).unwrap();
260- /// assert_eq!(dt.timestamp_nanos_opt (), Some(9_223_372_036_854_775_807));
205+ /// assert_eq!(dt.timestamp_nanos (), Some(9_223_372_036_854_775_807));
261206 ///
262207 /// let dt = NaiveDate::from_ymd_opt(1677, 9, 21).unwrap().and_hms_nano_opt(0, 12, 43, 145_224_191).unwrap().and_local_timezone(Utc).unwrap();
263- /// assert_eq!(dt.timestamp_nanos_opt (), None);
208+ /// assert_eq!(dt.timestamp_nanos (), None);
264209 ///
265210 /// let dt = NaiveDate::from_ymd_opt(2262, 4, 11).unwrap().and_hms_nano_opt(23, 47, 16, 854_775_808).unwrap().and_local_timezone(Utc).unwrap();
266- /// assert_eq!(dt.timestamp_nanos_opt (), None);
211+ /// assert_eq!(dt.timestamp_nanos (), None);
267212 /// ```
268213 #[ inline]
269214 #[ must_use]
270- pub fn timestamp_nanos_opt ( & self ) -> Option < i64 > {
271- self . datetime . timestamp_nanos_opt ( )
215+ pub fn timestamp_nanos ( & self ) -> Option < i64 > {
216+ self . datetime . timestamp_nanos ( )
272217 }
273218
274219 /// Returns the number of milliseconds since the last second boundary.
@@ -548,7 +493,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
548493 /// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Secs, true),
549494 /// "2018-01-26T18:30:09Z");
550495 ///
551- /// let pst = FixedOffset::east_opt (8 * 60 * 60).unwrap();
496+ /// let pst = FixedOffset::east (8 * 60 * 60).unwrap();
552497 /// let dt = pst.from_local_datetime(&NaiveDate::from_ymd_opt(2018, 1, 26).unwrap().and_hms_micro_opt(10, 30, 9, 453_829).unwrap()).unwrap();
553498 /// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Secs, true),
554499 /// "2018-01-26T10:30:09+08:00");
@@ -572,7 +517,7 @@ impl DateTime<Utc> {
572517 /// [`timestamp_subsec_nanos`](DateTime::timestamp_subsec_nanos).
573518 ///
574519 /// If you need to create a `DateTime` with a [`TimeZone`] different from [`Utc`], use
575- /// [`TimeZone::timestamp_opt `] or [`DateTime::with_timezone`].
520+ /// [`TimeZone::timestamp `] or [`DateTime::with_timezone`].
576521 ///
577522 /// The nanosecond part can exceed 1,000,000,000 in order to represent a
578523 /// [leap second](NaiveTime#leap-second-handling), but only when `secs % 60 == 59`.
@@ -597,7 +542,7 @@ impl DateTime<Utc> {
597542 #[ must_use]
598543 pub const fn from_timestamp ( secs : i64 , nsecs : u32 ) -> Option < Self > {
599544 Some ( DateTime {
600- datetime : try_opt ! ( NaiveDateTime :: from_timestamp_opt ( secs, nsecs) ) ,
545+ datetime : try_opt ! ( NaiveDateTime :: from_timestamp ( secs, nsecs) ) ,
601546 offset : Utc ,
602547 } )
603548 }
@@ -608,7 +553,7 @@ impl DateTime<Utc> {
608553 /// This is guaranteed to round-trip with regard to [`timestamp_millis`](DateTime::timestamp_millis).
609554 ///
610555 /// If you need to create a `DateTime` with a [`TimeZone`] different from [`Utc`], use
611- /// [`TimeZone::timestamp_millis_opt `] or [`DateTime::with_timezone`].
556+ /// [`TimeZone::timestamp_millis `] or [`DateTime::with_timezone`].
612557 ///
613558 /// # Errors
614559 ///
@@ -649,7 +594,7 @@ impl Default for DateTime<Local> {
649594
650595impl Default for DateTime < FixedOffset > {
651596 fn default ( ) -> Self {
652- FixedOffset :: west_opt ( 0 ) . unwrap ( ) . from_utc_datetime ( & NaiveDateTime :: default ( ) )
597+ FixedOffset :: west ( 0 ) . unwrap ( ) . from_utc_datetime ( & NaiveDateTime :: default ( ) )
653598 }
654599}
655600
@@ -660,7 +605,7 @@ impl From<DateTime<Utc>> for DateTime<FixedOffset> {
660605 /// Conversion is done via [`DateTime::with_timezone`]. Note that the converted value returned by
661606 /// this will be created with a fixed timezone offset of 0.
662607 fn from ( src : DateTime < Utc > ) -> Self {
663- src. with_timezone ( & FixedOffset :: east_opt ( 0 ) . unwrap ( ) )
608+ src. with_timezone ( & FixedOffset :: east ( 0 ) . unwrap ( ) )
664609 }
665610}
666611
@@ -762,7 +707,7 @@ impl DateTime<FixedOffset> {
762707 /// # use chrono::{DateTime, FixedOffset, TimeZone};
763708 /// assert_eq!(
764709 /// DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 GMT").unwrap(),
765- /// FixedOffset::east_opt (0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
710+ /// FixedOffset::east (0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
766711 /// );
767712 /// ```
768713 pub fn parse_from_rfc2822 ( s : & str ) -> ParseResult < DateTime < FixedOffset > > {
@@ -813,7 +758,7 @@ impl DateTime<FixedOffset> {
813758 ///
814759 /// let dt = DateTime::parse_from_str(
815760 /// "1983 Apr 13 12:09:14.274 +0000", "%Y %b %d %H:%M:%S%.3f %z");
816- /// assert_eq!(dt, Ok(FixedOffset::east_opt (0).unwrap().from_local_datetime(&NaiveDate::from_ymd_opt(1983, 4, 13).unwrap().and_hms_milli_opt(12, 9, 14, 274).unwrap()).unwrap()));
761+ /// assert_eq!(dt, Ok(FixedOffset::east (0).unwrap().from_local_datetime(&NaiveDate::from_ymd_opt(1983, 4, 13).unwrap().and_hms_milli_opt(12, 9, 14, 274).unwrap()).unwrap()));
817762 /// ```
818763 pub fn parse_from_str ( s : & str , fmt : & str ) -> ParseResult < DateTime < FixedOffset > > {
819764 let mut parsed = Parsed :: new ( ) ;
@@ -842,7 +787,7 @@ impl DateTime<FixedOffset> {
842787 /// "2015-02-18 23:16:09 +0200 trailing text", "%Y-%m-%d %H:%M:%S %z").unwrap();
843788 /// assert_eq!(
844789 /// datetime,
845- /// FixedOffset::east_opt (2*3600).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
790+ /// FixedOffset::east (2*3600).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
846791 /// );
847792 /// assert_eq!(remainder, " trailing text");
848793 /// ```
@@ -1192,8 +1137,8 @@ impl<Tz: TimeZone, Tz2: TimeZone> PartialOrd<DateTime<Tz2>> for DateTime<Tz> {
11921137 /// ```
11931138 /// use chrono::prelude::*;
11941139 ///
1195- /// let earlier = Utc.with_ymd_and_hms(2015, 5, 15, 2, 0, 0).unwrap().with_timezone(&FixedOffset::west_opt (1 * 3600).unwrap());
1196- /// let later = Utc.with_ymd_and_hms(2015, 5, 15, 3, 0, 0).unwrap().with_timezone(&FixedOffset::west_opt (5 * 3600).unwrap());
1140+ /// let earlier = Utc.with_ymd_and_hms(2015, 5, 15, 2, 0, 0).unwrap().with_timezone(&FixedOffset::west (1 * 3600).unwrap());
1141+ /// let later = Utc.with_ymd_and_hms(2015, 5, 15, 3, 0, 0).unwrap().with_timezone(&FixedOffset::west (5 * 3600).unwrap());
11971142 ///
11981143 /// assert_eq!(earlier.to_string(), "2015-05-15 01:00:00 -01:00");
11991144 /// assert_eq!(later.to_string(), "2015-05-14 22:00:00 -05:00");
@@ -1609,7 +1554,7 @@ impl From<SystemTime> for DateTime<Utc> {
16091554 }
16101555 }
16111556 } ;
1612- Utc . timestamp_opt ( sec, nsec) . unwrap ( )
1557+ Utc . timestamp ( sec, nsec) . unwrap ( )
16131558 }
16141559}
16151560
@@ -1652,7 +1597,7 @@ impl From<js_sys::Date> for DateTime<Utc> {
16521597) ) ]
16531598impl From < & js_sys:: Date > for DateTime < Utc > {
16541599 fn from ( date : & js_sys:: Date ) -> DateTime < Utc > {
1655- Utc . timestamp_millis_opt ( date. get_time ( ) as i64 ) . unwrap ( )
1600+ Utc . timestamp_millis ( date. get_time ( ) as i64 ) . unwrap ( )
16561601 }
16571602}
16581603
@@ -1700,14 +1645,14 @@ where
17001645
17011646 assert_eq ! (
17021647 to_string_fixed(
1703- & FixedOffset :: east_opt ( 3660 ) . unwrap( ) . with_ymd_and_hms( 2014 , 7 , 24 , 12 , 34 , 6 ) . unwrap( )
1648+ & FixedOffset :: east ( 3660 ) . unwrap( ) . with_ymd_and_hms( 2014 , 7 , 24 , 12 , 34 , 6 ) . unwrap( )
17041649 )
17051650 . ok( ) ,
17061651 Some ( r#""2014-07-24T12:34:06+01:01""# . into( ) )
17071652 ) ;
17081653 assert_eq ! (
17091654 to_string_fixed(
1710- & FixedOffset :: east_opt ( 3650 ) . unwrap( ) . with_ymd_and_hms( 2014 , 7 , 24 , 12 , 34 , 6 ) . unwrap( )
1655+ & FixedOffset :: east ( 3650 ) . unwrap( ) . with_ymd_and_hms( 2014 , 7 , 24 , 12 , 34 , 6 ) . unwrap( )
17111656 )
17121657 . ok( ) ,
17131658 // An offset with seconds is not allowed by RFC 3339, so we round it to the nearest minute.
@@ -1744,13 +1689,13 @@ fn test_decodable_json<FUtc, FFixed, FLocal, E>(
17441689 assert_eq ! (
17451690 norm( & fixed_from_str( r#""2014-07-24T12:34:06Z""# ) . ok( ) ) ,
17461691 norm( & Some (
1747- FixedOffset :: east_opt ( 0 ) . unwrap( ) . with_ymd_and_hms( 2014 , 7 , 24 , 12 , 34 , 6 ) . unwrap( )
1692+ FixedOffset :: east ( 0 ) . unwrap( ) . with_ymd_and_hms( 2014 , 7 , 24 , 12 , 34 , 6 ) . unwrap( )
17481693 ) )
17491694 ) ;
17501695 assert_eq ! (
17511696 norm( & fixed_from_str( r#""2014-07-24T13:57:06+01:23""# ) . ok( ) ) ,
17521697 norm( & Some (
1753- FixedOffset :: east_opt ( 60 * 60 + 23 * 60 )
1698+ FixedOffset :: east ( 60 * 60 + 23 * 60 )
17541699 . unwrap( )
17551700 . with_ymd_and_hms( 2014 , 7 , 24 , 13 , 57 , 6 )
17561701 . unwrap( )
0 commit comments