use chrono::{DateTime, Utc};
use std::cmp::Ordering;
fn get_current_time() -> DateTime<Utc> {
Utc::now()
}
pub type EventFunc = Box<dyn FnOnce(DateTime<Utc>)>;
pub struct Event {
time: DateTime<Utc>, func: EventFunc, }
impl Event {
pub fn new(time: DateTime<Utc>, func: EventFunc) -> Self {
Event { time, func }
}
pub(crate) fn has_expired(&self) -> bool {
get_current_time() >= self.time
}
pub(crate) fn execute(self) {
(self.func)(self.time);
}
}
impl PartialEq for Event {
fn eq(&self, other: &Self) -> bool {
self.time == other.time
}
}
impl Eq for Event {}
impl PartialOrd for Event {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Event {
fn cmp(&self, other: &Self) -> Ordering {
self.time.cmp(&other.time)
}
}