X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetTimesAjaxPage.java;h=1711a5b6b6d3197f28cd35f41918d4ee97b71054;hb=38cb6c5ec82298ee351d0eb15ddd8331db273af2;hp=0be0c465a3eb7b868e7c55d5fe3739986aeea8a7;hpb=bfe926f6fb3ef837e9641da51c5fce92aa260e75;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java index 0be0c46..1711a5b 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java @@ -24,6 +24,7 @@ import java.util.Date; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.number.Digits; @@ -51,8 +52,7 @@ public class GetTimesAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { - long now = System.currentTimeMillis(); + protected JsonObject createJsonObject(FreenetRequest request) { String allIds = request.getHttpRequest().getParam("posts"); JsonObject postTimes = new JsonObject(); if (allIds.length() > 0) { @@ -62,9 +62,8 @@ public class GetTimesAjaxPage extends JsonPage { if (post == null) { continue; } - long age = now - post.getTime(); JsonObject postTime = new JsonObject(); - Time time = getTime(age); + Time time = getTime(post.getTime()); postTime.put("timeText", time.getText()); postTime.put("refreshTime", time.getRefresh() / Time.SECOND); postTime.put("tooltip", dateFormat.format(new Date(post.getTime()))); @@ -80,9 +79,8 @@ public class GetTimesAjaxPage extends JsonPage { if (reply == null) { continue; } - long age = now - reply.getTime(); JsonObject replyTime = new JsonObject(); - Time time = getTime(age); + Time time = getTime(reply.getTime()); replyTime.put("timeText", time.getText()); replyTime.put("refreshTime", time.getRefresh() / Time.SECOND); replyTime.put("tooltip", dateFormat.format(new Date(reply.getTime()))); @@ -113,14 +111,14 @@ public class GetTimesAjaxPage extends JsonPage { // /** - * Returns the formatted relative time for a given age. + * Returns the formatted relative time for a given time. * - * @param age - * The age to format (in milliseconds) + * @param time + * The time to format the difference from (in milliseconds) * @return The formatted age */ - private Time getTime(long age) { - return getTime(webInterface, age); + private Time getTime(long time) { + return getTime(webInterface, time); } // @@ -128,15 +126,19 @@ public class GetTimesAjaxPage extends JsonPage { // /** - * Returns the formatted relative time for a given age. + * Returns the formatted relative time for a given time. * * @param webInterface * The Sone web interface (for l10n access) - * @param age - * The age to format (in milliseconds) + * @param time + * The time to format the difference from (in milliseconds) * @return The formatted age */ - public static Time getTime(WebInterface webInterface, long age) { + public static Time getTime(WebInterface webInterface, long time) { + if (time == 0) { + return new Time(webInterface.getL10n().getString("View.Sone.Text.UnknownDate"), 12 * Time.HOUR); + } + long age = System.currentTimeMillis() - time; String text; long refresh; if (age < 0) {