use num_conv::prelude::*; use quickcheck::{Arbitrary, TestResult}; use quickcheck_macros::quickcheck; use time::macros::{format_description, time}; use time::Weekday::*; use time::{Date, Duration, Month, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset, Weekday};
#[quickcheck] fn date_format_century_last_two_equivalent(d: Date) -> bool { let split_format = format_description!("[year repr:century][year repr:last_two]-[month]-[day]"); let split = d.format(&split_format).expect("formatting failed");
let combined_format = format_description!("[year]-[month]-[day]"); let combined = d.format(&combined_format).expect("formatting failed");
split == combined
}
#[quickcheck] fn date_parse_century_last_two_equivalent_extended(d: Date) -> TestResult { // With the extended range, there is an ambiguity when parsing a year with fewer than six // digits, as the first four are consumed by the century, leaving at most one for the last // two digits. if !matches!(d.year().unsigned_abs().to_string().len(), 6) { return TestResult::discard();
}
let split_format = format_description!("[year repr:century][year repr:last_two]-[month]-[day]"); let combined_format = format_description!("[year]-[month]-[day]"); let combined = d.format(&combined_format).expect("formatting failed");
#[quickcheck] fn date_parse_century_last_two_equivalent_standard(d: Date) -> TestResult { // With the standard range, the year must be at most four digits. if !matches!(d.year(), -9999..=9999) { return TestResult::discard();
}
let split_format = format_description!( "[year repr:century range:standard][year repr:last_two range:standard]-[month]-[day]"
); let combined_format = format_description!("[year range:standard]-[month]-[day]"); let combined = d.format(&combined_format).expect("formatting failed");
#[quickcheck] fn offset_date_time_roundtrip(a: OffsetDateTime) -> TestResult { // Values near the edge of what is allowed may panic if the conversion brings the underlying // value outside the valid range of values. if a.date() == Date::MIN || a.date() == Date::MAX { return TestResult::discard();
}
TestResult::from_bool(PrimitiveDateTime::new(a.date(), a.time()).assume_offset(a.offset()) == a)
}
#[quickcheck] fn unix_timestamp_roundtrip(odt: OffsetDateTime) -> TestResult { match odt.date() {
Date::MIN | Date::MAX => TestResult::discard(),
_ => TestResult::from_bool({ // nanoseconds are not stored in the basic Unix timestamp let odt = odt - Duration::nanoseconds(odt.nanosecond().into());
OffsetDateTime::from_unix_timestamp(odt.unix_timestamp()) == Ok(odt)
}),
}
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet am 2026-08-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.