psychobunny 12 years ago
commit 1f97fefac0

@ -3,7 +3,7 @@
<!-- BEGIN topics -->
<a href="topics/{topics.slug}"><li class="topic-row">
<h4>{topics.title}</h4>
<p>Posted on {topics.timestamp} by user {topics.uid}. {topics.post_count} posts.</p>
<p>Posted {topics.relativeTime} by user {topics.uid}. {topics.post_count} posts.</p>
</li></a>
<!-- END topics -->
</ul>

@ -2,7 +2,7 @@
<!-- BEGIN posts -->
<li class="topic-row">
<p>{posts.content}</p>
<p>Posted on {posts.timestamp} by user {posts.uid}.</p>
<p>Posted {posts.relativeTime} by user {posts.uid}.</p>
</li>
<!-- END posts -->
</ul>
@ -13,4 +13,4 @@ var post_reply = document.getElementById('post_reply');
post_reply.onclick = function() {
app.open_post_window('reply', {TOPIC_ID});
}
</script>
</script>

@ -1,4 +1,5 @@
var RDB = require('./redis.js');
var RDB = require('./redis.js'),
utils = require('./utils.js');
(function(Posts) {
//data structure
@ -42,7 +43,8 @@ var RDB = require('./redis.js');
posts.push({
'content' : content[i],
'uid' : uid[i],
'timestamp' : timestamp[i]
'timestamp' : timestamp[i],
'relativeTime': utils.relativeTime(timestamp[i])
});
}

@ -1,8 +1,6 @@
var RDB = require('./redis.js'),
posts = require('./posts.js');
posts = require('./posts.js'),
utils = require('./utils.js');
(function(Topics) {
//data structure
@ -82,6 +80,7 @@ var RDB = require('./redis.js'),
'title' : title[i],
'uid' : uid[i],
'timestamp' : timestamp[i],
'relativeTime': utils.relativeTime(timestamp[i]),
'slug' : slug[i],
'post_count' : postcount[i]
});

@ -1,5 +1,5 @@
var config = require('../config.js'),
utils = require('../utils.js'),
utils = require('./utils.js'),
RDB = require('./redis.js'),
crypto = require('crypto'),
emailjs = require('emailjs'),

@ -0,0 +1,35 @@
var utils = {
generateUUID: function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
},
relativeTime: function(timestamp) {
var now = +new Date(),
difference = now - Math.floor(parseFloat(timestamp));
difference = Math.floor(difference / 1000);
if (difference < 60) return difference + ' second' + (difference !== 1 ? 's' : '') + ' ago';
difference = Math.floor(difference / 60);
if (difference < 60) return difference + ' minute' + (difference !== 1 ? 's' : '') + ' ago';
difference = Math.floor(difference / 60);
if (difference < 24) return difference + ' hour' + (difference !== 1 ? 's' : '') + ' ago';
difference = Math.floor(difference / 24);
if (difference < 3) return difference + ' day' + (difference !== 1 ? 's' : '') + ' ago';
// Lastly, just return a formatted date
var date = new Date(timestamp);
// hour = date.getHours(),
// minute = date.getMinutes(),
// day = date.getDate(),
// month = date.getMonth(),
// months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
return date.toDateString();
}
}
module.exports = utils;

@ -1,10 +0,0 @@
var utils = {
generateUUID: function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
}
module.exports = utils;
Loading…
Cancel
Save