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

pub trait DateFormat where
    Self: Default
{ 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

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

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

The name of the format.

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

Implementors