mitsuhiko / minijinja

MiniJinja is a powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
https://docs.rs/minijinja/
Apache License 2.0
1.64k stars 99 forks source link

Custom time format strings #497

Closed WesleyAC closed 6 months ago

WesleyAC commented 6 months ago

It would be great to use custom strftime style format string with dateformat and the other time/date functions, or perhaps more cleanly, just make a strftime filter.

mitsuhiko commented 6 months ago

Can you be more specific of what the ask is? The filter already supports custom date formatting, but it uses a different format than strftime.

WesleyAC commented 6 months ago

Yeah — I was looking at the minijinja_contrib filters which support formats like short/medium/long/full/iso/unix, but don't allow fully custom formatting. Looking at the built-in filters I don't see any relating to time formatting.

What function should I be looking for that does custom date formatting?

mitsuhiko commented 6 months ago

@WesleyAC they support any of the formats from the time crate. So you can do this:

{{ foo|dateformat(format="[weekday], [month repr:long] [day padding:none] [year]") }}
WesleyAC commented 6 months ago

Is this format documented anywhere?

mitsuhiko commented 6 months ago

@WesleyAC yes, it's documented in the time crate: https://time-rs.github.io/book/api/format-description.html