Struct elastic::types::prelude::Date [] [src]

pub struct Date<F, M = DefaultDateMapping<F>> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
{ /* 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<DefaultDateFormat> = Date::now();

Defining a date using a named format:

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

Defining a date using a custom mapping:

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

Accessing the values of a date:

let date = Date::<BasicDateTime>::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<F, M> Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

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

This function will consume the provided chrono date.

Examples

Create an Date from the given chrono::DateTime:

use chrono::Utc;
use elastic_types::date::{ Date, DefaultDateFormat };
    
//Create a chrono DateTime struct
let chronoDate = Utc::now();
    
//Give it to the Date struct
let esDate: Date<DefaultDateFormat> = Date::new(chronoDate);

Creates an Date from the given Utc primitives:

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

Gets the current system time.

Examples

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

Parse the date and time from a string.

The format of the string must match the given DateFormat.

Examples

Parsing from a specified DateFormat.

let date = Date::<BasicDateTime>::parse("20151126T145543.778Z").unwrap();

Format the date and time as a string.

The format of the string is specified by the given DateFormat.

Examples

let date: Date<BasicDateTime> = Date::now();
let fmt = date.format();
    
//eg: 20151126T145543.778Z
println!("{}", fmt);

Change the format/mapping of this date.

Examples

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

Methods from Deref<Target = DateTime<Utc>>

Retrieves a date component.

Retrieves a time component. Unlike date, this is not associated to the time zone.

Returns the number of non-leap seconds since January 1, 1970 0:00:00 UTC (aka "UNIX timestamp").

Returns the number of milliseconds since the last second boundary

warning: in event of a leap second, this may exceed 999

note: this is not the number of milliseconds since January 1, 1970 0:00:00 UTC

Returns the number of microseconds since the last second boundary

warning: in event of a leap second, this may exceed 999_999

note: this is not the number of microseconds since January 1, 1970 0:00:00 UTC

Returns the number of nanoseconds since the last second boundary

warning: in event of a leap second, this may exceed 999_999_999

note: this is not the number of nanoseconds since January 1, 1970 0:00:00 UTC

Retrieves an associated offset from UTC.

Retrieves an associated time zone.

Changes the associated time zone. This does not change the actual DateTime (but will change the string representation).

Adds given Duration to the current date and time.

Returns None when it will result in overflow.

Subtracts given Duration from the current date and time.

Returns None when it will result in overflow.

Subtracts another DateTime from the current date and time. This does not overflow or underflow at all.

Returns a view to the naive UTC datetime.

Returns a view to the naive local datetime.

Returns an RFC 2822 date and time string such as Tue, 1 Jul 2003 10:52:37 +0200.

Returns an RFC 3339 and ISO 8601 date and time string such as 1996-12-19T16:39:57-08:00.

Formats the combined date and time with the specified formatting items.

Formats the combined date and time with the specified format string. See the format::strftime module on the supported escape sequences.

Trait Implementations

impl<F, M> Display for Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

Formats the value using the given formatter. Read more

impl<F, M> Default for Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

impl<M, F> AsRef<DateTime<Utc>> for Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

impl<F, M> DateFieldType<M, F> for Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

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

impl<F, M> Debug for Date<F, M> where
    F: Debug + DateFormat,
    M: Debug + DateMapping<Format = F>, 
[src]

Formats the value using the given formatter.

impl<F, M> Serialize for Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

Serialize this value into the given Serde serializer. Read more

impl<M, F> From<DateTime<Utc>> for Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

Performs the conversion.

impl<F, M> PartialEq<Date<F, M>> for Date<F, M> where
    F: PartialEq<F> + DateFormat,
    M: PartialEq<M> + DateMapping<Format = F>, 
[src]

impl<M, F> PartialEq<DateTime<Utc>> for Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

impl<M, F> Deref for Date<F, M> where
    F: DateFormat,
    M: DateMapping<Format = F>, 
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<F, M> Clone for Date<F, M> where
    F: Clone + DateFormat,
    M: Clone + DateMapping<Format = F>, 
[src]