From f3963f0b12055ba6710b9b28ddc93a5b5fe91d67 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 22 Sep 2017 16:39:00 +0300 Subject: Initial getNotifications query * using Java 8 DateTime API where possible --- .../pebble/extension/FormatterExtension.java | 6 ++---- .../pebble/extension/filters/PrettyTimeFilter.java | 5 +++-- .../pebble/extension/filters/TimestampFilter.java | 23 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java (limited to 'juick-www/src/main/java/com/mitchellbosecke/pebble') diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java index 7702a316..c8244df4 100644 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java @@ -17,10 +17,7 @@ package com.mitchellbosecke.pebble.extension; -import com.mitchellbosecke.pebble.extension.filters.FormatMessageFilter; -import com.mitchellbosecke.pebble.extension.filters.FormatRepliesFilter; -import com.mitchellbosecke.pebble.extension.filters.PrettyTimeFilter; -import com.mitchellbosecke.pebble.extension.filters.TagsListFilter; +import com.mitchellbosecke.pebble.extension.filters.*; import java.util.HashMap; import java.util.Map; @@ -35,6 +32,7 @@ public class FormatterExtension extends AbstractExtension { filters.put("formatMessage", new FormatMessageFilter()); filters.put("formatReplies", new FormatRepliesFilter()); filters.put("prettyTime", new PrettyTimeFilter()); + filters.put("timestamp", new TimestampFilter()); filters.put("tagsList", new TagsListFilter()); return filters; } diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java index 08e657c8..1d58ce79 100644 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java @@ -21,6 +21,7 @@ import com.juick.util.PrettyTimeFormatter; import com.mitchellbosecke.pebble.extension.Filter; import com.mitchellbosecke.pebble.template.EvaluationContext; +import java.time.Instant; import java.util.Date; import java.util.List; import java.util.Locale; @@ -35,10 +36,10 @@ public class PrettyTimeFilter implements Filter { @Override public Object apply(Object input, Map args) { - if (input instanceof Date) { + if (input instanceof Instant) { EvaluationContext context = (EvaluationContext) args.get("_context"); Locale locale = context.getLocale(); - return formatter.format(locale, (Date)input); + return formatter.format(locale, Date.from((Instant)input)); } throw new IllegalArgumentException("invalid input"); } diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java new file mode 100644 index 00000000..35efb314 --- /dev/null +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java @@ -0,0 +1,23 @@ +package com.mitchellbosecke.pebble.extension.filters; + +import com.mitchellbosecke.pebble.extension.Filter; + +import java.time.Instant; +import java.util.Date; +import java.util.List; +import java.util.Map; + +public class TimestampFilter implements Filter { + @Override + public Object apply(Object input, Map args) { + if (input instanceof Instant) { + return Date.from((Instant)input); + } + throw new IllegalArgumentException("invalid input"); + } + + @Override + public List getArgumentNames() { + return null; + } +} -- cgit v1.2.3