mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-28 05:21:39 +00:00
Implement Arbitrary for timezones
This commit is contained in:
parent
c879b18dbf
commit
de57f5617a
@ -152,6 +152,16 @@ impl fmt::Display for FixedOffset {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "arbitrary")]
|
||||||
|
impl arbitrary::Arbitrary<'_> for FixedOffset {
|
||||||
|
fn arbitrary(u: &mut arbitrary::Unstructured) -> arbitrary::Result<FixedOffset> {
|
||||||
|
let secs = u.int_in_range(-86_399..=86_399)?;
|
||||||
|
let fixed_offset = FixedOffset::east_opt(secs)
|
||||||
|
.expect("Could not generate a valid chrono::FixedOffset. It looks like implementation of Arbitrary for FixedOffset is erroneous.");
|
||||||
|
Ok(fixed_offset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// addition or subtraction of FixedOffset to/from Timelike values is the same as
|
// addition or subtraction of FixedOffset to/from Timelike values is the same as
|
||||||
// adding or subtracting the offset's local_minus_utc value
|
// adding or subtracting the offset's local_minus_utc value
|
||||||
// but keep keeps the leap second information.
|
// but keep keeps the leap second information.
|
||||||
|
@ -52,6 +52,7 @@ mod tz_info;
|
|||||||
/// ```
|
/// ```
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
|
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
|
||||||
|
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||||
pub struct Local;
|
pub struct Local;
|
||||||
|
|
||||||
impl Local {
|
impl Local {
|
||||||
|
@ -41,6 +41,7 @@ use crate::{Date, DateTime};
|
|||||||
/// ```
|
/// ```
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
|
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
|
||||||
|
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
|
||||||
pub struct Utc;
|
pub struct Utc;
|
||||||
|
|
||||||
#[cfg(feature = "clock")]
|
#[cfg(feature = "clock")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user