git ssb

16+

Dominic / patchbay



Tree: 25a8b716544bd1f58eeba52a1feb6bb5a6eb78ae

Files: 25a8b716544bd1f58eeba52a1feb6bb5a6eb78ae / modules_basic / timestamp.js

1011 bytesRaw
1var fs = require('fs')
2var Path = require('path')
3var h = require('../h')
4var human = require('human-time')
5
6exports.needs = {}
7
8exports.gives = {
9 timestamp: true,
10 mcss: true
11}
12
13exports.create = function () {
14 setInterval(function () {
15 var els = [].slice.call(document.querySelectorAll('.Timestamp'))
16 els.forEach(updateTimestampEl)
17 }, 60e3)
18
19 return {
20 timestamp,
21 mcss: () => fs.readFileSync(Path.join(__dirname, 'timestamp.mcss'))
22 }
23
24 function updateTimestampEl (el) {
25 var timestamp = Number(el.getAttribute('data-timestamp'))
26 var display = human(new Date(timestamp))
27 el.querySelector('a').firstChild.nodeValue = display
28 return el
29 }
30
31 function timestamp (msg) {
32 var { key, value } = msg
33 var { timestamp } = value
34 var el = h('Timestamp', {
35 attributes: {
36 'data-timestamp': timestamp
37 }
38 }, [
39 h('a', {
40 href: `#${key}`,
41 title: new Date(timestamp)
42 }, '')
43 ])
44 updateTimestampEl(el)
45 return el
46 }
47}
48

Built with git-ssb-web