Skip to content

Create model::Date from OffsetDateTime, or another way of expanding supported date formats #581

@jesseditson

Description

@jesseditson

Internally, DateTime is represented as

pub struct DateTime {
    inner: DateTimeImpl,
}

where

type DateTimeImpl = time::OffsetDateTime;

My implementation supports broader time parsing than liquid-rust, so I have a time::OffsetDateTime, and need a liquid::model::DateTime. Sadly, because inner is private, I have to serialize to a string and deserialize. I do this during batch imports and it's unnecessarily slow.

I understand that keeping the internal representation private is a reasonable decision given it gives you flexibility on representation later. I do think it might make sense to add an impl From<OffsetDateTime>, which sadly I cannot do from outside the crate given the visibility. This could obviously be feature flagged, and if you do change the inner implementation in the future, the implementation can just parse the OffsetDateTime into the new format, which is future proof and fairly low-cost.

today, the impl would be along the lines of

#[cfg(feature = "date-time-from-offset-date-time")]
impl From<time::OffsetDateTime> for DateTime {
    fn from(value: time::OffsetDateTime) -> Self {
        Self { inner: value }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions