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]
TMapping: DateMapping,
fn new<I>(date: I) -> Self where
I: Into<FormattableDateValue<TMapping::Format>>,
[src]
I: Into<FormattableDateValue<TMapping::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
[src]
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
[src]
fn remap<TNewMapping>(date: Date<TMapping>) -> Date<TNewMapping> where
TNewMapping: DateMapping,
[src]
TNewMapping: 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<TMapping: Debug> Debug for Date<TMapping> where
TMapping: DateMapping,
TMapping::Format: Debug,
[src]
TMapping: DateMapping,
TMapping::Format: Debug,
impl<TMapping: Clone> Clone for Date<TMapping> where
TMapping: DateMapping,
TMapping::Format: Clone,
[src]
TMapping: DateMapping,
TMapping::Format: Clone,
fn clone(&self) -> Date<TMapping>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
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]
TMapping: DateMapping,
TMapping::Format: PartialEq,
fn eq(&self, __arg_0: &Date<TMapping>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Date<TMapping>) -> bool
[src]
This method tests for !=
.
impl<TMapping> DateFieldType<TMapping> for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
impl<TMapping> From<FormattableDateValue<TMapping::Format>> for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
fn from(date: FormattableDateValue<TMapping::Format>) -> Self
[src]
Performs the conversion.
impl<TMapping> From<DateValue> for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
impl<TMapping> PartialEq<ChronoDateTime> for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
fn eq(&self, other: &ChronoDateTime) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &ChronoDateTime) -> bool
[src]
This method tests for !=
.
impl<TMapping> Deref for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
type Target = ChronoDateTime
The resulting type after dereferencing.
fn deref(&self) -> &ChronoDateTime
[src]
Dereferences the value.
impl<TMapping> Borrow<ChronoDateTime> for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
fn borrow(&self) -> &ChronoDateTime
[src]
Immutably borrows from an owned value. Read more
impl<TMapping> Default for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
impl<TMapping> Display for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
fn fmt(&self, f: &mut Formatter) -> FmtResult
[src]
Formats the value using the given formatter. Read more
impl<TMapping> Serialize for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
[src]
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de, TMapping> Deserialize<'de> for Date<TMapping> where
TMapping: DateMapping,
[src]
TMapping: DateMapping,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more