Struct Event

Source
pub struct Event { /* private fields */ }
Expand description

Represents an event that happens at a given point in time and may span until an optional end datetime.

Single instant events can be created via Event::at, while Event::new and Event::try_new can be used to construct events with an explict end.

§Example

use jiff::{ToSpan, civil::date};
use recurring::Event;

let start = date(2025, 1, 1).at(0, 0, 0, 0);
let end = date(2025, 1, 2).at(0, 0, 0, 0);
let event = Event::new(start, end);
assert_eq!(event.start(), start);
assert_eq!(event.end(), Some(end));
assert_eq!(event.duration().fieldwise(), 1.day());

Implementations§

Source§

impl Event

Source

pub fn at(instant: DateTime) -> Event

Creates a new Event which starts and ends at instant.

The event duration is effectively zero.

§Example
use jiff::civil::date;
use recurring::Event;

let start = date(2025, 1, 1).at(0, 0, 0, 0);
let event = Event::at(start);
Source

pub fn new(start: DateTime, end: DateTime) -> Event

Creates a new Event which spans from a start (inclusive) to an end (exclusive).

The fallible version of this method is Event::try_new.

§Panics

Panics if start >= end.

§Example
use jiff::civil::date;
use recurring::Event;

let start = date(2025, 1, 1).at(0, 0, 0, 0);
let end = date(2025, 1, 2).at(0, 0, 0, 0);
let event = Event::new(start, end);
Source

pub fn try_new(start: DateTime, end: DateTime) -> Result<Event, Error>

Creates a new Event which spans from a start (inclusive) to an end (exclusive).

The panicking version of this method is Event::new.

§Errors

Returns and Error if start >= end.

§Example
use jiff::civil::date;
use recurring::Event;

let start = date(2025, 1, 1).at(0, 0, 0, 0);
let end = date(2025, 1, 2).at(0, 0, 0, 0);
let event = Event::try_new(start, end)?;
Source

pub fn start(&self) -> DateTime

Returns the DateTime at which the event starts.

§Example
use jiff::civil::date;
use recurring::Event;

let start = date(2025, 1, 1).at(0, 0, 0, 0);
let event = Event::at(start);
assert_eq!(event.start(), start);
Source

pub fn end(&self) -> Option<DateTime>

Returns the DateTime at which the event ends if it has an end, None otherwise.

§Example
use jiff::civil::date;
use recurring::Event;

let start = date(2025, 1, 1).at(0, 0, 0, 0);
let event = Event::at(start);
assert!(event.end().is_none());

let end = date(2025, 1, 2).at(0, 0, 0, 0);
let event = Event::new(start, end);
assert_eq!(event.end(), Some(end));
Source

pub fn duration(&self) -> Span

Returns the duration between the events’ start and end.

For events that don’t have an end, this always returns a zero Span.

§Example
use jiff::{ToSpan, civil::date};
use recurring::Event;

let start = date(2025, 1, 1).at(0, 0, 0, 0);
let event = Event::at(start);
assert!(event.duration().is_zero());

let end = date(2025, 1, 2).at(0, 0, 0, 0);
let event = Event::new(start, end);
assert_eq!(event.duration().fieldwise(), 1.day());
Source

pub fn contains(&self, instant: DateTime) -> bool

Returns true if instant falls within the events’ duration, false otherwise.

For events that don’t have an end, this is equivalent to event.start() == instant.

§Example
use jiff::{ToSpan, civil::date};
use recurring::Event;

let start = date(2025, 1, 1).at(0, 0, 0, 0);
let event = Event::at(start);
assert!(!event.contains(start - 1.nanosecond()));
assert!(event.contains(start));
assert!(!event.contains(start + 1.nanosecond()));

let end = date(2025, 1, 2).at(0, 0, 0, 0);
let event = Event::new(start, end);
assert!(!event.contains(start - 1.nanosecond()));
assert!(event.contains(start));
assert!(event.contains(start + 1.nanosecond()));
assert!(event.contains(end - 1.nanosecond()));
assert!(!event.contains(end));
assert!(!event.contains(end + 1.nanosecond()));

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Event

Source§

fn cmp(&self, other: &Event) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Event

Source§

fn partial_cmp(&self, other: &Event) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToSeries for Event

Source§

fn to_series<P: Pattern>(&self, pattern: P) -> Result<Series<P>, Error>

Converts an Event to a Series with the given recurrence Pattern.

§Errors

Returns an error if the event duration cannot be represented as a Span or if the events’ start is DateTime::MAX.

§Example
use jiff::civil::date;
use recurring::{Event, ToSeries, pattern::hourly};

let date = date(2025, 1, 1);
let start = date.at(0, 0, 0, 0);
let end = date.at(0, 30, 0, 0);

let event = Event::new(start, end);
let series = event.to_series(hourly(2))?;

let mut events = series.iter();

assert_eq!(events.next(), Some(Event::new(date.at(0, 0, 0, 0), date.at(0, 30, 0, 0))));
assert_eq!(events.next(), Some(Event::new(date.at(2, 0, 0, 0), date.at(2, 30, 0, 0))));
Source§

impl Eq for Event

Source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.