aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-09-22 16:39:00 +0300
committerGravatar Vitaly Takmazov2017-09-22 16:39:00 +0300
commitf3963f0b12055ba6710b9b28ddc93a5b5fe91d67 (patch)
treee05c2a4ab6cdbda573c800d79b89572840222fea /juick-www/src/main/java/com
parent030257f473a92693a4b696acfa745bbf64c98580 (diff)
Initial getNotifications query
* using Java 8 DateTime API where possible
Diffstat (limited to 'juick-www/src/main/java/com')
-rw-r--r--juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java6
-rw-r--r--juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/PrettyTimeFilter.java5
-rw-r--r--juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/TimestampFilter.java23
3 files changed, 28 insertions, 6 deletions
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<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;
+ }
+}