[][src]Struct elastic_types::date::DateExpr

pub struct DateExpr<TFormat> { /* fields omitted */ }

A date math expression.

Date math expressions start from an anchor date, like the literal now or 2017-05-06 and apply math operations to produce a new date value.

Examples

A date expression for now plus 2 days:

let expr: DateExpr<BasicDateTime> = DateExpr::now().add_days(2);

Which serialises to:

"now+2d"

A date expression using a concrete date value plus 2 days:

let expr: DateExpr<BasicDateTime> = DateExpr::value(DateValue::now()).add_days(2);

Which serialises to:

"20150301T145500.000Z||+2d"

Methods

impl<TFormat> DateExpr<TFormat> where
    TFormat: DateFormat
[src]

pub fn now() -> Self[src]

Create a new date expression for now.

This value is different from Date::now() because it doesn't calculate the current date from the system clock. It serialises to the literal string "now", which is interpreted by Elasticsearch when indexing.

pub fn value<TDate>(date: TDate) -> Self where
    TDate: Into<FormattableDateValue<TFormat>>, 
[src]

Create a new date expression from a concrete date value.

If the input is a DateValue, then it'll use any format specified on the DateExpr. If the input is a Date or chrono::DateTime, then the format on its mapping must match the format expected by the DateExpr.

Examples

Create a date expression from a chrono::DateTime:

let date = DateValue::now();

// The format annotation `EpochMillis` is required
let expr: DateExpr<EpochMillis> = DateExpr::value(date);

Create a date expression from a Date:

let date: Date<DefaultDateMapping<EpochMillis>> = Date::now();

// The format `EpochMillis` is inferred
let expr = DateExpr::value(date);

Attempting to create a date expression from a Date with a different format will fail to compile:

let date: Date<DefaultDateMapping<BasicDateTime>> = Date::now();

// Error: expected struct `EpochMillis`, found struct `BasicDateTime`
let expr: DateExpr<EpochMillis> = DateExpr::value(date);

This is to ensure formats aren't silently converted when they shouldn't be, leading to runtime errors in Elasticsearch. Convert the date into a DateValue first:

let date: Date<DefaultDateMapping<BasicDateTime>> = Date::now();

let expr: DateExpr<EpochMillis> = DateExpr::value(DateValue::from(date));

pub fn add_years(self, value: usize) -> Self[src]

Add to the anchored date.

pub fn sub_years(self, value: usize) -> Self[src]

Subtract from the anchored date.

pub fn round_year(self) -> Self[src]

Round the anchored date.

pub fn add_months(self, value: usize) -> Self[src]

Add to the anchored date.

pub fn sub_months(self, value: usize) -> Self[src]

Subtract from the anchored date.

pub fn round_month(self) -> Self[src]

Round the anchored date.

pub fn add_weeks(self, value: usize) -> Self[src]

Add to the anchored date.

pub fn sub_weeks(self, value: usize) -> Self[src]

Subtract from the anchored date.

pub fn round_week(self) -> Self[src]

Round the anchored date.

pub fn add_days(self, value: usize) -> Self[src]

Add to the anchored date.

pub fn sub_days(self, value: usize) -> Self[src]

Subtract from the anchored date.

pub fn round_day(self) -> Self[src]

Round the anchored date.

pub fn add_hours(self, value: usize) -> Self[src]

Add to the anchored date.

pub fn sub_hours(self, value: usize) -> Self[src]

Subtract from the anchored date.

pub fn round_hour(self) -> Self[src]

Round the anchored date.

pub fn add_minutes(self, value: usize) -> Self[src]

Add to the anchored date.

pub fn sub_minutes(self, value: usize) -> Self[src]

Subtract from the anchored date.

pub fn round_minute(self) -> Self[src]

Round the anchored date.

pub fn add_seconds(self, value: usize) -> Self[src]

Add to the anchored date.

pub fn sub_seconds(self, value: usize) -> Self[src]

Subtract from the anchored date.

pub fn round_second(self) -> Self[src]

Round the anchored date.

Trait Implementations

impl<TFormat: PartialEq> PartialEq<DateExpr<TFormat>> for DateExpr<TFormat>[src]

impl<TFormat: Clone> Clone for DateExpr<TFormat>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<TFormat> Display for DateExpr<TFormat> where
    TFormat: DateFormat
[src]

impl<TFormat: Debug> Debug for DateExpr<TFormat>[src]

impl<TFormat> Serialize for DateExpr<TFormat> where
    TFormat: DateFormat
[src]

Auto Trait Implementations

impl<TFormat> Send for DateExpr<TFormat> where
    TFormat: Send

impl<TFormat> Sync for DateExpr<TFormat> where
    TFormat: Sync

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Same for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf for SP where
    SS: SubsetOf<SP>,