Fixes and enhancements to the date filter #107

Merged
merged 1 commit into from Jan 6, 2017

Projects

None yet

2 participants

@philwhineray
Contributor

No description provided.

src/tera.rs
@@ -350,7 +350,7 @@ impl Tera {
self.register_filter("pluralize", number::pluralize);
self.register_filter("round", number::round);
self.register_filter("filesizeformat", number::filesizeformat);
- self.register_filter("filesizeformat", number::date);
+ self.register_filter("date", number::date);
@Keats
Keats Jan 4, 2017 Owner

ah <_<

src/filters/number.rs
+///
+/// Input can be an i64 timestamp (seconds since epoch) or an RFC3339 string
+/// (default serialization format for chrono::DateTime).
+///
/// Time formatting syntax is inspired from strftime and a full reference is available
/// on [chrono docs](https://lifthrasiir.github.io/rust-chrono/chrono/format/strftime/index.html)
pub fn date(value: Value, args: HashMap<String, Value>) -> Result<Value> {
@Keats
Keats Jan 4, 2017 Owner

since that now works on both number and string, can you put it in common.rs and use pattern matching on the value like in that file?

@Keats
Owner
Keats commented Jan 4, 2017

Thanks, facepalm for the registration of the date filter

@philwhineray
Contributor

Will make the changes as requested and resubmit - it might take me a couple of days as I've quite a bit on.

If you want the registration fix immediately, feel free to cherry pick it or re-implement and I'll rebase.

@philwhineray philwhineray Add RFC3339 format support to the date filter
Should allow, for example, direct use of chrono::DateTime as context
arguments, since RFC3339 is their default serialization format.

Moved the date function into common.rs and use pattern matching to
extract a local date before formatting.
67dd886
@philwhineray
Contributor

Hopefully this is what you had in mind

@Keats
Owner
Keats commented Jan 6, 2017

Looks good, thanks!

@Keats Keats merged commit 813c830 into Keats:master Jan 6, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment