new Date().getTime() to Date.now(); #1281
Costa Tsaousis (ktsaou) committed
Nov 26, 2016 at 15:22 UTC
581387dc986b11b4262aea9798c9a2ba50bc94a6
5 files changed
+52
-52
node.d/node_modules/netdata.js
+6
-6
@@ -171,7 +171,7 @@ var netdata = {
171
if(typeof service === 'undefined')
172
service = {};
173
174
- var now = new Date().getTime();
174
+ var now = Date.now();
175
176
service._current_chart = null; // the current chart we work on
177
service._queue = ''; // data to be sent to netdata
@@ -214,7 +214,7 @@ var netdata = {
214
if(this.added !== true) {
215
this.added = true;
216
217
- var now = new Date().getTime();
217
+ var now = Date.now();
218
this.next_run = now - (now % (service.update_every * 1000)) + (service.update_every * 1000);
219
220
netdata.services.push(this);
@@ -230,14 +230,14 @@ var netdata = {
230
231
this.module.active++;
232
this.running = true;
233
- this.started = new Date().getTime();
233
+ this.started = Date.now();
234
this.updates++;
235
236
if(netdata.options.DEBUG === true)
237
netdata.debug(this.module.name + ': ' + this.name + ': making ' + this.processor.name + ' request: ' + netdata.stringify(this));
238
239
this.processor.process(this, function(response) {
240
- service.ended = new Date().getTime();
240
+ service.ended = Date.now();
241
service.duration = service.ended - service.started;
242
243
if(typeof response === 'undefined')
@@ -541,7 +541,7 @@ var netdata = {
541
runAllServices: function() {
542
if(netdata.options.DEBUG === true) netdata.debug('runAllServices()');
543
544
- var now = new Date().getTime();
544
+ var now = Date.now();
545
var len = netdata.services.length;
546
while(len--) {
547
var service = netdata.services[len];
@@ -551,7 +551,7 @@ var netdata = {
551
552
service.update();
553
554
- now = new Date().getTime();
554
+ now = Date.now();
555
service.next_run = now - (now % (service.update_every * 1000)) + (service.update_every * 1000);
556
}
557
web/dashboard.js
+32
-32
@@ -249,7 +249,7 @@
249
// rendering the chart that is panned or zoomed).
250
// Used with .current.global_pan_sync_time
251
252
- last_resized: new Date().getTime(), // the timestamp of the last resize request
252
+ last_resized: Date.now(), // the timestamp of the last resize request
253
254
last_page_scroll: 0, // the timestamp the last time the page was scrolled
255
@@ -501,7 +501,7 @@
501
console.log('welcome to NETDATA');
502
503
NETDATA.onresize = function() {
504
- NETDATA.options.last_resized = new Date().getTime();
504
+ NETDATA.options.last_resized = Date.now();
505
NETDATA.onscroll();
506
};
507
@@ -514,7 +514,7 @@
514
NETDATA.onscroll_updater = function() {
515
NETDATA.onscroll_updater_running = true;
516
NETDATA.onscroll_updater_count++;
517
- var start = new Date().getTime();
517
+ var start = Date.now();
518
519
var targets = NETDATA.options.targets;
520
var len = targets.length;
@@ -546,7 +546,7 @@
546
targets[len].isVisible();
547
}
548
549
- var end = new Date().getTime();
549
+ var end = Date.now();
550
// console.log('scroll No ' + NETDATA.onscroll_updater_count + ' calculation took ' + (end - start).toString() + ' ms');
551
552
if(NETDATA.options.current.async_on_scroll === false) {
@@ -574,7 +574,7 @@
574
NETDATA.onscroll = function() {
575
// console.log('onscroll');
576
577
- NETDATA.options.last_page_scroll = new Date().getTime();
577
+ NETDATA.options.last_page_scroll = Date.now();
578
NETDATA.options.auto_refresher_stop_until = 0;
579
580
if(NETDATA.options.targets === null) return;
@@ -641,7 +641,7 @@
641
NETDATA.error = function(code, msg) {
642
NETDATA.errorLast.code = code;
643
NETDATA.errorLast.message = msg;
644
- NETDATA.errorLast.datetime = new Date().getTime();
644
+ NETDATA.errorLast.datetime = Date.now();
645
646
console.log("ERROR " + code + ": " + NETDATA.errorCodes[code].message + ": " + msg);
647
@@ -877,7 +877,7 @@
877
if(this.master !== null && this.master !== state)
878
this.master.resetChart(true, true);
879
880
- var now = new Date().getTime();
880
+ var now = Date.now();
881
this.master = state;
882
this.seq = now;
883
this.force_after_ms = after;
@@ -1408,7 +1408,7 @@
1408
if(NETDATA.chartDefaults.min_width !== null)
1409
$(that.element).css('min-width', NETDATA.chartDefaults.min_width);
1410
1411
- that.tm.last_dom_created = new Date().getTime();
1411
+ that.tm.last_dom_created = Date.now();
1412
1413
showLoading();
1414
};
@@ -1453,7 +1453,7 @@
1453
that.data_before = 0; // milliseconds - the last timestamp of the data
1454
that.data_update_every = 0; // milliseconds - the frequency to update the data
1455
1456
- that.tm.last_initialized = new Date().getTime();
1456
+ that.tm.last_initialized = Date.now();
1457
createDOM();
1458
1459
that.setMode('auto');
@@ -1555,7 +1555,7 @@
1555
showRendering();
1556
that.element_chart.style.display = 'none';
1557
if(that.element_legend !== null) that.element_legend.style.display = 'none';
1558
- that.tm.last_hidden = new Date().getTime();
1558
+ that.tm.last_hidden = Date.now();
1559
1560
// de-allocate data
1561
// This works, but I not sure there are no corner cases somewhere
@@ -1581,7 +1581,7 @@
1581
init();
1582
}
1583
else {
1584
- that.tm.last_unhidden = new Date().getTime();
1584
+ that.tm.last_unhidden = Date.now();
1585
that.element_chart.style.display = '';
1586
if(that.element_legend !== null) that.element_legend.style.display = '';
1587
resizeChart();
@@ -1672,7 +1672,7 @@
1672
maxMessageFontSize();
1673
}
1674
1675
- that.tm.last_resized = new Date().getTime();
1675
+ that.tm.last_resized = Date.now();
1676
}
1677
};
1678
@@ -1689,7 +1689,7 @@
1689
if(that.settings_id !== null)
1690
NETDATA.localStorageSet('chart_heights.' + that.settings_id, h);
1691
1692
- var now = new Date().getTime();
1692
+ var now = Date.now();
1693
NETDATA.options.last_page_scroll = now;
1694
NETDATA.options.auto_refresher_stop_until = now + NETDATA.options.current.stop_updates_while_resizing;
1695
@@ -1724,7 +1724,7 @@
1724
this.event_resize.chart_last_w = this.element.clientWidth;
1725
this.event_resize.chart_last_h = this.element.clientHeight;
1726
1727
- var now = new Date().getTime();
1727
+ var now = Date.now();
1728
if(now - this.event_resize.last <= NETDATA.options.current.double_click_speed) {
1729
// double click / double tap event
1730
@@ -1797,7 +1797,7 @@
1797
var noDataToShow = function() {
1798
showMessageIcon('<i class="fa fa-warning"></i> empty');
1799
that.legendUpdateDOM();
1800
- that.tm.last_autorefreshed = new Date().getTime();
1800
+ that.tm.last_autorefreshed = Date.now();
1801
// that.data_update_every = 30 * 1000;
1802
//that.element_chart.style.display = 'none';
1803
//if(that.element_legend !== null) that.element_legend.style.display = 'none';
@@ -1827,7 +1827,7 @@
1827
this.current.force_before_ms = null;
1828
this.current.force_after_ms = null;
1829
1830
- this.tm.last_mode_switch = new Date().getTime();
1830
+ this.tm.last_mode_switch = Date.now();
1831
};
1832
1833
// ----------------------------------------------------------------------------------------------------------------
@@ -1839,9 +1839,9 @@
1839
return;
1840
1841
if(typeof ms === 'number')
1842
- NETDATA.globalSelectionSync.dont_sync_before = new Date().getTime() + ms;
1842
+ NETDATA.globalSelectionSync.dont_sync_before = Date.now() + ms;
1843
else
1844
- NETDATA.globalSelectionSync.dont_sync_before = new Date().getTime() + NETDATA.options.current.sync_selection_delay;
1844
+ NETDATA.globalSelectionSync.dont_sync_before = Date.now() + NETDATA.options.current.sync_selection_delay;
1845
};
1846
1847
// can we globally apply selection sync?
@@ -1849,7 +1849,7 @@
1849
if(NETDATA.options.current.sync_selection === false)
1850
return false;
1851
1852
- if(NETDATA.globalSelectionSync.dont_sync_before > new Date().getTime())
1852
+ if(NETDATA.globalSelectionSync.dont_sync_before > Date.now())
1853
return false;
1854
1855
return true;
@@ -2164,7 +2164,7 @@
2164
if(this.debug === true)
2165
this.log(logme + 'ACCEPTING UPDATE: current/min duration: ' + (current_duration / 1000).toString() + '/' + (this.fixed_min_duration / 1000).toString() + ', wanted duration: ' + (wanted_duration / 1000).toString() + ', duration diff: ' + (Math.round(Math.abs(current_duration - wanted_duration) / 1000)).toString() + ', movement: ' + (movement / 1000).toString() + ', tolerance: ' + (tolerance / 1000).toString() + ', returning: ' + ret);
2166
2167
- this.current.force_update_at = new Date().getTime() + NETDATA.options.current.pan_and_zoom_delay;
2167
+ this.current.force_update_at = Date.now() + NETDATA.options.current.pan_and_zoom_delay;
2168
this.current.force_after_ms = after;
2169
this.current.force_before_ms = before;
2170
NETDATA.globalPanAndZoom.setMaster(this, after, before);
@@ -2900,7 +2900,7 @@
2900
this.updates_since_last_unhide++;
2901
this.updates_since_last_creation++;
2902
2903
- var started = new Date().getTime();
2903
+ var started = Date.now();
2904
2905
// if the result is JSON, find the latest update-every
2906
this.data_update_every = data.view_update_every * 1000;
@@ -2978,7 +2978,7 @@
2978
NETDATA.globalSelectionSync.stop();
2979
2980
// update the performance counters
2981
- var now = new Date().getTime();
2981
+ var now = Date.now();
2982
this.tm.last_updated = now;
2983
2984
// don't update last_autorefreshed if this chart is
@@ -3103,7 +3103,7 @@
3103
if(nocache === false && this.tm.last_visible_check > NETDATA.options.last_page_scroll)
3104
return this.___isVisible___;
3105
3106
- this.tm.last_visible_check = new Date().getTime();
3106
+ this.tm.last_visible_check = Date.now();
3107
3108
var wh = window.innerHeight;
3109
var x = this.element.getBoundingClientRect();
@@ -3146,7 +3146,7 @@
3146
};
3147
3148
this.canBeAutoRefreshed = function() {
3149
- var now = new Date().getTime();
3149
+ var now = Date.now();
3150
3151
if(this.running === true) {
3152
if(this.debug === true)
@@ -3267,7 +3267,7 @@
3267
this.chart_url = chart.url;
3268
this.data_update_every = chart.update_every * 1000;
3269
this.data_points = Math.round(this.chartWidth() / this.chartPixelsPerPoint());
3270
- this.tm.last_info_downloaded = new Date().getTime();
3270
+ this.tm.last_info_downloaded = Date.now();
3271
3272
if(this.title === null)
3273
this.title = chart.title;
@@ -3617,7 +3617,7 @@
3617
};
3618
3619
NETDATA.parseDom = function(callback) {
3620
- NETDATA.options.last_page_scroll = new Date().getTime();
3620
+ NETDATA.options.last_page_scroll = Date.now();
3621
NETDATA.options.updated_dom = false;
3622
3623
var targets = $('div[data-netdata]'); //.filter(':visible');
@@ -4070,7 +4070,7 @@
4070
dygraph.updateOptions(options);
4071
}
4072
4073
- state.dygraph_last_rendered = new Date().getTime();
4073
+ state.dygraph_last_rendered = Date.now();
4074
return true;
4075
};
4076
@@ -4485,7 +4485,7 @@
4485
// the internal default of dygraphs
4486
context.touchDirections = { x: true, y: false };
4487
4488
- state.dygraph_last_touch_start = new Date().getTime();
4488
+ state.dygraph_last_touch_start = Date.now();
4489
state.dygraph_last_touch_move = 0;
4490
4491
if(typeof event.touches[0].pageX === 'number')
@@ -4500,7 +4500,7 @@
4500
state.dygraph_user_action = true;
4501
Dygraph.defaultInteractionModel.touchmove(event, dygraph, context);
4502
4503
- state.dygraph_last_touch_move = new Date().getTime();
4503
+ state.dygraph_last_touch_move = Date.now();
4504
},
4505
touchend: function(event, dygraph, context) {
4506
if(NETDATA.options.debug.dygraph === true || state.debug === true)
@@ -4519,7 +4519,7 @@
4519
}
4520
4521
// if it was double tap within double click time, reset the charts
4522
- var now = new Date().getTime();
4522
+ var now = Date.now();
4523
if(typeof state.dygraph_last_touch_end !== 'undefined') {
4524
if(state.dygraph_last_touch_move === 0) {
4525
var dt = now - state.dygraph_last_touch_end;
@@ -4560,7 +4560,7 @@
4560
4561
state.dygraph_force_zoom = false;
4562
state.dygraph_user_action = false;
4563
- state.dygraph_last_rendered = new Date().getTime();
4563
+ state.dygraph_last_rendered = Date.now();
4564
4565
if(typeof state.dygraph_instance.axes_[0].extremeRange !== 'undefined') {
4566
state.__commonMin = self.data('common-min') || null;
@@ -6211,7 +6211,7 @@
6211
NETDATA.registry.machines = {};
6212
NETDATA.registry.machines_array = new Array();
6213
6214
- var now = new Date().getTime();
6214
+ var now = Date.now();
6215
var apu = person_urls;
6216
var i = apu.length;
6217
while(i--) {
web/index.html
+2
-2
@@ -1604,7 +1604,7 @@
1604
}
1605
1606
// find the proper family of each alarm
1607
- var now = new Date().getTime();
1607
+ var now = Date.now();
1608
var x;
1609
var count_active = 0;
1610
var count_all = 0;
@@ -2166,7 +2166,7 @@
2166
function notifyForUpdate(force) {
2167
versionLog('<p>checking for updates...</p>');
2168
2169
- var now = new Date().getTime();
2169
+ var now = Date.now();
2170
2171
if(typeof force === 'undefined' || force !== true) {
2172
var last = loadLocalStorage('last_update_check');
web/old/index.js
+8
-8
@@ -228,7 +228,7 @@ function refreshHiddenChart(doNext) {
228
}
229
230
// is it too soon for a refresh?
231
- var now = new Date().getTime();
231
+ var now = Date.now();
232
if((now - mainchart.hiddenchart.last_updated) < (mainchart.update_every * 10 * 1000) || (now - mainchart.hiddenchart.last_updated) < (mainchart.hiddenchart.group * mainchart.hiddenchart.update_every * 1000)) {
233
if(typeof doNext == "function") doNext();
234
return;
@@ -319,7 +319,7 @@ function refreshHiddenChart(doNext) {
319
}
320
321
mainchart.dashboard.draw(mainchart.control_data);
322
- mainchart.hiddenchart.last_updated = new Date().getTime();
322
+ mainchart.hiddenchart.last_updated = Date.now();
323
mainchart.hiddenchart.refreshCount++;
324
})
325
.always(function() {
@@ -583,7 +583,7 @@ function playGraphs() {
583
$('.global_play_button').button('play');
584
585
// check if the thread died due to a javascript error
586
- var now = new Date().getTime();
586
+ var now = Date.now();
587
if((now - last_refresh) > 60000) {
588
// it died or never started
589
//mylog('It seems the refresh thread died. Restarting it.');
@@ -607,7 +607,7 @@ function checkRefreshThread() {
607
return;
608
}
609
610
- var now = new Date().getTime();
610
+ var now = Date.now();
611
if(now - last_refresh > 60000) {
612
mylog('Refresh thread died. Restarting it.');
613
renderChartCallback();
@@ -619,7 +619,7 @@ function checkRefreshThread() {
619
// never call it directly, or new javascript threads will be spawn
620
var timeout = null;
621
function renderChartCallback() {
622
- last_refresh = new Date().getTime();
622
+ last_refresh = Date.now();
623
624
if(!page_is_visible) {
625
timeout = setTimeout(triggerRefresh, CHARTS_CHECK_NO_FOCUS);
@@ -635,7 +635,7 @@ function renderChartCallback() {
635
}
636
637
if(last_user_scroll) {
638
- var now = new Date().getTime();
638
+ var now = Date.now();
639
if((now - last_user_scroll) >= CHARTS_SCROLL_IDLE) {
640
last_user_scroll = 0;
641
mylog('Scrolling: resuming refresh...');
@@ -672,7 +672,7 @@ function triggerRefresh() {
672
//mylog('triggerRefresh()');
673
674
if(!page_is_visible || (refresh_mode == REFRESH_PAUSED && mode != MODE_MAIN)) {
675
- last_refresh = new Date().getTime();
675
+ last_refresh = Date.now();
676
timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE);
677
return;
678
}
@@ -1028,7 +1028,7 @@ function initCharts() {
1028
var height = TARGET_THUMB_GRAPH_HEIGHT;
1029
1030
window.onscroll = function (e) {
1031
- last_user_scroll = new Date().getTime();
1031
+ last_user_scroll = Date.now();
1032
mylog('Scrolling: detected');
1033
}
1034
web/old/netdata.js
+4
-4
@@ -13,7 +13,7 @@ function canChartBeRefreshed(chart) {
13
if(chart.chart && chart.chart.getSelection()[0]) return false;
14
15
// is it too soon for a refresh?
16
- var now = new Date().getTime();
16
+ var now = Date.now();
17
if((now - chart.last_updated) < (chart.group * chart.update_every * 1000)) return false;
18
19
// is the chart in the visible area?
@@ -79,7 +79,7 @@ function renderChart(chart, doNext) {
79
if(chart.chart) {
80
chart.chart.draw(chart.datatable, chart.chartOptions);
81
chart.refreshCount++;
82
- chart.last_updated = new Date().getTime();
82
+ chart.last_updated = Date.now();
83
}
84
else console.log('Cannot create chart for ' + chart.url);
85
})
@@ -89,7 +89,7 @@ function renderChart(chart, doNext) {
89
chart.chart = null;
90
chart.refreshCount = 0;
91
showChartIsLoading(chart.div, chart.name, chart.chartOptions.width, chart.chartOptions.height, "failed to refresh");
92
- chart.last_updated = new Date().getTime();
92
+ chart.last_updated = Date.now();
93
})
94
.always(function() {
95
if(typeof doNext == "function") doNext();
@@ -128,7 +128,7 @@ function calculateChartPointsToShow(c, divisor, maxtime, group, enable_curve) {
128
129
if(!divisor) divisor = 2;
130
131
- var before = c.before?c.before:new Date().getTime() / 1000;
131
+ var before = c.before?c.before:Date.now() / 1000;
132
var after = c.after?c.after:c.first_entry_t;
133
134
var dt = before - after;