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]
M: DateMapping,
fn new<I>(date: I) -> Self where
I: Into<FormattableDateValue<M::Format>>,
I: Into<FormattableDateValue<M::Format>>,
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 Date
s 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 Date
s 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));
fn build(
year: i32,
month: u32,
day: u32,
hour: u32,
minute: u32,
second: u32,
milli: u32
) -> Self
year: i32,
month: u32,
day: u32,
hour: u32,
minute: u32,
second: u32,
milli: u32
) -> Self
Creates an Date
from the given Utc primitives:
let date: Date<DefaultDateMapping> = Date::build(2015, 5, 14, 16, 45, 8, 886);
fn now() -> Self
fn remap<MInto>(date: Date<M>) -> Date<MInto> where
MInto: DateMapping,
MInto: DateMapping,
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]
M: DateMapping,
M::Format: Debug,
impl<M: Clone> Clone for Date<M> where
M: DateMapping,
M::Format: Clone,
[src]
M: DateMapping,
M::Format: Clone,
fn clone(&self) -> Date<M>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<M: PartialEq> PartialEq for Date<M> where
M: DateMapping,
M::Format: PartialEq,
[src]
M: DateMapping,
M::Format: PartialEq,
fn eq(&self, __arg_0: &Date<M>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Date<M>) -> bool
This method tests for !=
.
impl<M> DateFieldType<M> for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
impl<M> From<FormattableDateValue<M::Format>> for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
fn from(date: FormattableDateValue<M::Format>) -> Self
Performs the conversion.
impl<M> From<DateValue> for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
impl<M> PartialEq<ChronoDateTime> for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
fn eq(&self, other: &ChronoDateTime) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &ChronoDateTime) -> bool
This method tests for !=
.
impl<M> Deref for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
type Target = ChronoDateTime
The resulting type after dereferencing
fn deref(&self) -> &ChronoDateTime
The method called to dereference a value
impl<M> Borrow<ChronoDateTime> for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
fn borrow(&self) -> &ChronoDateTime
Immutably borrows from an owned value. Read more
impl<M> Default for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
impl<M> Display for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
fn fmt(&self, f: &mut Formatter) -> FmtResult
Formats the value using the given formatter. Read more
impl<M> Serialize for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de, M> Deserialize<'de> for Date<M> where
M: DateMapping,
[src]
M: DateMapping,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more