diff --git a/forms.tmpl b/forms.tmpl
index 4419486..3b60cca 100644
--- a/forms.tmpl
+++ b/forms.tmpl
@@ -59,7 +59,10 @@
# "(select creation from post where id = (select max(id) from post where thread = ?)))"), %threadId)
#let timeStr = formatTimestamp(latestReplyDate.parseInt())
-
$timeStr
+
+ $timeStr
+ $timeStr
+
# end for
diff --git a/forum.nim b/forum.nim
index 42da8f2..f5d9954 100644
--- a/forum.nim
+++ b/forum.nim
@@ -143,42 +143,9 @@ proc genButtons(c: var TForumData, btns: seq[TStyledButton]): string =
result.add(("""$2""") % [
btns[i].link, btns[i].text, class, anchor])
-proc toInterval(diff: int64): TimeInterval =
- var remaining = diff
- let years = remaining div 31536000
- remaining -= years * 31536000
- let months = remaining div 2592000
- remaining -= months * 2592000
- let days = remaining div 86400
- remaining -= days * 86400
- let hours = remaining div 3600
- remaining -= hours * 3600
- let minutes = remaining div 60
- remaining -= minutes * 60
- #assert false
- result = initInterval(0, remaining.int, minutes.int, hours.int, days.int,
- months.int, years.int)
-
proc formatTimestamp(t: int): string =
let t2 = TTime(t)
- let now = getTime()
- let diff = (now - t2).toInterval()
- if diff.years > 0:
- return getGMTime(t2).format("MMMM d',' yyyy")
- elif diff.months > 0:
- return $diff.months & (if diff.months > 1: " months ago" else: " month ago")
- elif diff.days > 0:
- return $diff.days & (if diff.days > 1: " days ago" else: " day ago")
- elif diff.hours > 0:
- return $diff.hours & (if diff.hours > 1: " hours ago" else: " hour ago")
- elif diff.minutes > 0:
- return $diff.minutes &
- (if diff.minutes > 1: " minutes ago" else: " minute ago")
- elif diff.seconds > 0:
- return $diff.seconds &
- (if diff.seconds > 1: " seconds ago" else: " second ago")
- else:
- return "less than a second ago"
+ return t2.getGMTime().format("yyyy-MM-dd'T'HH':'mm':'ss'Z'")
proc getGravatarUrl(email: string, size = 80): string =
let emailMD5 = email.toLower.toMD5
diff --git a/public/css/style.css b/public/css/style.css
index dceed6e..484e2e4 100644
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -496,3 +496,8 @@ hr
{
border: 1px solid #3D3D3D;
}
+
+.activity .isoDate
+{
+ display: none;
+}
diff --git a/public/js/forum.js b/public/js/forum.js
index 7af672b..2f354d3 100644
--- a/public/js/forum.js
+++ b/public/js/forum.js
@@ -2,4 +2,75 @@
window.onload = function() {
positionGlowArrow();
+ processMainDates();
+ window.setTimeout(performProcessingMainDates, 1000);
};
+
+function performProcessingMainDates()
+{
+ if (processMainDates())
+ {
+ window.setTimeout(performProcessingMainDates, 1000);
+ }
+ else
+ {
+ window.setTimeout(performProcessingMainDates, 60000);
+ }
+}
+
+function timeSince(date) {
+ var result = ["", false];
+ var seconds = Math.floor((new Date() - date) / 1000);
+
+ var interval = Math.floor(seconds / 31536000);
+
+ if (interval >= 1) {
+ result[0] = interval + (interval == 1 ? " year ago" : " years ago");
+ return result;
+ }
+ interval = Math.floor(seconds / 2592000);
+ if (interval >= 1) {
+ result[0] = interval + (interval == 1 ? " month ago" : " months ago");
+ return result;
+ }
+ interval = Math.floor(seconds / 86400);
+ if (interval >= 1) {
+ result[0] = interval + (interval == 1 ? " day ago" : " days ago");
+ return result;
+ }
+ interval = Math.floor(seconds / 3600);
+ if (interval >= 1) {
+ result[0] = interval + (interval == 1 ? " hour ago" : " hours ago");
+ return result;
+ }
+ interval = Math.floor(seconds / 60);
+ if (interval >= 1) {
+ result[0] = interval + (interval == 1 ? " minute ago" : " minutes ago");
+ return result;
+ }
+ if (seconds >= 1) {
+ result[0] = Math.floor(seconds) +
+ (seconds == 1 ? " second ago" : " seconds ago");
+ result[1] = true;
+ return result;
+ }
+ return ["less than a second ago", true];
+}
+
+function processMainDates() {
+ var result = false;
+ var threads = document.getElementById("talk-threads").children;
+ for (var i = 0; i < threads.length; i++)
+ {
+ var activity = threads[i].getElementsByClassName("activity")[0];
+ var activityDiv = activity.children[0];
+ var isoDate = activityDiv.children[0].innerHTML;
+ var parsed = Date.parse(isoDate);
+ var timeS = timeSince(parsed);
+
+ activityDiv.innerHTML = activityDiv.children[0].outerHTML +
+ timeS[0];
+ if (timeS[1]) { result = timeS[1] }
+ }
+ return result;
+}