@@ -42,11 +42,6 @@ function Hallway (sites) {
4242 }
4343
4444 this.templateEntry = function (entry) {
45− const now = new Date()
46− const then = Date.parse(entry.date)
47− const diff = (now - then)
48− const date = Math.floor(diff / 86400000)
49−
5045 // Find mention
5146 if (entry.body.indexOf('@<') > -1) {
5247 const data = entry.body.split('@<').pop().split('>')[0]
@@ -56,7 +51,7 @@ function Hallway (sites) {
5651 entry.body = entry.body.replace(`@<${data}>`, `<a href='${path}'>${name}</a>`)
5752 }
5853
59− return `<li class='entry'><span class='date'>${ago(date)}</span> <span class='author'>${entry.author}</span> <span class='body'>${entry.body}</span></li>`
54+ return `<li class='entry'><span class='date'>${timeAgo(Date.parse(entry.date))}</span> <span class='author'>${entry.author}</span> <span class='body'>${entry.body}</span></li>`
6055 }
6156
6257 // Feeds
@@ -81,7 +76,7 @@ function Hallway (sites) {
8176
8277 this.fetchFeed = function (id, feed) {
8378 console.log(`Fetching ${id}(${feed.path})..`)
84− Promise.all([ fetch(feed.path, { cache: 'no-store' }).then(x => x.text()) ]).then(([content]) => {
79+ Promise.all([ fetch(feed.path + '?v=1', { cache: 'no-store' }).then(x => x.text()) ]).then(([content]) => {
8580 feeds[id].content = parseFeed(id, content)
8681 this.refresh()
8782 })
@@ -107,13 +102,33 @@ function Hallway (sites) {
107102 return entries
108103 }
109104
110− function ago (days, cap = 9999) {
111− if (-days > cap) { return `${this.toString(true)}` }
112− if (days === -1) { return `yesterday` }
113− if (days === 1) { return 'tomorrow' }
114− if (days === 0) { return 'today' }
115− if (days < -365) { return `${Math.floor(days / -365)} years ago` }
116− if (days < 1) { return `${days * -1} days ago` }
117− return `in ${days} days`
105+ function timeAgo (dateParam) {
106+ if (!dateParam) {
107+ return null
108+ }
109+
110+ const date = typeof dateParam === 'object' ? dateParam : new Date(dateParam)
111+ const DAY_IN_MS = 86400000 // 24 * 60 * 60 * 1000
112+ const today = new Date()
113+ const yesterday = new Date(today - DAY_IN_MS)
114+ const seconds = Math.round((today - date) / 1000)
115+ const minutes = Math.round(seconds / 60)
116+ const isToday = today.toDateString() === date.toDateString()
117+ const isYesterday = yesterday.toDateString() === date.toDateString()
118+
119+ if (seconds < 5) {
120+ return 'now'
121+ } else if (seconds < 60) {
122+ return `${seconds} seconds ago`
123+ } else if (seconds < 90) {
124+ return 'about a minute ago'
125+ } else if (minutes < 60) {
126+ return `${minutes} minutes ago`
127+ } else if (isToday) {
128+ return `${Math.floor(minutes / 60)} hours ago`
129+ } else if (isYesterday) {
130+ return 'yesterday'
131+ }
132+ return `${Math.floor(minutes / 1440)} days ago`
118133 }
119134}