cobalt-org / liquid-rust

Liquid templating for Rust
docs.rs/liquid
MIT License
473 stars 79 forks source link

Support millisecond precision on date variables #494

Closed juanazam closed 1 year ago

juanazam commented 1 year ago

Closes #493

To sum up, the problem describe on the issue is the following:

const DATE_TIME_FORMAT: &[time::format_description::FormatItem<'static>] = time::macros::format_description!(
    "[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour sign:mandatory][offset_minute]"
);

This format format doesn't include the subsecond component, so when a variable was being serialized, the subseconds were lost.

This PR introduces a new format for serialization and uses it for that purpose:

const DATE_TIME_FORMAT_SUBSEC: &[time::format_description::FormatItem<'static>] = time::macros::format_description!(
    "[year]-[month]-[day] [hour]:[minute]:[second].[subsecond] [offset_hour sign:mandatory][offset_minute]"
);

I also added it to the list of supported parsing date formats

epage commented 1 year ago

Ignore appveyor, I can't get it off our CI. Just need the rustfmt issue resolved

juanazam commented 1 year ago

From what I saw, only commit messages were failing, that's what you meant? updated!

juanazam commented 1 year ago

Saw the formatting issue, and fixed that as well!

epage commented 1 year ago

Thanks!

tglman commented 1 year ago

Hi,

From this implementation, now the date format in case of reading require .[subsecond] this make the reading of dates without that part fail, this functionality is used in cobalt for frontmatter parsing, so if you cargo update cobalt you want be able to parse the old frontmatters that miss the subseconds, I think to fix this should be enough to add the double parsing of dates in case of deserialization, like there is optional serialization of subseconds.

Regards