diff options
Diffstat (limited to 'vendor/chrono/src/lib.rs')
-rw-r--r-- | vendor/chrono/src/lib.rs | 105 |
1 files changed, 53 insertions, 52 deletions
diff --git a/vendor/chrono/src/lib.rs b/vendor/chrono/src/lib.rs index 861ee1059..3737d1a9b 100644 --- a/vendor/chrono/src/lib.rs +++ b/vendor/chrono/src/lib.rs @@ -110,7 +110,8 @@ //! or in the local time zone //! ([`Local::now()`](./offset/struct.Local.html#method.now)). //! -//! ```rust +#![cfg_attr(not(feature = "clock"), doc = "```ignore")] +#![cfg_attr(feature = "clock", doc = "```rust")] //! use chrono::prelude::*; //! //! let utc: DateTime<Utc> = Utc::now(); // e.g. `2014-11-28T12:45:59.324310806Z` @@ -122,25 +123,30 @@ //! This is a bit verbose due to Rust's lack of function and method overloading, //! but in turn we get a rich combination of initialization methods. //! -//! ```rust +#![cfg_attr(not(feature = "std"), doc = "```ignore")] +#![cfg_attr(feature = "std", doc = "```rust")] //! use chrono::prelude::*; //! use chrono::offset::LocalResult; //! +//! # fn doctest() -> Option<()> { +//! //! let dt = Utc.with_ymd_and_hms(2014, 7, 8, 9, 10, 11).unwrap(); // `2014-07-08T09:10:11Z` +//! assert_eq!(dt, NaiveDate::from_ymd_opt(2014, 7, 8)?.and_hms_opt(9, 10, 11)?.and_local_timezone(Utc).unwrap()); +//! //! // July 8 is 188th day of the year 2014 (`o` for "ordinal") -//! assert_eq!(dt, Utc.yo(2014, 189).and_hms_opt(9, 10, 11).unwrap()); +//! assert_eq!(dt, NaiveDate::from_yo_opt(2014, 189)?.and_hms_opt(9, 10, 11)?.and_utc()); //! // July 8 is Tuesday in ISO week 28 of the year 2014. -//! assert_eq!(dt, Utc.isoywd(2014, 28, Weekday::Tue).and_hms_opt(9, 10, 11).unwrap()); +//! assert_eq!(dt, NaiveDate::from_isoywd_opt(2014, 28, Weekday::Tue)?.and_hms_opt(9, 10, 11)?.and_utc()); //! -//! let dt = NaiveDate::from_ymd_opt(2014, 7, 8).unwrap().and_hms_milli_opt(9, 10, 11, 12).unwrap().and_local_timezone(Utc).unwrap(); // `2014-07-08T09:10:11.012Z` -//! assert_eq!(dt, NaiveDate::from_ymd_opt(2014, 7, 8).unwrap().and_hms_micro_opt(9, 10, 11, 12_000).unwrap().and_local_timezone(Utc).unwrap()); -//! assert_eq!(dt, NaiveDate::from_ymd_opt(2014, 7, 8).unwrap().and_hms_nano_opt(9, 10, 11, 12_000_000).unwrap().and_local_timezone(Utc).unwrap()); +//! let dt = NaiveDate::from_ymd_opt(2014, 7, 8)?.and_hms_milli_opt(9, 10, 11, 12)?.and_local_timezone(Utc).unwrap(); // `2014-07-08T09:10:11.012Z` +//! assert_eq!(dt, NaiveDate::from_ymd_opt(2014, 7, 8)?.and_hms_micro_opt(9, 10, 11, 12_000)?.and_local_timezone(Utc).unwrap()); +//! assert_eq!(dt, NaiveDate::from_ymd_opt(2014, 7, 8)?.and_hms_nano_opt(9, 10, 11, 12_000_000)?.and_local_timezone(Utc).unwrap()); //! //! // dynamic verification -//! assert_eq!(Utc.ymd_opt(2014, 7, 8).and_hms_opt(21, 15, 33), -//! LocalResult::Single(Utc.with_ymd_and_hms(2014, 7, 8, 21, 15, 33).unwrap())); -//! assert_eq!(Utc.ymd_opt(2014, 7, 8).and_hms_opt(80, 15, 33), LocalResult::None); -//! assert_eq!(Utc.ymd_opt(2014, 7, 38).and_hms_opt(21, 15, 33), LocalResult::None); +//! assert_eq!(Utc.with_ymd_and_hms(2014, 7, 8, 21, 15, 33), +//! LocalResult::Single(NaiveDate::from_ymd_opt(2014, 7, 8)?.and_hms_opt(21, 15, 33)?.and_utc())); +//! assert_eq!(Utc.with_ymd_and_hms(2014, 7, 8, 80, 15, 33), LocalResult::None); +//! assert_eq!(Utc.with_ymd_and_hms(2014, 7, 38, 21, 15, 33), LocalResult::None); //! //! // other time zone objects can be used to construct a local datetime. //! // obviously, `local_dt` is normally different from `dt`, but `fixed_dt` should be identical. @@ -148,6 +154,9 @@ //! let fixed_dt = FixedOffset::east_opt(9 * 3600).unwrap().from_local_datetime(&NaiveDate::from_ymd_opt(2014, 7, 8).unwrap().and_hms_milli_opt(18, 10, 11, 12).unwrap()).unwrap(); //! assert_eq!(dt, fixed_dt); //! # let _ = local_dt; +//! # Some(()) +//! # } +//! # doctest().unwrap(); //! ``` //! //! Various properties are available to the date and time, and can be altered individually. @@ -217,6 +226,7 @@ //! The `unstable-locales` feature requires and implies at least the `alloc` feature. //! //! ```rust +//! # #[allow(unused_imports)] //! use chrono::prelude::*; //! //! # #[cfg(feature = "unstable-locales")] @@ -314,12 +324,13 @@ //! [`DateTime.timestamp_subsec_nanos`](./struct.DateTime.html#method.timestamp_subsec_nanos) //! to get the number of additional number of nanoseconds. //! -//! ```rust +#![cfg_attr(not(feature = "std"), doc = "```ignore")] +#![cfg_attr(feature = "std", doc = "```rust")] //! // We need the trait in scope to use Utc::timestamp(). //! use chrono::{DateTime, TimeZone, Utc}; //! //! // Construct a datetime from epoch: -//! let dt = Utc.timestamp(1_500_000_000, 0); +//! let dt = Utc.timestamp_opt(1_500_000_000, 0).unwrap(); //! assert_eq!(dt.to_rfc2822(), "Fri, 14 Jul 2017 02:40:00 +0000"); //! //! // Get epoch value from a datetime: @@ -327,33 +338,6 @@ //! assert_eq!(dt.timestamp(), 1_500_000_000); //! ``` //! -//! ### Individual date -//! -//! Chrono also provides an individual date type ([**`Date`**](./struct.Date.html)). -//! It also has time zones attached, and have to be constructed via time zones. -//! Most operations available to `DateTime` are also available to `Date` whenever appropriate. -//! -//! ```rust -//! use chrono::prelude::*; -//! use chrono::offset::LocalResult; -//! -//! # // these *may* fail, but only very rarely. just rerun the test if you were that unfortunate ;) -//! assert_eq!(Utc::today(), Utc::now().date()); -//! assert_eq!(Local::today(), Local::now().date()); -//! -//! assert_eq!(Utc.ymd_opt(2014, 11, 28).unwrap().weekday(), Weekday::Fri); -//! assert_eq!(Utc.ymd_opt(2014, 11, 31), LocalResult::None); -//! assert_eq!(NaiveDate::from_ymd_opt(2014, 11, 28).unwrap().and_hms_milli_opt(7, 8, 9, 10).unwrap().and_local_timezone(Utc).unwrap().format("%H%M%S").to_string(), -//! "070809"); -//! ``` -//! -//! There is no timezone-aware `Time` due to the lack of usefulness and also the complexity. -//! -//! `DateTime` has [`date`](./struct.DateTime.html#method.date) method -//! which returns a `Date` which represents its date component. -//! There is also a [`time`](./struct.DateTime.html#method.time) method, -//! which simply returns a naive local time described below. -//! //! ### Naive date and time //! //! Chrono provides naive counterparts to `Date`, (non-existent) `Time` and `DateTime` @@ -398,7 +382,7 @@ //! Advanced time zone handling is not yet supported. //! For now you can try the [Chrono-tz](https://github.com/chronotope/chrono-tz/) crate instead. -#![doc(html_root_url = "https://docs.rs/chrono/latest/")] +#![doc(html_root_url = "https://docs.rs/chrono/latest/", test(attr(deny(warnings))))] #![cfg_attr(feature = "bench", feature(test))] // lib stability features as per RFC #507 #![deny(missing_docs)] #![deny(missing_debug_implementations)] @@ -418,6 +402,8 @@ mod oldtime; // this reexport is to aid the transition and should not be in the prelude! pub use oldtime::{Duration, OutOfRangeError}; +use core::fmt; + #[cfg(feature = "__doctest")] #[cfg_attr(feature = "__doctest", cfg(doctest))] use doc_comment::doctest; @@ -502,26 +488,41 @@ pub use naive::__BenchYearFlags; /// Serialization/Deserialization with serde. /// /// This module provides default implementations for `DateTime` using the [RFC 3339][1] format and various -/// alternatives for use with serde's [`with` annotation][1]. +/// alternatives for use with serde's [`with` annotation][2]. /// /// *Available on crate feature 'serde' only.* /// /// [1]: https://tools.ietf.org/html/rfc3339 -/// [2]: https://serde.rs/attributes.html#field-attributes +/// [2]: https://serde.rs/field-attrs.html#with #[cfg(feature = "serde")] #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] pub mod serde { pub use super::datetime::serde::*; } -/// MSRV 1.42 -#[cfg(test)] -#[macro_export] -macro_rules! matches { - ($expression:expr, $(|)? $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => { - match $expression { - $( $pattern )|+ $( if $guard )? => true, - _ => false - } +/// Out of range error type used in various converting APIs +#[derive(Clone, Copy, Hash, PartialEq, Eq)] +pub struct OutOfRange { + _private: (), +} + +impl OutOfRange { + const fn new() -> OutOfRange { + OutOfRange { _private: () } } } + +impl fmt::Display for OutOfRange { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "out of range") + } +} + +impl fmt::Debug for OutOfRange { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "out of range") + } +} + +#[cfg(feature = "std")] +impl std::error::Error for OutOfRange {} |