Skip to content

Commit 0a8b545

Browse files
committed
feat(typerenderer): possibility to render number as date
Closes #743
1 parent 284f5ba commit 0a8b545

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"underscore": "1.8.2",
7777
"uri.js": "1.14.1",
7878
"x2js": "1.1.7",
79-
"web-animations-js": "2.1.2"
79+
"web-animations-js": "2.1.2",
80+
"moment": "~2.10.6"
8081
},
8182
"resolutions": {
8283
"jsgraph": "v1.13.3-20"

gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ module.exports = function (grunt) {
124124
'./bluebird/js/browser/**',
125125
'./notifyjs/dist/**',
126126
'./web-animations-js/*.js',
127-
'./web-animations-js/*.js.map'
127+
'./web-animations-js/*.js.map',
128+
'./moment/min/moment.min.js'
128129
],
129130

130131
dest: './build/components/'

src/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
require.config({
1616
waitSeconds: 0,
1717
paths: {
18+
moment: 'components/moment/min/moment.min',
1819
ace: 'components/ace/src',
1920
async: 'components/async/lib/async',
2021
bowser: 'components/bowser/bowser.min',

src/src/util/typerenderer.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
define(['require', 'jquery', 'lodash', 'src/util/api', 'src/util/util'], function (require, $, _, API, Util) {
3+
define(['require', 'jquery', 'lodash', 'src/util/api', 'src/util/util', 'moment'], function (require, $, _, API, Util, moment) {
44

55
var functions = {};
66

@@ -73,6 +73,16 @@ define(['require', 'jquery', 'lodash', 'src/util/api', 'src/util/util'], functio
7373
$element.html(result);
7474
};
7575

76+
function checkDate(options) {
77+
return options.hasOwnProperty('dateFormat');
78+
}
79+
80+
function toDate(value, options) {
81+
if (options.dateFormat) {
82+
return moment(value).format(options.dateFormat);
83+
}
84+
}
85+
7686
functions.number = {};
7787
functions.number.toscreen = function ($element, val, rootVal, options) {
7888
var number = Number(val);
@@ -82,6 +92,8 @@ define(['require', 'jquery', 'lodash', 'src/util/api', 'src/util/util'], functio
8292
number = number.toPrecision(options.toPrecision);
8393
} else if (options.hasOwnProperty('toFixed')) {
8494
number = number.toFixed(options.toFixed);
95+
} else if (checkDate(options)) {
96+
number = toDate(number, options);
8597
}
8698
$element.html(number);
8799
};

0 commit comments

Comments
 (0)