Struct elastic_types::date::Date []

pub struct Date<M> where
    M: DateMapping
{ /* fields omitted */ }

An Elasticsearch date type with a required time component.

The format is provided as a generic parameter. This struct wraps up a chrono::DateTime<Utc> struct, meaning storing time in Utc is required.

Examples

Defining a date using the default format:

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

Defining a date using a named format:

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

Accessing the values of a date:

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

//eg: 2010/04/30 13:56:59.372
println!("{}/{}/{} {}:{}:{}.{}",
    date.year(),
    date.month(),
    date.day(),
    date.hour(),
    date.minute(),
    date.second(),
    date.nanosecond() / 1000000
);

Links

Methods

impl<M> Date<M> where
    M: DateMapping
[src]

Creates a new Date from the given chrono::DateTime<Utc>.

This function will consume the provided chrono date.

Examples

Create a Date from a DateValue:

//Create a DateValue struct
let date = DateValue::now();
    
//Give it to the Date struct
let date: Date<DefaultDateMapping> = Date::new(date);

If the Dates format is ChronoFormat, then it can also be created from chrono::DateTime:

use chrono::Utc;
    
//Create a chrono DateTime struct
let chronoDate = Utc::now();
    
//Give it to the Date struct
let date: Date<DefaultDateMapping<ChronoFormat>> = Date::new(chronoDate);

If the Dates format isn't ChronoFormat, then the chrono::DateTime will need to be converted into a DateValue first. This is to make sure you don't accidentally change the format of a date, which could lead to errors at runtime:

use chrono::Utc;
    
//Create a chrono DateTime struct
let chronoDate = Utc::now();
    
//Give it to the Date struct
let date: Date<DefaultDateMapping<EpochMillis>> = Date::new(DateValue::from(chronoDate));

Creates an Date from the given Utc primitives:

let date: Date<DefaultDateMapping> = Date::build(2015, 5, 14, 16, 45, 8, 886);

Gets the current system time.

Examples

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

Change the format/mapping of this date.

Examples

//Get the current datetime formatted as basic_date_time
let date: Date<DefaultDateMapping<BasicDateTime>> = Date::now();
    
//Change the format to epoch_millis
let otherdate: Date<DefaultDateMapping<EpochMillis>> = Date::remap(date);

Trait Implementations

impl<M: Debug> Debug for Date<M> where
    M: DateMapping,
    M::Format: Debug
[src]

Formats the value using the given formatter.

impl<M: Clone> Clone for Date<M> where
    M: DateMapping,
    M::Format: Clone
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<M: PartialEq> PartialEq for Date<M> where
    M: DateMapping,
    M::Format: PartialEq
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<M> DateFieldType<M> for Date<M> where
    M: DateMapping
[src]

impl<M> From<FormattableDateValue<M::Format>> for Date<M> where
    M: DateMapping
[src]

Performs the conversion.

impl<M> From<DateValue> for Date<M> where
    M: DateMapping
[src]

Performs the conversion.

impl<M> PartialEq<ChronoDateTime> for Date<M> where
    M: DateMapping
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<M> Deref for Date<M> where
    M: DateMapping
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<M> Borrow<ChronoDateTime> for Date<M> where
    M: DateMapping
[src]

Immutably borrows from an owned value. Read more

impl<M> Default for Date<M> where
    M: DateMapping
[src]

Returns the "default value" for a type. Read more

impl<M> Display for Date<M> where
    M: DateMapping
[src]

Formats the value using the given formatter. Read more

impl<M> Serialize for Date<M> where
    M: DateMapping
[src]

Serialize this value into the given Serde serializer. Read more

impl<'de, M> Deserialize<'de> for Date<M> where
    M: DateMapping
[src]

Deserialize this value from the given Serde deserializer. Read more