diff options
Diffstat (limited to 'juick-www')
9 files changed, 42 insertions, 20 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; + } +} diff --git a/juick-www/src/main/webapp/WEB-INF/views/macros/tree.html b/juick-www/src/main/webapp/WEB-INF/views/macros/tree.html index 09ba5365..f0c283e9 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/macros/tree.html +++ b/juick-www/src/main/webapp/WEB-INF/views/macros/tree.html @@ -20,9 +20,9 @@ </div> <div class="msg-ts"> <a href="/{{ msg.mid }}#{{ msg.rid }}"> - <time datetime="{{ msg.date | date('yyyy-MM-dd HH:mm:ss') }}Z" - title="{{ msg.date | date('yyyy-MM-dd HH:mm:ss') }} GMT"> - {{ msg.date | prettyTime }} + <time datetime="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }}Z" + title="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }} GMT"> + {{ msg.timestamp | prettyTime }} </time> </a> </div> diff --git a/juick-www/src/main/webapp/WEB-INF/views/partial/message.html b/juick-www/src/main/webapp/WEB-INF/views/partial/message.html index b3ff86cd..f3a42ff2 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/partial/message.html +++ b/juick-www/src/main/webapp/WEB-INF/views/partial/message.html @@ -7,9 +7,9 @@ <div class="msg-menu"><a href="#"><i data-icon="ei-link" data-size="s"></i></a></div> <div class="msg-ts"> <a href="/{{ msg.user.name }}/{{ msg.mid }}"> - <time datetime="{{ msg.date | date('yyyy-MM-dd HH:mm:ss') }}Z" - title="{{ msg.date | date('yyyy-MM-dd HH:mm:ss') }} GMT"> - {{ msg.date | prettyTime }} + <time datetime="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }}Z" + title="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }} GMT"> + {{ msg.timestamp | prettyTime }} </time> </a> </div> diff --git a/juick-www/src/main/webapp/WEB-INF/views/partial/thread_list.html b/juick-www/src/main/webapp/WEB-INF/views/partial/thread_list.html index 275ffeaf..918c4fb0 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/partial/thread_list.html +++ b/juick-www/src/main/webapp/WEB-INF/views/partial/thread_list.html @@ -18,9 +18,9 @@ </div> <div class="msg-ts"> <a href="/{{ msg.mid }}#{{ msg.rid }}"> - <time datetime="{{ msg.date | date('yyyy-MM-dd HH:mm:ss') }}Z" - title="{{ msg.date | date('yyyy-MM-dd HH:mm:ss') }} GMT"> - {{ msg.date | prettyTime }} + <time datetime="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }}Z" + title="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }} GMT"> + {{ msg.timestamp | prettyTime }} </time> </a> </div> diff --git a/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html b/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html index a8a8a1e9..156877c0 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html +++ b/juick-www/src/main/webapp/WEB-INF/views/pm_inbox.html @@ -12,7 +12,7 @@ <img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/> </a> </div> - <div class="msg-ts">{{ msg.date }}</div> + <div class="msg-ts">{{ msg.timestamp | prettyTime }}</div> </div> <div class="msg-txt">{{ msg | formatMessage }}</div> diff --git a/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html b/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html index 48aaa7e1..08b9585a 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html +++ b/juick-www/src/main/webapp/WEB-INF/views/pm_sent.html @@ -19,7 +19,7 @@ <img src="//i.juick.com/a/{{ msg.user.uid }}.png" alt="{{ msg.user.name }}"/> </a> </div> - <div class="msg-ts">{{ msg.date }}</div> + <div class="msg-ts">{{ msg.timestamp | prettyTime }}</div> </div> <div class="msg-txt">{{ msg | formatMessage }}</div> </div> diff --git a/juick-www/src/main/webapp/WEB-INF/views/thread.html b/juick-www/src/main/webapp/WEB-INF/views/thread.html index 5f1cb148..57d7e0a1 100644 --- a/juick-www/src/main/webapp/WEB-INF/views/thread.html +++ b/juick-www/src/main/webapp/WEB-INF/views/thread.html @@ -6,9 +6,9 @@ <div class="msg-cont"> <div class="msg-menu"><a href="#"><i data-icon="ei-link" data-size="s"></i></a></div> <div class="msg-ts"><a href="/{{ msg.user.name }}/{{ msg.mid }}"> - <time datetime="{{ msg.date | date('yyyy-MM-dd HH:mm:ss') }}Z" - title="{{ msg.date | date('yyyy-MM-dd HH:mm:ss') }} GMT"> - {{ msg.date | prettyTime }} + <time datetime="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }}Z" + title="{{ msg.timestamp | timestamp | date('yyyy-MM-dd HH:mm:ss') }} GMT"> + {{ msg.timestamp | prettyTime }} </time> </a> </div> |