client/home: format absolute time
This commit is contained in:
parent
ad6750a055
commit
85ed552fce
|
@ -1,5 +1,5 @@
|
||||||
<div class='content-wrapper transparent' id='home'>
|
<div class='content-wrapper transparent' id='home'>
|
||||||
<div class='messages'></div>
|
<div class='messages'></div>
|
||||||
<h1>{{name}}</h1>
|
<h1>{{name}}</h1>
|
||||||
<footer>Version: <span class='version'>{{version}}</span> (built {{buildDate}})</footer>
|
<footer>Version: <span class='version'>{{version}}</span> (built {{#reltime}}{{buildDate}}{{/reltime}})</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
require('./util/handlebars-helpers.js');
|
||||||
|
|
||||||
// ----------------------
|
// ----------------------
|
||||||
// - import controllers -
|
// - import controllers -
|
||||||
// ----------------------
|
// ----------------------
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const handlebars = require('handlebars');
|
||||||
|
const misc = require('./misc.js');
|
||||||
|
|
||||||
|
handlebars.registerHelper('reltime', function(options) {
|
||||||
|
return new handlebars.SafeString(
|
||||||
|
'<time datetime="' +
|
||||||
|
options.fn(this) +
|
||||||
|
'" title="' +
|
||||||
|
options.fn(this) +
|
||||||
|
'">' +
|
||||||
|
misc.formatRelativeTime(options.fn(this)) +
|
||||||
|
'</time>');
|
||||||
|
});
|
|
@ -12,16 +12,16 @@ function formatRelativeTime(timeString) {
|
||||||
|
|
||||||
const descriptions = [
|
const descriptions = [
|
||||||
[60, 'a few seconds', null],
|
[60, 'a few seconds', null],
|
||||||
[60*2, 'a minute', null],
|
[60 * 2, 'a minute', null],
|
||||||
[60*60, '% minutes', 60],
|
[60 * 60, '% minutes', 60],
|
||||||
[60*60*2, 'an hour', null],
|
[60 * 60 * 2, 'an hour', null],
|
||||||
[60*60*24, '% hours', 60*60],
|
[60 * 60 * 24, '% hours', 60 * 60],
|
||||||
[60*60*24*2, 'a day', null],
|
[60 * 60 * 24 * 2, 'a day', null],
|
||||||
[60*60*24*30.42, '% days', 60*60*24],
|
[60 * 60 * 24 * 30.42, '% days', 60 * 60 * 24],
|
||||||
[60*60*24*30.42*2, 'a month', null],
|
[60 * 60 * 24 * 30.42 * 2, 'a month', null],
|
||||||
[60*60*24*30.42*12, '% months', 60*60*24*30.42],
|
[60 * 60 * 24 * 30.42 * 12, '% months', 60 * 60 * 24 * 30.42],
|
||||||
[60*60*24*30.42*12*2, 'a year', null],
|
[60 * 60 * 24 * 30.42 * 12 * 2, 'a year', null],
|
||||||
[8640000000000000/*max*/, '% years', 60*60*24*30.42*12],
|
[8640000000000000 /*max*/, '% years', 60 * 60 * 24 * 30.42 * 12],
|
||||||
];
|
];
|
||||||
|
|
||||||
let text = null;
|
let text = null;
|
|
@ -1,6 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const util = require('../util.js');
|
|
||||||
const config = require('../config.js');
|
const config = require('../config.js');
|
||||||
const BaseView = require('./base_view.js');
|
const BaseView = require('./base_view.js');
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ class HomeView extends BaseView {
|
||||||
this.showView(this.template({
|
this.showView(this.template({
|
||||||
name: config.basic.name,
|
name: config.basic.name,
|
||||||
version: config.meta.version,
|
version: config.meta.version,
|
||||||
buildDate: util.formatRelativeTime(config.meta.buildDate),
|
buildDate: config.meta.buildDate,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue