client/home: format absolute time
This commit is contained in:
parent
ad6750a055
commit
85ed552fce
5 changed files with 30 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
|||
<div class='content-wrapper transparent' id='home'>
|
||||
<div class='messages'></div>
|
||||
<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>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
require('./util/handlebars-helpers.js');
|
||||
|
||||
// ----------------------
|
||||
// - import controllers -
|
||||
// ----------------------
|
||||
|
|
15
client/js/util/handlebars-helpers.js
Normal file
15
client/js/util/handlebars-helpers.js
Normal file
|
@ -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>');
|
||||
});
|
|
@ -11,17 +11,17 @@ function formatRelativeTime(timeString) {
|
|||
const future = now < then;
|
||||
|
||||
const descriptions = [
|
||||
[60, 'a few seconds', null],
|
||||
[60*2, 'a minute', null],
|
||||
[60*60, '% minutes', 60],
|
||||
[60*60*2, 'an hour', null],
|
||||
[60*60*24, '% hours', 60*60],
|
||||
[60*60*24*2, 'a day', null],
|
||||
[60*60*24*30.42, '% days', 60*60*24],
|
||||
[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*2, 'a year', null],
|
||||
[8640000000000000/*max*/, '% years', 60*60*24*30.42*12],
|
||||
[60, 'a few seconds', null],
|
||||
[60 * 2, 'a minute', null],
|
||||
[60 * 60, '% minutes', 60],
|
||||
[60 * 60 * 2, 'an hour', null],
|
||||
[60 * 60 * 24, '% hours', 60 * 60],
|
||||
[60 * 60 * 24 * 2, 'a day', null],
|
||||
[60 * 60 * 24 * 30.42, '% days', 60 * 60 * 24],
|
||||
[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 * 2, 'a year', null],
|
||||
[8640000000000000 /*max*/, '% years', 60 * 60 * 24 * 30.42 * 12],
|
||||
];
|
||||
|
||||
let text = null;
|
|
@ -1,6 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const util = require('../util.js');
|
||||
const config = require('../config.js');
|
||||
const BaseView = require('./base_view.js');
|
||||
|
||||
|
@ -14,7 +13,7 @@ class HomeView extends BaseView {
|
|||
this.showView(this.template({
|
||||
name: config.basic.name,
|
||||
version: config.meta.version,
|
||||
buildDate: util.formatRelativeTime(config.meta.buildDate),
|
||||
buildDate: config.meta.buildDate,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue