X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetTimesAjaxPage.java;h=b0d9dacc2e4e5b5e767dc5f3ff52591b515f1ce9;hb=2ae861a6760a2bd9212287ddf342e291d2bdc87c;hp=13cf424ba7bfcc802b6e663fa3aa7de8d1d09bbc;hpb=3b751d0c053450961bb66d2507d6187ce56f8785;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 13cf424..b0d9dac 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java @@ -28,6 +28,8 @@ import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; +import com.google.common.base.Optional; + /** * Ajax page that returns a formatted, relative timestamp for replies or posts. * @@ -58,16 +60,16 @@ public class GetTimesAjaxPage extends JsonPage { if (allIds.length() > 0) { String[] ids = allIds.split(","); for (String id : ids) { - Post post = webInterface.getCore().getPost(id); - if (post == null) { + Optional post = webInterface.getCore().getPost(id); + if (!post.isPresent()) { continue; } JsonObject postTime = new JsonObject(); - Time time = getTime(post.getTime()); + Time time = getTime(post.get().getTime()); postTime.put("timeText", time.getText()); postTime.put("refreshTime", TimeUnit.MILLISECONDS.toSeconds(time.getRefresh())); synchronized (dateFormat) { - postTime.put("tooltip", dateFormat.format(new Date(post.getTime()))); + postTime.put("tooltip", dateFormat.format(new Date(post.get().getTime()))); } postTimes.put(id, postTime); } @@ -77,16 +79,16 @@ public class GetTimesAjaxPage extends JsonPage { if (allIds.length() > 0) { String[] ids = allIds.split(","); for (String id : ids) { - PostReply reply = webInterface.getCore().getPostReply(id); - if (reply == null) { + Optional reply = webInterface.getCore().getPostReply(id); + if (!reply.isPresent()) { continue; } JsonObject replyTime = new JsonObject(); - Time time = getTime(reply.getTime()); + Time time = getTime(reply.get().getTime()); replyTime.put("timeText", time.getText()); replyTime.put("refreshTime", TimeUnit.MILLISECONDS.toSeconds(time.getRefresh())); synchronized (dateFormat) { - replyTime.put("tooltip", dateFormat.format(new Date(reply.getTime()))); + replyTime.put("tooltip", dateFormat.format(new Date(reply.get().getTime()))); } replyTimes.put(id, replyTime); } @@ -179,7 +181,7 @@ public class GetTimesAjaxPage extends JsonPage { text = webInterface.getL10n().getString("View.Time.AWeekAgo"); refresh = TimeUnit.DAYS.toMillis(1); } else if (age < TimeUnit.DAYS.toMillis(28)) { - text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((TimeUnit.MILLISECONDS.toHours(age) + 84) / 24)); + text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((TimeUnit.MILLISECONDS.toHours(age) + 84) / (7 * 24))); refresh = TimeUnit.DAYS.toMillis(1); } else if (age < TimeUnit.DAYS.toMillis(42)) { text = webInterface.getL10n().getString("View.Time.AMonthAgo");