diff options
author | 2017-09-22 16:39:00 +0300 | |
---|---|---|
committer | 2017-09-22 16:39:00 +0300 | |
commit | f3963f0b12055ba6710b9b28ddc93a5b5fe91d67 (patch) | |
tree | e05c2a4ab6cdbda573c800d79b89572840222fea /juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters | |
parent | 030257f473a92693a4b696acfa745bbf64c98580 (diff) |
Initial getNotifications query
* using Java 8 DateTime API where possible
Diffstat (limited to 'juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters')
2 files changed, 26 insertions, 2 deletions
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<String, Object> 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<String, Object> args) { + if (input instanceof Instant) { + return Date.from((Instant)input); + } + throw new IllegalArgumentException("invalid input"); + } + + @Override + public List<String> getArgumentNames() { + return null; + } +} |