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

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]

pub fn new<I>(date: I) -> Self where
    I: Into<FormattableDateValue<TMapping::Format>>, 
[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));

pub fn build(
    year: i32,
    month: u32,
    day: u32,
    hour: u32,
    minute: u32,
    second: u32,
    milli: u32
) -> Self
[src]

Creates an Date from the given Utc primitives:

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

pub fn now() -> Self[src]

Gets the current system time.

Examples

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

pub fn remap<TNewMapping>(date: Date<TMapping>) -> Date<TNewMapping> where
    TNewMapping: DateMapping
[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> DateFieldType<TMapping> for Date<TMapping> where
    TMapping: DateMapping
[src]

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

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

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

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

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

Performs copy-assignment from source. Read more

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

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

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

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

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

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

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

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

type Target = ChronoDateTime

The resulting type after dereferencing.

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

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

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

Auto Trait Implementations

impl<TMapping> Send for Date<TMapping> where
    <TMapping as DateMapping>::Format: Send

impl<TMapping> Sync for Date<TMapping> where
    <TMapping as DateMapping>::Format: Sync

Blanket Implementations

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

type Owned = T

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

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

impl<T> From for T[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Same for T

type Output = T

Should always be Self

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