clean code

This commit is contained in:
2025-09-20 15:02:26 +02:00
parent 67119311c7
commit 2188bf9409
2 changed files with 19 additions and 12 deletions
@@ -18,7 +18,7 @@ import jakarta.servlet.http.HttpServletResponse;
public class FediServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 2357332474144454738L;
private VelocityEngine velocityEngine;
private String instance;
@@ -1,17 +1,20 @@
package de.jalin.fedipage;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PostDateFormatter {
public class PostDateFormatter implements Serializable {
final SimpleDateFormat dfTimestamp;
final SimpleDateFormat dfEuropean;
private static final long serialVersionUID = 1661651668644302982L;
final SimpleDateFormat jsonTimestampDateformat;
final SimpleDateFormat europeanDateformat;
public PostDateFormatter() {
dfTimestamp = new SimpleDateFormat("yyyy-MM-dd");
dfEuropean = new SimpleDateFormat("dd.MM.yyyy");
jsonTimestampDateformat = new SimpleDateFormat("yyyy-MM-dd");
europeanDateformat = new SimpleDateFormat("dd.MM.yyyy");
}
public String format(final String timestamp) {
@@ -22,18 +25,22 @@ public class PostDateFormatter {
return timestamp;
}
long now = System.currentTimeMillis();
if (timestamp.startsWith(dfTimestamp.format(new Date(now)))) {
if (timestamp.startsWith(jsonTimestampDateformat.format(new Date(now)))) {
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";
}
if (timestamp.startsWith(jsonTimestampDateformat.format(new Date(now - oneDayMillis - oneDayMillis)))) {
return "vorgestern";
}
final String timeStampDate = timestamp.substring(0, 10);
try {
final Date date = dfTimestamp.parse(timestamp.substring(0, 10));
return dfEuropean.format(date);
return europeanDateformat.format(jsonTimestampDateformat.parse(timeStampDate));
} catch (ParseException e) {
}
return timestamp.substring(0, 10);
return timeStampDate;
}
}