Expand description

Adds a functionality to easily convert between toml_datetime’s and chrono’s/time’s types.

Features

Using serde derive macros

This crate can be used with #[serde(with="toml_datetime_compat")], but the functions deserialize and serialize can also be used on their own to (de)serialize chrono an time types.

Meaning this struct

#[derive(Deserialize, Serialize)]
struct SomeDateTimes {
    #[serde(with = "toml_datetime_compat")]
    chrono_naive_date: chrono::NaiveDate,
    #[serde(with = "toml_datetime_compat")]
    chrono_naive_time: chrono::NaiveTime,
    #[serde(with = "toml_datetime_compat")]
    chrono_naive_date_time: chrono::NaiveDateTime,
    #[serde(with = "toml_datetime_compat")]
    chrono_date_time_utc: chrono::DateTime<chrono::Utc>,
    #[serde(with = "toml_datetime_compat")]
    chrono_date_time_offset: chrono::DateTime<chrono::FixedOffset>,
    #[serde(with = "toml_datetime_compat")]
    time_date: time::Date,
    #[serde(with = "toml_datetime_compat")]
    time_time: time::Time,
    #[serde(with = "toml_datetime_compat")]
    time_primitive_date_time: time::PrimitiveDateTime,
    #[serde(with = "toml_datetime_compat")]
    time_offset_date_time: time::OffsetDateTime,
}

will (de)serialize from/to

naive_date = 1523-08-20
naive_time = 23:54:33.000011235
naive_date_time = 1523-08-20T23:54:33.000011235
date_time_utc = 1523-08-20T23:54:33.000011235Z
date_time_offset = 1523-08-20T23:54:33.000011235+04:30
date = 1523-08-20
time = 23:54:33.000011235
primitive_date_time = 1523-08-20T23:54:33.000011235
offset_date_time = 1523-08-20T23:54:33.000011235+04:30

Using serde_with

It is also possible to use serde_with using the TomlDateTime converter.

This is especially helpful to deserialize optional date time values (due to serde-rs/serde#723).

Using FromToTomlDateTime

And by introducing a new trait FromToTomlDateTime that adds to_toml and from_toml functions to the relevant structs from chrono and time.

Structs

Struct to allow the integration into the serde_with ecosystem

Enums

Error that can occur while transforming TomlDatetime from and to chrono and time types

Traits

Trait that allows easy conversion between TomlDatetime and chrono’s/time’s types

Functions