Files: 7da1b2adbfa620cd35e8dcf31baf0f7d82bc9874 / modules_basic / timestamp.js
655 bytesRaw
1 | var h = require('hyperscript') |
2 | var _human = require('human-time') |
3 | |
4 | function human (date) { |
5 | var s =_human(date).split(' ') |
6 | return s[0] + (s[1] == 'month' ? 'M' : s[1][0]) |
7 | } |
8 | |
9 | function updateTimestampEl(el) { |
10 | el.firstChild.nodeValue = human(new Date(el.timestamp)) |
11 | return el |
12 | } |
13 | |
14 | setInterval(function () { |
15 | var els = [].slice.call(document.querySelectorAll('.timestamp')) |
16 | els.forEach(updateTimestampEl) |
17 | }, 60e3) |
18 | |
19 | exports.message_meta = function (msg) { |
20 | var d = new Date(msg.value.timestamp) |
21 | return updateTimestampEl(h('a.enter.timestamp', { |
22 | href: '#'+msg.key, |
23 | timestamp: msg.value.timestamp, |
24 | title: _human(d) + '\n'+d |
25 | }, '')) |
26 | } |
27 | |
28 | |
29 | |
30 |
Built with git-ssb-web