tera icon indicating copy to clipboard operation
tera copied to clipboard

Make `date` filter work on a RFC3339 string as well

Open blfpd opened this issue 10 months ago • 0 comments

Add capability of the Tera filter {{ s | date }} to parse strings formatted as RFC 2822.

Example of RFC 2822 dates:

Fri, 25 Oct 2024 10:30:00 GMT
Fri, 25 Oct 2024 10:30:00 -0500
25 Oct 2024 10:30:00 +0200

Implementation

Hopefuly chrono supports it out of the box.

In the implementation, we can’t just test if the string contains a T as the timezone GMT is commonly used. So I added the T test at the second place. I tested a string that might be of format 2822 if it contains at least 3 spaces. If you find a better implementation, I open to suggetions.

Motivation

In Zola, when using load_data(url="https://anchor.fm/s/41f4a6b4/podcast/rss"), the dates are formatted as RFC 2822, instead of a more common format. I wanted to format them the way I intended.

blfpd avatar Feb 28 '25 12:02 blfpd