Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time window Display impl #53

Merged
merged 2 commits into from
Feb 7, 2024
Merged
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
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,12 @@ impl TimeWindow {
}
}

impl Display for TimeWindow {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}, {}]", self.start, self.end)
}
}

/// A duration of time.
///
/// Duration can be negative. Internally duration is represented as
Expand Down Expand Up @@ -1590,6 +1596,18 @@ mod duration_test {
assert_eq!("-1m1s", Duration::seconds(-61).to_string());
}

#[test]
fn test_time_window_display() {
assert_eq!(
"[1970-01-01T00:00:00+00:00, ∞]",
TimeWindow::new(Time::EPOCH, Time::MAX).to_string()
);
assert_eq!(
"[1970-01-01T01:00:00+00:00, 2024-02-06T16:53:47+00:00]",
TimeWindow::new(Time::hours(1), Time::millis(1707238427962)).to_string()
);
}

#[test]
fn test_duration_is_non_negative_returns_correctly() {
struct TestCase {
Expand Down
Loading