mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	Merge branch 'master' of https://github.com/psychobunny/node-forum
This commit is contained in:
		| @@ -3,7 +3,7 @@ | |||||||
| <!-- BEGIN topics --> | <!-- BEGIN topics --> | ||||||
| <a href="topics/{topics.slug}"><li class="topic-row"> | <a href="topics/{topics.slug}"><li class="topic-row"> | ||||||
| 	<h4>{topics.title}</h4> | 	<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> | </li></a> | ||||||
| <!-- END topics --> | <!-- END topics --> | ||||||
| </ul> | </ul> | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| <!-- BEGIN posts --> | <!-- BEGIN posts --> | ||||||
| <li class="topic-row"> | <li class="topic-row"> | ||||||
| 	<p>{posts.content}</p> | 	<p>{posts.content}</p> | ||||||
| 	<p>Posted on {posts.timestamp} by user {posts.uid}.</p> | 	<p>Posted {posts.relativeTime} by user {posts.uid}.</p> | ||||||
| </li> | </li> | ||||||
| <!-- END posts --> | <!-- END posts --> | ||||||
| </ul> | </ul> | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| var	RDB = require('./redis.js'); | var	RDB = require('./redis.js'), | ||||||
|  | 	utils = require('./utils.js'); | ||||||
|  |  | ||||||
| (function(Posts) { | (function(Posts) { | ||||||
| 	//data structure | 	//data structure | ||||||
| @@ -42,7 +43,8 @@ var	RDB = require('./redis.js'); | |||||||
| 							posts.push({ | 							posts.push({ | ||||||
| 								'content' : content[i], | 								'content' : content[i], | ||||||
| 								'uid' : uid[i], | 								'uid' : uid[i], | ||||||
| 								'timestamp' : timestamp[i] | 								'timestamp' : timestamp[i], | ||||||
|  | 								'relativeTime': utils.relativeTime(timestamp[i]) | ||||||
| 							}); | 							}); | ||||||
| 						} | 						} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,8 +1,6 @@ | |||||||
| var	RDB = require('./redis.js'), | var	RDB = require('./redis.js'), | ||||||
| 	posts = require('./posts.js'); | 	posts = require('./posts.js'), | ||||||
|  | 	utils = require('./utils.js'); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| (function(Topics) { | (function(Topics) { | ||||||
| 	//data structure | 	//data structure | ||||||
| @@ -82,6 +80,7 @@ var	RDB = require('./redis.js'), | |||||||
| 								'title' : title[i], | 								'title' : title[i], | ||||||
| 								'uid' : uid[i], | 								'uid' : uid[i], | ||||||
| 								'timestamp' : timestamp[i], | 								'timestamp' : timestamp[i], | ||||||
|  | 								'relativeTime': utils.relativeTime(timestamp[i]), | ||||||
| 								'slug' : slug[i], | 								'slug' : slug[i], | ||||||
| 								'post_count' : postcount[i] | 								'post_count' : postcount[i] | ||||||
| 							}); | 							}); | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| var	config = require('../config.js'), | var	config = require('../config.js'), | ||||||
| 	utils = require('../utils.js'), | 	utils = require('./utils.js'), | ||||||
| 	RDB = require('./redis.js'), | 	RDB = require('./redis.js'), | ||||||
| 	crypto = require('crypto'), | 	crypto = require('crypto'), | ||||||
| 	emailjs = require('emailjs'), | 	emailjs = require('emailjs'), | ||||||
|   | |||||||
							
								
								
									
										35
									
								
								src/utils.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/utils.js
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||||
		Reference in New Issue
	
	Block a user