cobalt-org / liquid-rust

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

Can't render dates with millisecond precision #493

Closed juanazam closed 1 year ago

juanazam commented 1 year ago

liquid-rust version: 0.26.0 rust version: 1.66 OS: macOS Monterrey (12.5)

Hello!

First of all, thanks to the maintainers for all the hard work on this project, I'm far from a Rust expert but I have been able to add custom filters easily which says a lot about the abstractions that the crate provides.

I'm running into an issue which I'm not 100% aware if it's an issue on the create or something I'm doing wrong.

I'm creating DateTime values manually with millisecond precision: 2023-02-22 21:47:07.331 +00:00:00. But whenever I try to process then on filters like this:

{{variable | date: "in milliseconds %L"}} 

I always get "000" as a result. The example date above gets stored within an object as a variable, but for some reason, everytime that the filter is evaluated milliseconds are lost. From what I have been able to debug myself, at some point, the DateTime I created gets converted to a string, and it loses the precision: Str("2023-02-22 21:47:07 +0000")

Any clues on what may I be doing wrong?

juanazam commented 1 year ago

More on this.

I checked out the crate locally and ran some tests.

Updating the following line: https://github.com/cobalt-org/liquid-rust/blob/master/crates/core/src/model/scalar/datetime.rs#L134

To:

"[year]-[month]-[day] [hour]:[minute]:[second].[subsecond] [offset_hour sign:mandatory][offset_minute]"

(added the subsecond part to the format) Seems to do the trick. Would this be an appropriate fix for the issue?