Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bigdecimal = { version = "0.4", optional = true, default-features = false }
chrono = { version = "0.4", optional = true, default-features = false, features = ["alloc"] }
float-cmp = { version = "0.10", optional = true }
indexmap = { version = "2", optional = true, default-features = false }
jiff = { version = "0.2", optional = true, default-features = false, features = ["alloc"] }
jiff = { version = "1", optional = true, default-features = false, features = ["alloc"] }
num-bigint = { version = "0.5", optional = true, default-features = false }
once_cell = { version = "1", optional = true, default-features = false, features = ["alloc", "critical-section"] }
rapidhash = { version = "4", optional = true, default-features = false }
Expand All @@ -68,7 +68,7 @@ time = { version = "0.3", optional = true, default-features = false, features =
[dev-dependencies]
anyhow = "1"
fakeenv = { version = "0.1", default-features = false, features = ["fake"] }
jiff = { version = "0.2", default-features = true }
jiff = { version = "1", default-features = true }
proptest = "1"
serde = { version = "1", default-features = false, features = ["alloc", "derive"] }
serde_bytes = { version = "0.11", default-features = false, features = ["alloc"] }
Expand Down
38 changes: 24 additions & 14 deletions src/jiff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::spec::{
};
use crate::temporal::{TemporalMargin, ToDuration};
use jiff::civil::{Date, DateTime, Time};
use jiff::{SignedDuration, Span, Timestamp, Zoned};
use jiff::{SignedDuration, Span, Timestamp, ZonedDateTime};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -265,29 +265,34 @@ where

impl Invertible for IsCloseTo<DateTime, TemporalMargin> {}

impl<D, R> AssertIsCloseToWithinMargin<Zoned, TemporalMargin> for Spec<'_, Zoned, D, R>
impl<D, R> AssertIsCloseToWithinMargin<ZonedDateTime, TemporalMargin>
for Spec<'_, ZonedDateTime, D, R>
where
D: Represent<Zoned> + Represent<TemporalMargin>,
D: Represent<ZonedDateTime> + Represent<TemporalMargin>,
R: FailingStrategy,
{
fn is_close_to_with_margin(self, expected: Zoned, margin: impl Into<TemporalMargin>) -> Self {
fn is_close_to_with_margin(
self,
expected: ZonedDateTime,
margin: impl Into<TemporalMargin>,
) -> Self {
self.expecting(is_close_to(expected).within_margin(margin))
}

fn is_not_close_to_with_margin(
self,
expected: Zoned,
expected: ZonedDateTime,
margin: impl Into<TemporalMargin>,
) -> Self {
self.expecting(not(is_close_to(expected).within_margin(margin)))
}
}

impl<D> Expectation<Zoned, D> for IsCloseTo<Zoned, TemporalMargin>
impl<D> Expectation<ZonedDateTime, D> for IsCloseTo<ZonedDateTime, TemporalMargin>
where
D: Represent<Zoned> + Represent<TemporalMargin>,
D: Represent<ZonedDateTime> + Represent<TemporalMargin>,
{
fn test(&mut self, subject: &Zoned) -> bool {
fn test(&mut self, subject: &ZonedDateTime) -> bool {
if *subject < self.expected {
subject.duration_until(&self.expected) <= self.margin.to_duration()
} else {
Expand All @@ -298,7 +303,7 @@ where
fn message(
&self,
expression: &Expression<'_>,
actual: &Zoned,
actual: &ZonedDateTime,
inverted: bool,
representation: &D,
format: &DiffFormat,
Expand All @@ -316,7 +321,7 @@ where
}
}

impl Invertible for IsCloseTo<Zoned, TemporalMargin> {}
impl Invertible for IsCloseTo<ZonedDateTime, TemporalMargin> {}

impl<O, D> AssertIsCloseToWithinMargin<Timestamp, TemporalMargin>
for DerivedSpec<'_, O, Timestamp, D>
Expand Down Expand Up @@ -399,18 +404,23 @@ where
}
}

impl<O, D> AssertIsCloseToWithinMargin<Zoned, TemporalMargin> for DerivedSpec<'_, O, Zoned, D>
impl<O, D> AssertIsCloseToWithinMargin<ZonedDateTime, TemporalMargin>
for DerivedSpec<'_, O, ZonedDateTime, D>
where
D: Represent<Zoned> + Represent<TemporalMargin>,
D: Represent<ZonedDateTime> + Represent<TemporalMargin>,
O: DoFail,
{
fn is_close_to_with_margin(self, expected: Zoned, margin: impl Into<TemporalMargin>) -> Self {
fn is_close_to_with_margin(
self,
expected: ZonedDateTime,
margin: impl Into<TemporalMargin>,
) -> Self {
self.expecting(is_close_to(expected).within_margin(margin))
}

fn is_not_close_to_with_margin(
self,
expected: Zoned,
expected: ZonedDateTime,
margin: impl Into<TemporalMargin>,
) -> Self {
self.expecting(not(is_close_to(expected).within_margin(margin)))
Expand Down
32 changes: 16 additions & 16 deletions src/jiff/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::prelude::*;
use crate::temporal::TemporalMargin;
use jiff::civil::{Date, DateTime, Time, date, datetime, time};
use jiff::{SignedDuration, Span, Timestamp, Zoned};
use jiff::{SignedDuration, Span, Timestamp, ZonedDateTime};

#[test]
fn temporal_margin_of_nanoseconds_to_duration() {
Expand Down Expand Up @@ -477,7 +477,7 @@ fn verify_civil_datetime_is_close_to_within_milliseconds_plus_margin_fails() {
}

#[test]
fn zoned_is_equal_to() {
fn zoneddatetime_is_equal_to() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("UTC")
Expand All @@ -492,7 +492,7 @@ fn zoned_is_equal_to() {
}

#[test]
fn zoned_is_before() {
fn zoneddatetime_is_before() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("UTC")
Expand All @@ -507,7 +507,7 @@ fn zoned_is_before() {
}

#[test]
fn zoned_is_after() {
fn zoneddatetime_is_after() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("UTC")
Expand All @@ -522,7 +522,7 @@ fn zoned_is_after() {
}

#[test]
fn zoned_is_between() {
fn zoneddatetime_is_between() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("UTC")
Expand All @@ -541,7 +541,7 @@ fn zoned_is_between() {
}

#[test]
fn zoned_is_close_to_within_milliseconds_exact_equal() {
fn zoneddatetime_is_close_to_within_milliseconds_exact_equal() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("UTC")
Expand All @@ -557,7 +557,7 @@ fn zoned_is_close_to_within_milliseconds_exact_equal() {
}

#[test]
fn zoned_is_close_to_within_milliseconds_plus_margin() {
fn zoneddatetime_is_close_to_within_milliseconds_plus_margin() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("UTC")
Expand All @@ -574,7 +574,7 @@ fn zoned_is_close_to_within_milliseconds_plus_margin() {
}

#[test]
fn zoned_is_close_to_within_milliseconds_minus_margin() {
fn zoneddatetime_is_close_to_within_milliseconds_minus_margin() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("UTC")
Expand All @@ -591,7 +591,7 @@ fn zoned_is_close_to_within_milliseconds_minus_margin() {
}

#[test]
fn verify_zoned_is_close_to_within_seconds_minus_margin_fails() {
fn verify_zoneddatetime_is_close_to_within_seconds_minus_margin_fails() {
let subject = date(2022, 1, 1)
.at(12, 34, 53, 0)
.in_tz("UTC")
Expand Down Expand Up @@ -620,7 +620,7 @@ fn verify_zoned_is_close_to_within_seconds_minus_margin_fails() {
}

#[test]
fn verify_zoned_is_close_to_within_seconds_plus_margin_fails() {
fn verify_zoneddatetime_is_close_to_within_seconds_plus_margin_fails() {
let subject = date(2022, 1, 1)
.at(12, 35, 0, 0)
.in_tz("UTC")
Expand Down Expand Up @@ -648,7 +648,7 @@ fn verify_zoned_is_close_to_within_seconds_plus_margin_fails() {
}

#[test]
fn zoned_is_close_to_within_minutes_different_utc_offset() {
fn zoneddatetime_is_close_to_within_minutes_different_utc_offset() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("Europe/Vienna")
Expand All @@ -664,7 +664,7 @@ fn zoned_is_close_to_within_minutes_different_utc_offset() {
}

#[test]
fn verify_zoned_is_close_to_within_minutes_different_utc_offset_fails() {
fn verify_zoneddatetime_is_close_to_within_minutes_different_utc_offset_fails() {
let subject = date(2022, 1, 1)
.at(12, 34, 56, 0)
.in_tz("Europe/Vienna")
Expand Down Expand Up @@ -740,8 +740,8 @@ fn extracting_ref_civil_datetime_is_close_to_within_milliseconds() {
}

#[test]
fn extracting_ref_zoned_utc_is_close_to_within_minutes() {
struct MyZoned(Zoned);
fn extracting_ref_zoneddatetime_utc_is_close_to_within_minutes() {
struct MyZoned(ZonedDateTime);

let subject = MyZoned(
date(2023, 11, 30)
Expand All @@ -762,8 +762,8 @@ fn extracting_ref_zoned_utc_is_close_to_within_minutes() {
}

#[test]
fn extracting_ref_zoned_tz_is_close_to_within_minutes() {
struct MyZoned(Zoned);
fn extracting_ref_zoneddatetime_tz_is_close_to_within_minutes() {
struct MyZoned(ZonedDateTime);

let subject = MyZoned(
date(2023, 11, 30)
Expand Down
Loading