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]
F: DateFormat,
M: DateMapping<Format = F>,
fn new(date: DateTime<Utc>) -> Date<F, M>
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);
fn build(
year: i32,
month: u32,
day: u32,
hour: u32,
minute: u32,
second: u32,
milli: u32
) -> Date<F, M>
year: i32,
month: u32,
day: u32,
hour: u32,
minute: u32,
second: u32,
milli: u32
) -> Date<F, M>
Creates an Date
from the given Utc primitives:
let esDate: Date<DefaultDateFormat> = Date::build(2015, 5, 14, 16, 45, 8, 886);
fn now() -> Date<F, M>
fn parse(date: &str) -> Result<Date<F, M>, ParseError>
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();
fn format(&self) -> String
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);
fn remap<FInto, MInto>(self) -> Date<FInto, MInto> where
FInto: DateFormat,
MInto: DateMapping<Format = FInto>,
FInto: DateFormat,
MInto: DateMapping<Format = FInto>,
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>>
fn date(&self) -> Date<Tz>
Retrieves a date component.
fn time(&self) -> NaiveTime
Retrieves a time component.
Unlike date
, this is not associated to the time zone.
fn timestamp(&self) -> i64
Returns the number of non-leap seconds since January 1, 1970 0:00:00 UTC (aka "UNIX timestamp").
fn timestamp_subsec_millis(&self) -> u32
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
fn timestamp_subsec_micros(&self) -> u32
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
fn timestamp_subsec_nanos(&self) -> u32
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
fn offset(&'a self) -> &'a <Tz as TimeZone>::Offset
Retrieves an associated offset from UTC.
fn timezone(&self) -> Tz
Retrieves an associated time zone.
fn with_timezone<Tz2>(&self, tz: &Tz2) -> DateTime<Tz2> where
Tz2: TimeZone,
Tz2: TimeZone,
Changes the associated time zone.
This does not change the actual DateTime
(but will change the string representation).
fn checked_add_signed(self, rhs: Duration) -> Option<DateTime<Tz>>
Adds given Duration
to the current date and time.
Returns None
when it will result in overflow.
fn checked_sub_signed(self, rhs: Duration) -> Option<DateTime<Tz>>
Subtracts given Duration
from the current date and time.
Returns None
when it will result in overflow.
fn signed_duration_since<Tz2>(self, rhs: DateTime<Tz2>) -> Duration where
Tz2: TimeZone,
Tz2: TimeZone,
Subtracts another DateTime
from the current date and time.
This does not overflow or underflow at all.
fn naive_utc(&self) -> NaiveDateTime
Returns a view to the naive UTC datetime.
fn naive_local(&self) -> NaiveDateTime
Returns a view to the naive local datetime.
fn to_rfc2822(&self) -> String
Returns an RFC 2822 date and time string such as Tue, 1 Jul 2003 10:52:37 +0200
.
fn to_rfc3339(&self) -> String
Returns an RFC 3339 and ISO 8601 date and time string such as 1996-12-19T16:39:57-08:00
.
fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I> where
I: Iterator<Item = Item<'a>> + Clone,
I: Iterator<Item = Item<'a>> + Clone,
Formats the combined date and time with the specified formatting items.
fn format(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Formats the combined date and time with the specified format string.
See the format::strftime
module
on the supported escape sequences.
Trait Implementations
impl<M, F> Deref for Date<F, M> where
F: DateFormat,
M: DateMapping<Format = F>,
[src]
F: DateFormat,
M: DateMapping<Format = F>,
type Target = DateTime<Utc>
The resulting type after dereferencing
fn deref(&self) -> &DateTime<Utc>
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]
F: Clone + DateFormat,
M: Clone + DateMapping<Format = F>,
impl<F, M> Display for Date<F, M> where
F: DateFormat,
M: DateMapping<Format = F>,
[src]
F: DateFormat,
M: DateMapping<Format = F>,
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
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]
F: DateFormat,
M: DateMapping<Format = F>,
impl<M, F> AsRef<DateTime<Utc>> for Date<F, M> where
F: DateFormat,
M: DateMapping<Format = F>,
[src]
F: DateFormat,
M: DateMapping<Format = F>,
impl<F, M> DateFieldType<M, F> for Date<F, M> where
F: DateFormat,
M: DateMapping<Format = F>,
[src]
F: DateFormat,
M: DateMapping<Format = F>,
impl<F, M> Debug for Date<F, M> where
F: Debug + DateFormat,
M: Debug + DateMapping<Format = F>,
[src]
F: Debug + DateFormat,
M: Debug + DateMapping<Format = F>,
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<F, M> Serialize for Date<F, M> where
F: DateFormat,
M: DateMapping<Format = F>,
[src]
F: DateFormat,
M: DateMapping<Format = F>,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
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]
F: DateFormat,
M: DateMapping<Format = F>,
impl<'de, F, M> Deserialize<'de> for Date<F, M> where
F: DateFormat,
M: DateMapping<Format = F>,
[src]
F: DateFormat,
M: DateMapping<Format = F>,
fn deserialize<D>(
deserializer: D
) -> Result<Date<F, M>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
deserializer: D
) -> Result<Date<F, M>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
impl<F, M> PartialEq<Date<F, M>> for Date<F, M> where
F: PartialEq<F> + DateFormat,
M: PartialEq<M> + DateMapping<Format = F>,
[src]
F: PartialEq<F> + DateFormat,
M: PartialEq<M> + DateMapping<Format = F>,
impl<M, F> PartialEq<DateTime<Utc>> for Date<F, M> where
F: DateFormat,
M: DateMapping<Format = F>,
[src]
F: DateFormat,
M: DateMapping<Format = F>,