pub struct IntervalEndpoints {
pub from: Option<TimePoint>,
pub to: Option<TimePoint>,
}Expand description
A resolved time value — either a single point or an interval.
use duckling::{parse, Locale, Lang, Context, Options, DimensionKind,
DimensionValue, TimeValue, TimePoint, Grain};
use chrono::{NaiveDate, TimeZone, Utc};
let locale = Locale::new(Lang::EN, None);
let context = Context {
reference_time: Utc.with_ymd_and_hms(2013, 2, 12, 4, 30, 0).unwrap(),
..Context::default()
};
let options = Options::default();
// Single time point
let results = parse("tomorrow", &locale, &[DimensionKind::Time], &context, &options);
if let DimensionValue::Time(TimeValue::Single { value: TimePoint::Naive { value, grain }, .. }) = &results[0].value {
assert_eq!(*value, NaiveDate::from_ymd_opt(2013, 2, 13).unwrap().and_hms_opt(0, 0, 0).unwrap());
assert_eq!(*grain, Grain::Day);
} else { panic!("expected Naive time point"); }
// Time interval
let results = parse("from 3pm to 5pm", &locale, &[DimensionKind::Time], &context, &options);
if let DimensionValue::Time(TimeValue::Interval { from: Some(f), to: Some(t), .. }) = &results[0].value {
assert!(matches!(f, TimePoint::Naive { value, grain: Grain::Hour }
if *value == NaiveDate::from_ymd_opt(2013, 2, 12).unwrap().and_hms_opt(15, 0, 0).unwrap()));
assert!(matches!(t, TimePoint::Naive { value, grain: Grain::Hour }
if *value == NaiveDate::from_ymd_opt(2013, 2, 12).unwrap().and_hms_opt(18, 0, 0).unwrap()));
} else { panic!("expected Interval time value"); }A pair of interval endpoints, used in the values array for intervals.
Fields§
§from: Option<TimePoint>The start of the interval, if bounded.
to: Option<TimePoint>The end of the interval, if bounded.
Trait Implementations§
Source§impl Clone for IntervalEndpoints
impl Clone for IntervalEndpoints
Source§fn clone(&self) -> IntervalEndpoints
fn clone(&self) -> IntervalEndpoints
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for IntervalEndpoints
impl Debug for IntervalEndpoints
Source§impl PartialEq for IntervalEndpoints
impl PartialEq for IntervalEndpoints
Source§impl Serialize for IntervalEndpoints
impl Serialize for IntervalEndpoints
impl StructuralPartialEq for IntervalEndpoints
Auto Trait Implementations§
impl Freeze for IntervalEndpoints
impl RefUnwindSafe for IntervalEndpoints
impl Send for IntervalEndpoints
impl Sync for IntervalEndpoints
impl Unpin for IntervalEndpoints
impl UnsafeUnpin for IntervalEndpoints
impl UnwindSafe for IntervalEndpoints
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more