[][src]Trait elastic_types::date::prelude::DateFormat

pub trait DateFormat {
    fn parse(date: &str) -> Result<DateValue, ParseError>;
fn format<'a>(date: &'a DateValue) -> FormattedDate<'a>;
fn name() -> &'static str; }

A format used for parsing and formatting dates.

The format is specified as two functions: parse and format. A general DateValue is used as an intermediate value passed as input and produced as output for formatting.

Examples

The easiest way to implement DateFormat is to derive ElasticDateFormat on a unit struct:

#[derive(Default, ElasticDateFormat)]
#[elastic(date_format="yyyy-MM-dd'T'HH:mm:ss")]
struct MyFormat;

The #[elastic(date_format)] attribute is required, and must contain a valid format string.

NOTE: Only a small subset of the Joda time format is supported.

You can customise the indexed format name by adding an #[elastic(date_format_name)] attribute:

#[derive(Default, ElasticDateFormat)]
#[elastic(date_format="yyyyMMdd'T'HHmmssZ", date_format_name="basic_date_time_no_millis")]
struct MyFormat;

Required methods

fn parse(date: &str) -> Result<DateValue, ParseError>

Parses a date string to a chrono::DateTime<Utc> result.

fn format<'a>(date: &'a DateValue) -> FormattedDate<'a>

Formats a given chrono::DateTime<Utc> as a string.

fn name() -> &'static str

The name of the format.

This is the string used when defining the format in the field mapping.

Loading content...

Implementors

impl DateFormat for BasicDateTime[src]

impl DateFormat for BasicDateTimeNoMillis[src]

impl DateFormat for ChronoFormat[src]

impl DateFormat for EpochMillis[src]

Loading content...