aboutsummaryrefslogtreecommitdiff
path: root/juick-core/src/main/java
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-core/src/main/java
parent030257f473a92693a4b696acfa745bbf64c98580 (diff)
Initial getNotifications query
* using Java 8 DateTime API where possible
Diffstat (limited to 'juick-core/src/main/java')
-rw-r--r--juick-core/src/main/java/com/juick/Message.java16
-rw-r--r--juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java3
-rw-r--r--juick-core/src/main/java/com/juick/util/DateFormatter.java15
-rw-r--r--juick-core/src/main/java/com/juick/xml/adapters/SimpleDateAdapter.java8
4 files changed, 24 insertions, 18 deletions
diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java
index 72f60c82..25463c46 100644
--- a/juick-core/src/main/java/com/juick/Message.java
+++ b/juick-core/src/main/java/com/juick/Message.java
@@ -26,7 +26,11 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import java.util.*;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
/**
* @author Ugnich Anton
@@ -40,7 +44,7 @@ public class Message implements Comparable {
private String text = null;
private User user = null;
private final List<Tag> tags;
- private Date date;
+ private Instant ts;
@XmlTransient
@JsonIgnore
public int TimeAgo = 0;
@@ -239,12 +243,12 @@ public class Message implements Comparable {
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC")
@XmlAttribute(name = "ts")
@XmlJavaTypeAdapter(SimpleDateAdapter.class)
- public Date getDate() {
- return date;
+ public Instant getTimestamp() {
+ return ts;
}
- public void setDate(Date date) {
- this.date = date;
+ public void setTimestamp(Instant timestamp) {
+ this.ts = timestamp;
}
public com.juick.PM getPM() {
diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
index 8f9378a8..c62e0134 100644
--- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
+++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
@@ -22,6 +22,7 @@ import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringUtils;
import org.ocpsoft.prettytime.PrettyTime;
+import java.util.Date;
import java.util.Locale;
/**
@@ -45,7 +46,7 @@ public class PlainTextFormatter {
public static String formatPostSummary(Message m) {
int cropLength = 384;
- String timeAgo = pt.format(m.getDate());
+ String timeAgo = pt.format(Date.from(m.getTimestamp()));
String repliesCount = m.getReplies() == 1 ? "; 1 reply" : m.getReplies() == 0 ? ""
: String.format("; %d replies", m.getReplies());
String txt = m.getText().length() >= cropLength ?
diff --git a/juick-core/src/main/java/com/juick/util/DateFormatter.java b/juick-core/src/main/java/com/juick/util/DateFormatter.java
index d7cf16bf..f9e23a91 100644
--- a/juick-core/src/main/java/com/juick/util/DateFormatter.java
+++ b/juick-core/src/main/java/com/juick/util/DateFormatter.java
@@ -19,10 +19,11 @@ package com.juick.util;
import org.apache.commons.lang3.StringUtils;
+import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
-import java.util.Date;
+import java.util.Locale;
/**
* Created by aalexeev on 12/7/16.
@@ -31,25 +32,25 @@ public class DateFormatter {
private final DateTimeFormatter formatter;
public DateFormatter(String pattern) {
- formatter = DateTimeFormatter.ofPattern(pattern);
+ formatter = DateTimeFormatter.ofPattern(pattern, Locale.ENGLISH);
}
- public String format(final Date date) {
- if (date == null)
+ public String format(final Instant ts) {
+ if (ts == null)
return null;
- LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC);
+ LocalDateTime ldt = LocalDateTime.ofInstant(ts, ZoneOffset.UTC);
return ldt.format(formatter);
}
- public Date parse(final String v) {
+ public Instant parse(final String v) {
if (StringUtils.isBlank(v))
return null;
LocalDateTime ldt = LocalDateTime.parse(v, formatter);
- return Date.from(ldt.toInstant(ZoneOffset.UTC));
+ return ldt.toInstant(ZoneOffset.UTC);
}
}
diff --git a/juick-core/src/main/java/com/juick/xml/adapters/SimpleDateAdapter.java b/juick-core/src/main/java/com/juick/xml/adapters/SimpleDateAdapter.java
index 9a6061cf..6dd40582 100644
--- a/juick-core/src/main/java/com/juick/xml/adapters/SimpleDateAdapter.java
+++ b/juick-core/src/main/java/com/juick/xml/adapters/SimpleDateAdapter.java
@@ -20,21 +20,21 @@ package com.juick.xml.adapters;
import com.juick.util.DateFormattersHolder;
import javax.xml.bind.annotation.adapters.XmlAdapter;
-import java.util.Date;
+import java.time.Instant;
/**
* Created by vitalyster on 15.11.2016.
*/
-public class SimpleDateAdapter extends XmlAdapter<String, Date> {
+public class SimpleDateAdapter extends XmlAdapter<String, Instant> {
@Override
- public String marshal(Date v) throws Exception {
+ public String marshal(Instant v) throws Exception {
return DateFormattersHolder.getMessageFormatterInstance().format(v);
}
@Override
- public Date unmarshal(String v) throws Exception {
+ public Instant unmarshal(String v) throws Exception {
return DateFormattersHolder.getMessageFormatterInstance().parse(v);
}
}