projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Convert “image insert failed” into EventBus-based event.
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
web
/
ajax
/
GetTimesAjaxPage.java
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
f90806a
..
4d67c3c
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java
@@
-1,5
+1,5
@@
/*
/*
- * Sone - GetTimesAjaxPage.java - Copyright © 2010–201
1
David Roden
+ * Sone - GetTimesAjaxPage.java - Copyright © 2010–201
2
David Roden
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
@@
-22,8
+22,9
@@
import java.text.SimpleDateFormat;
import java.util.Date;
import net.pterodactylus.sone.data.Post;
import java.util.Date;
import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Reply;
+import net.pterodactylus.sone.data.
Post
Reply;
import net.pterodactylus.sone.web.WebInterface;
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;
import net.pterodactylus.util.json.JsonObject;
import net.pterodactylus.util.number.Digits;
@@
-51,8
+52,7
@@
public class GetTimesAjaxPage extends JsonPage {
* {@inheritDoc}
*/
@Override
* {@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) {
String allIds = request.getHttpRequest().getParam("posts");
JsonObject postTimes = new JsonObject();
if (allIds.length() > 0) {
@@
-62,12
+62,13
@@
public class GetTimesAjaxPage extends JsonPage {
if (post == null) {
continue;
}
if (post == null) {
continue;
}
- long age = now - post.getTime();
JsonObject postTime = new JsonObject();
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("timeText", time.getText());
postTime.put("refreshTime", time.getRefresh() / Time.SECOND);
- postTime.put("tooltip", dateFormat.format(new Date(post.getTime())));
+ synchronized (dateFormat) {
+ postTime.put("tooltip", dateFormat.format(new Date(post.getTime())));
+ }
postTimes.put(id, postTime);
}
}
postTimes.put(id, postTime);
}
}
@@
-76,16
+77,17
@@
public class GetTimesAjaxPage extends JsonPage {
if (allIds.length() > 0) {
String[] ids = allIds.split(",");
for (String id : ids) {
if (allIds.length() > 0) {
String[] ids = allIds.split(",");
for (String id : ids) {
-
Reply reply = webInterface.getCore().ge
tReply(id, false);
+
PostReply reply = webInterface.getCore().getPos
tReply(id, false);
if (reply == null) {
continue;
}
if (reply == null) {
continue;
}
- long age = now - reply.getTime();
JsonObject replyTime = new JsonObject();
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("timeText", time.getText());
replyTime.put("refreshTime", time.getRefresh() / Time.SECOND);
- replyTime.put("tooltip", dateFormat.format(new Date(reply.getTime())));
+ synchronized (dateFormat) {
+ replyTime.put("tooltip", dateFormat.format(new Date(reply.getTime())));
+ }
replyTimes.put(id, replyTime);
}
}
replyTimes.put(id, replyTime);
}
}
@@
-113,14
+115,14
@@
public class GetTimesAjaxPage extends JsonPage {
//
/**
//
/**
- * Returns the formatted relative time for a given
ag
e.
+ * Returns the formatted relative time for a given
tim
e.
*
*
- * @param
ag
e
- * The
age to format
(in milliseconds)
+ * @param
tim
e
+ * The
time to format the difference from
(in milliseconds)
* @return The formatted age
*/
* @return The formatted age
*/
- private Time getTime(long
ag
e) {
- return getTime(webInterface,
ag
e);
+ private Time getTime(long
tim
e) {
+ return getTime(webInterface,
tim
e);
}
//
}
//
@@
-128,15
+130,19
@@
public class GetTimesAjaxPage extends JsonPage {
//
/**
//
/**
- * Returns the formatted relative time for a given
ag
e.
+ * Returns the formatted relative time for a given
tim
e.
*
* @param webInterface
* The Sone web interface (for l10n access)
*
* @param webInterface
* The Sone web interface (for l10n access)
- * @param
ag
e
- * The
age to format
(in milliseconds)
+ * @param
tim
e
+ * The
time to format the difference from
(in milliseconds)
* @return The formatted age
*/
* @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) {
String text;
long refresh;
if (age < 0) {
@@
-152,7
+158,7
@@
public class GetTimesAjaxPage extends JsonPage {
text = webInterface.getL10n().getString("View.Time.AMinuteAgo");
refresh = Time.MINUTE;
} else if (age < 30 * Time.MINUTE) {
text = webInterface.getL10n().getString("View.Time.AMinuteAgo");
refresh = Time.MINUTE;
} else if (age < 30 * Time.MINUTE) {
- text = webInterface.getL10n().getString("View.Time.XMinutesAgo", "min", String.valueOf((int)
Digits.round(age / Time.MINUTE, 1
)));
+ text = webInterface.getL10n().getString("View.Time.XMinutesAgo", "min", String.valueOf((int)
(Digits.round(age, Time.MINUTE) / Time.MINUTE
)));
refresh = 1 * Time.MINUTE;
} else if (age < 45 * Time.MINUTE) {
text = webInterface.getL10n().getString("View.Time.HalfAnHourAgo");
refresh = 1 * Time.MINUTE;
} else if (age < 45 * Time.MINUTE) {
text = webInterface.getL10n().getString("View.Time.HalfAnHourAgo");
@@
-161,31
+167,31
@@
public class GetTimesAjaxPage extends JsonPage {
text = webInterface.getL10n().getString("View.Time.AnHourAgo");
refresh = Time.HOUR;
} else if (age < 21 * Time.HOUR) {
text = webInterface.getL10n().getString("View.Time.AnHourAgo");
refresh = Time.HOUR;
} else if (age < 21 * Time.HOUR) {
- text = webInterface.getL10n().getString("View.Time.XHoursAgo", "hour", String.valueOf((int)
Digits.round(age / Time.HOUR, 1
)));
+ text = webInterface.getL10n().getString("View.Time.XHoursAgo", "hour", String.valueOf((int)
(Digits.round(age, Time.HOUR) / Time.HOUR
)));
refresh = Time.HOUR;
} else if (age < 42 * Time.HOUR) {
text = webInterface.getL10n().getString("View.Time.ADayAgo");
refresh = Time.DAY;
} else if (age < 6 * Time.DAY) {
refresh = Time.HOUR;
} else if (age < 42 * Time.HOUR) {
text = webInterface.getL10n().getString("View.Time.ADayAgo");
refresh = Time.DAY;
} else if (age < 6 * Time.DAY) {
- text = webInterface.getL10n().getString("View.Time.XDaysAgo", "day", String.valueOf((int)
Digits.round(age / Time.DAY, 1
)));
+ text = webInterface.getL10n().getString("View.Time.XDaysAgo", "day", String.valueOf((int)
(Digits.round(age, Time.DAY) / Time.DAY
)));
refresh = Time.DAY;
} else if (age < 11 * Time.DAY) {
text = webInterface.getL10n().getString("View.Time.AWeekAgo");
refresh = Time.DAY;
} else if (age < 4 * Time.WEEK) {
refresh = Time.DAY;
} else if (age < 11 * Time.DAY) {
text = webInterface.getL10n().getString("View.Time.AWeekAgo");
refresh = Time.DAY;
} else if (age < 4 * Time.WEEK) {
- text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((int)
Digits.round(age / Time.WEEK, 1
)));
+ text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((int)
(Digits.round(age, Time.WEEK) / Time.WEEK
)));
refresh = Time.DAY;
} else if (age < 6 * Time.WEEK) {
text = webInterface.getL10n().getString("View.Time.AMonthAgo");
refresh = Time.DAY;
} else if (age < 11 * Time.MONTH) {
refresh = Time.DAY;
} else if (age < 6 * Time.WEEK) {
text = webInterface.getL10n().getString("View.Time.AMonthAgo");
refresh = Time.DAY;
} else if (age < 11 * Time.MONTH) {
- text = webInterface.getL10n().getString("View.Time.XMonthsAgo", "month", String.valueOf((int)
Digits.round(age / Time.MONTH, 1
)));
+ text = webInterface.getL10n().getString("View.Time.XMonthsAgo", "month", String.valueOf((int)
(Digits.round(age, Time.MONTH) / Time.MONTH
)));
refresh = Time.DAY;
} else if (age < 18 * Time.MONTH) {
text = webInterface.getL10n().getString("View.Time.AYearAgo");
refresh = Time.WEEK;
} else {
refresh = Time.DAY;
} else if (age < 18 * Time.MONTH) {
text = webInterface.getL10n().getString("View.Time.AYearAgo");
refresh = Time.WEEK;
} else {
- text = webInterface.getL10n().getString("View.Time.XYearsAgo", "year", String.valueOf((int)
Digits.round(age / Time.YEAR, 1
)));
+ text = webInterface.getL10n().getString("View.Time.XYearsAgo", "year", String.valueOf((int)
(Digits.round(age, Time.YEAR) / Time.YEAR
)));
refresh = Time.WEEK;
}
return new Time(text, refresh);
refresh = Time.WEEK;
}
return new Time(text, refresh);