Struct elastic_types::date::Date [] [src]

pub struct Date<TMapping> where
    TMapping: 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<TMapping> Date<TMapping> where
    TMapping: DateMapping
[src]

[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));

[src]

Creates an Date from the given Utc primitives:

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

[src]

Gets the current system time.

Examples

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

[src]

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<TMapping: Debug> Debug for Date<TMapping> where
    TMapping: DateMapping,
    TMapping::Format: Debug
[src]

[src]

Formats the value using the given formatter.

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

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

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

[src]

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

[src]

This method tests for !=.

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

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

[src]

Performs the conversion.

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

[src]

Performs the conversion.

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

[src]

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

[src]

This method tests for !=.

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

The resulting type after dereferencing.

[src]

Dereferences the value.

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

[src]

Immutably borrows from an owned value. Read more

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

[src]

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

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

[src]

Formats the value using the given formatter. Read more

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

[src]

Serialize this value into the given Serde serializer. Read more

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

[src]

Deserialize this value from the given Serde deserializer. Read more