From 85ed552fce38af36a7ac6aef51506dfad9628283 Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 5 Apr 2016 17:57:26 +0200 Subject: [PATCH] client/home: format absolute time --- client/html/home.hbs | 2 +- client/js/main.js | 2 ++ client/js/util/handlebars-helpers.js | 15 +++++++++++++++ client/js/{util.js => util/misc.js} | 22 +++++++++++----------- client/js/views/home_view.js | 3 +-- 5 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 client/js/util/handlebars-helpers.js rename client/js/{util.js => util/misc.js} (52%) diff --git a/client/html/home.hbs b/client/html/home.hbs index fc476b5..3c7bcf9 100644 --- a/client/html/home.hbs +++ b/client/html/home.hbs @@ -1,5 +1,5 @@

{{name}}

-
Version: {{version}} (built {{buildDate}})
+
Version: {{version}} (built {{#reltime}}{{buildDate}}{{/reltime}})
diff --git a/client/js/main.js b/client/js/main.js index c031edf..6f386ff 100644 --- a/client/js/main.js +++ b/client/js/main.js @@ -1,5 +1,7 @@ 'use strict'; +require('./util/handlebars-helpers.js'); + // ---------------------- // - import controllers - // ---------------------- diff --git a/client/js/util/handlebars-helpers.js b/client/js/util/handlebars-helpers.js new file mode 100644 index 0000000..8d121d5 --- /dev/null +++ b/client/js/util/handlebars-helpers.js @@ -0,0 +1,15 @@ +'use strict'; + +const handlebars = require('handlebars'); +const misc = require('./misc.js'); + +handlebars.registerHelper('reltime', function(options) { + return new handlebars.SafeString( + ''); +}); diff --git a/client/js/util.js b/client/js/util/misc.js similarity index 52% rename from client/js/util.js rename to client/js/util/misc.js index 0933410..39e90db 100644 --- a/client/js/util.js +++ b/client/js/util/misc.js @@ -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; diff --git a/client/js/views/home_view.js b/client/js/views/home_view.js index 4beca60..1f1f0f4 100644 --- a/client/js/views/home_view.js +++ b/client/js/views/home_view.js @@ -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, })); } }