clean code
This commit is contained in:
@@ -18,7 +18,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
public class FediServlet extends HttpServlet {
|
public class FediServlet extends HttpServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 2357332474144454738L;
|
||||||
|
|
||||||
private VelocityEngine velocityEngine;
|
private VelocityEngine velocityEngine;
|
||||||
private String instance;
|
private String instance;
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
package de.jalin.fedipage;
|
package de.jalin.fedipage;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class PostDateFormatter {
|
public class PostDateFormatter implements Serializable {
|
||||||
|
|
||||||
final SimpleDateFormat dfTimestamp;
|
private static final long serialVersionUID = 1661651668644302982L;
|
||||||
final SimpleDateFormat dfEuropean;
|
|
||||||
|
final SimpleDateFormat jsonTimestampDateformat;
|
||||||
|
final SimpleDateFormat europeanDateformat;
|
||||||
|
|
||||||
public PostDateFormatter() {
|
public PostDateFormatter() {
|
||||||
dfTimestamp = new SimpleDateFormat("yyyy-MM-dd");
|
jsonTimestampDateformat = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
dfEuropean = new SimpleDateFormat("dd.MM.yyyy");
|
europeanDateformat = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String format(final String timestamp) {
|
public String format(final String timestamp) {
|
||||||
@@ -22,18 +25,22 @@ public class PostDateFormatter {
|
|||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (timestamp.startsWith(dfTimestamp.format(new Date(now)))) {
|
if (timestamp.startsWith(jsonTimestampDateformat.format(new Date(now)))) {
|
||||||
return "heute";
|
return "heute";
|
||||||
}
|
}
|
||||||
if (timestamp.startsWith(dfTimestamp.format(new Date(now - (24*60*60*1000L))))) {
|
final long oneDayMillis = 24*60*60*1000L;
|
||||||
|
if (timestamp.startsWith(jsonTimestampDateformat.format(new Date(now - oneDayMillis)))) {
|
||||||
return "gestern";
|
return "gestern";
|
||||||
}
|
}
|
||||||
|
if (timestamp.startsWith(jsonTimestampDateformat.format(new Date(now - oneDayMillis - oneDayMillis)))) {
|
||||||
|
return "vorgestern";
|
||||||
|
}
|
||||||
|
final String timeStampDate = timestamp.substring(0, 10);
|
||||||
try {
|
try {
|
||||||
final Date date = dfTimestamp.parse(timestamp.substring(0, 10));
|
return europeanDateformat.format(jsonTimestampDateformat.parse(timeStampDate));
|
||||||
return dfEuropean.format(date);
|
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
}
|
}
|
||||||
return timestamp.substring(0, 10);
|
return timeStampDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user