Struct elastic::types::prelude::DateExpr
[−]
[src]
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]
TFormat: DateFormat,
fn now() -> DateExpr<TFormat>
[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.
fn value<TDate>(date: TDate) -> DateExpr<TFormat> where
TDate: Into<FormattableDateValue<TFormat>>,
[src]
TDate: Into<FormattableDateValue<TFormat>>,
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));
fn add_years(self, value: usize) -> DateExpr<TFormat>
[src]
Add to the anchored date.
fn sub_years(self, value: usize) -> DateExpr<TFormat>
[src]
Subtract from the anchored date.
fn round_year(self) -> DateExpr<TFormat>
[src]
Round the anchored date.
fn add_months(self, value: usize) -> DateExpr<TFormat>
[src]
Add to the anchored date.
fn sub_months(self, value: usize) -> DateExpr<TFormat>
[src]
Subtract from the anchored date.
fn round_month(self) -> DateExpr<TFormat>
[src]
Round the anchored date.
fn add_weeks(self, value: usize) -> DateExpr<TFormat>
[src]
Add to the anchored date.
fn sub_weeks(self, value: usize) -> DateExpr<TFormat>
[src]
Subtract from the anchored date.
fn round_week(self) -> DateExpr<TFormat>
[src]
Round the anchored date.
fn add_days(self, value: usize) -> DateExpr<TFormat>
[src]
Add to the anchored date.
fn sub_days(self, value: usize) -> DateExpr<TFormat>
[src]
Subtract from the anchored date.
fn round_day(self) -> DateExpr<TFormat>
[src]
Round the anchored date.
fn add_hours(self, value: usize) -> DateExpr<TFormat>
[src]
Add to the anchored date.
fn sub_hours(self, value: usize) -> DateExpr<TFormat>
[src]
Subtract from the anchored date.
fn round_hour(self) -> DateExpr<TFormat>
[src]
Round the anchored date.
fn add_minutes(self, value: usize) -> DateExpr<TFormat>
[src]
Add to the anchored date.
fn sub_minutes(self, value: usize) -> DateExpr<TFormat>
[src]
Subtract from the anchored date.
fn round_minute(self) -> DateExpr<TFormat>
[src]
Round the anchored date.
fn add_seconds(self, value: usize) -> DateExpr<TFormat>
[src]
Add to the anchored date.
fn sub_seconds(self, value: usize) -> DateExpr<TFormat>
[src]
Subtract from the anchored date.
fn round_second(self) -> DateExpr<TFormat>
[src]
Round the anchored date.
Trait Implementations
impl<TFormat> Serialize for DateExpr<TFormat> where
TFormat: DateFormat,
[src]
TFormat: DateFormat,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
[src]
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<TFormat> Clone for DateExpr<TFormat> where
TFormat: Clone,
[src]
TFormat: Clone,
fn clone(&self) -> DateExpr<TFormat>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<TFormat> PartialEq<DateExpr<TFormat>> for DateExpr<TFormat> where
TFormat: PartialEq<TFormat>,
[src]
TFormat: PartialEq<TFormat>,
fn eq(&self, __arg_0: &DateExpr<TFormat>) -> bool
[src]
fn ne(&self, __arg_0: &DateExpr<TFormat>) -> bool
[src]
impl<TFormat> Debug for DateExpr<TFormat> where
TFormat: Debug,
[src]
TFormat: Debug,
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<TFormat> Display for DateExpr<TFormat> where
TFormat: DateFormat,
[src]
TFormat: DateFormat,