From 581387dc986b11b4262aea9798c9a2ba50bc94a6 Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Sat, 26 Nov 2016 15:22:19 +0200 Subject: [PATCH] new Date().getTime() to Date.now(); #1281 --- node.d/node_modules/netdata.js | 12 +++---- web/dashboard.js | 64 +++++++++++++++++----------------- web/index.html | 4 +-- web/old/index.js | 16 ++++----- web/old/netdata.js | 8 ++--- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/node.d/node_modules/netdata.js b/node.d/node_modules/netdata.js index 5e052e13..6b138ee5 100644 --- a/node.d/node_modules/netdata.js +++ b/node.d/node_modules/netdata.js @@ -171,7 +171,7 @@ var netdata = { if(typeof service === 'undefined') service = {}; - var now = new Date().getTime(); + var now = Date.now(); service._current_chart = null; // the current chart we work on service._queue = ''; // data to be sent to netdata @@ -214,7 +214,7 @@ var netdata = { if(this.added !== true) { this.added = true; - var now = new Date().getTime(); + var now = Date.now(); this.next_run = now - (now % (service.update_every * 1000)) + (service.update_every * 1000); netdata.services.push(this); @@ -230,14 +230,14 @@ var netdata = { this.module.active++; this.running = true; - this.started = new Date().getTime(); + this.started = Date.now(); this.updates++; if(netdata.options.DEBUG === true) netdata.debug(this.module.name + ': ' + this.name + ': making ' + this.processor.name + ' request: ' + netdata.stringify(this)); this.processor.process(this, function(response) { - service.ended = new Date().getTime(); + service.ended = Date.now(); service.duration = service.ended - service.started; if(typeof response === 'undefined') @@ -541,7 +541,7 @@ var netdata = { runAllServices: function() { if(netdata.options.DEBUG === true) netdata.debug('runAllServices()'); - var now = new Date().getTime(); + var now = Date.now(); var len = netdata.services.length; while(len--) { var service = netdata.services[len]; @@ -551,7 +551,7 @@ var netdata = { service.update(); - now = new Date().getTime(); + now = Date.now(); service.next_run = now - (now % (service.update_every * 1000)) + (service.update_every * 1000); } diff --git a/web/dashboard.js b/web/dashboard.js index c47c5c0c..59026f4f 100644 --- a/web/dashboard.js +++ b/web/dashboard.js @@ -249,7 +249,7 @@ // rendering the chart that is panned or zoomed). // Used with .current.global_pan_sync_time - last_resized: new Date().getTime(), // the timestamp of the last resize request + last_resized: Date.now(), // the timestamp of the last resize request last_page_scroll: 0, // the timestamp the last time the page was scrolled @@ -501,7 +501,7 @@ console.log('welcome to NETDATA'); NETDATA.onresize = function() { - NETDATA.options.last_resized = new Date().getTime(); + NETDATA.options.last_resized = Date.now(); NETDATA.onscroll(); }; @@ -514,7 +514,7 @@ NETDATA.onscroll_updater = function() { NETDATA.onscroll_updater_running = true; NETDATA.onscroll_updater_count++; - var start = new Date().getTime(); + var start = Date.now(); var targets = NETDATA.options.targets; var len = targets.length; @@ -546,7 +546,7 @@ targets[len].isVisible(); } - var end = new Date().getTime(); + var end = Date.now(); // console.log('scroll No ' + NETDATA.onscroll_updater_count + ' calculation took ' + (end - start).toString() + ' ms'); if(NETDATA.options.current.async_on_scroll === false) { @@ -574,7 +574,7 @@ NETDATA.onscroll = function() { // console.log('onscroll'); - NETDATA.options.last_page_scroll = new Date().getTime(); + NETDATA.options.last_page_scroll = Date.now(); NETDATA.options.auto_refresher_stop_until = 0; if(NETDATA.options.targets === null) return; @@ -641,7 +641,7 @@ NETDATA.error = function(code, msg) { NETDATA.errorLast.code = code; NETDATA.errorLast.message = msg; - NETDATA.errorLast.datetime = new Date().getTime(); + NETDATA.errorLast.datetime = Date.now(); console.log("ERROR " + code + ": " + NETDATA.errorCodes[code].message + ": " + msg); @@ -877,7 +877,7 @@ if(this.master !== null && this.master !== state) this.master.resetChart(true, true); - var now = new Date().getTime(); + var now = Date.now(); this.master = state; this.seq = now; this.force_after_ms = after; @@ -1408,7 +1408,7 @@ if(NETDATA.chartDefaults.min_width !== null) $(that.element).css('min-width', NETDATA.chartDefaults.min_width); - that.tm.last_dom_created = new Date().getTime(); + that.tm.last_dom_created = Date.now(); showLoading(); }; @@ -1453,7 +1453,7 @@ that.data_before = 0; // milliseconds - the last timestamp of the data that.data_update_every = 0; // milliseconds - the frequency to update the data - that.tm.last_initialized = new Date().getTime(); + that.tm.last_initialized = Date.now(); createDOM(); that.setMode('auto'); @@ -1555,7 +1555,7 @@ showRendering(); that.element_chart.style.display = 'none'; if(that.element_legend !== null) that.element_legend.style.display = 'none'; - that.tm.last_hidden = new Date().getTime(); + that.tm.last_hidden = Date.now(); // de-allocate data // This works, but I not sure there are no corner cases somewhere @@ -1581,7 +1581,7 @@ init(); } else { - that.tm.last_unhidden = new Date().getTime(); + that.tm.last_unhidden = Date.now(); that.element_chart.style.display = ''; if(that.element_legend !== null) that.element_legend.style.display = ''; resizeChart(); @@ -1672,7 +1672,7 @@ maxMessageFontSize(); } - that.tm.last_resized = new Date().getTime(); + that.tm.last_resized = Date.now(); } }; @@ -1689,7 +1689,7 @@ if(that.settings_id !== null) NETDATA.localStorageSet('chart_heights.' + that.settings_id, h); - var now = new Date().getTime(); + var now = Date.now(); NETDATA.options.last_page_scroll = now; NETDATA.options.auto_refresher_stop_until = now + NETDATA.options.current.stop_updates_while_resizing; @@ -1724,7 +1724,7 @@ this.event_resize.chart_last_w = this.element.clientWidth; this.event_resize.chart_last_h = this.element.clientHeight; - var now = new Date().getTime(); + var now = Date.now(); if(now - this.event_resize.last <= NETDATA.options.current.double_click_speed) { // double click / double tap event @@ -1797,7 +1797,7 @@ var noDataToShow = function() { showMessageIcon(' empty'); that.legendUpdateDOM(); - that.tm.last_autorefreshed = new Date().getTime(); + that.tm.last_autorefreshed = Date.now(); // that.data_update_every = 30 * 1000; //that.element_chart.style.display = 'none'; //if(that.element_legend !== null) that.element_legend.style.display = 'none'; @@ -1827,7 +1827,7 @@ this.current.force_before_ms = null; this.current.force_after_ms = null; - this.tm.last_mode_switch = new Date().getTime(); + this.tm.last_mode_switch = Date.now(); }; // ---------------------------------------------------------------------------------------------------------------- @@ -1839,9 +1839,9 @@ return; if(typeof ms === 'number') - NETDATA.globalSelectionSync.dont_sync_before = new Date().getTime() + ms; + NETDATA.globalSelectionSync.dont_sync_before = Date.now() + ms; else - NETDATA.globalSelectionSync.dont_sync_before = new Date().getTime() + NETDATA.options.current.sync_selection_delay; + NETDATA.globalSelectionSync.dont_sync_before = Date.now() + NETDATA.options.current.sync_selection_delay; }; // can we globally apply selection sync? @@ -1849,7 +1849,7 @@ if(NETDATA.options.current.sync_selection === false) return false; - if(NETDATA.globalSelectionSync.dont_sync_before > new Date().getTime()) + if(NETDATA.globalSelectionSync.dont_sync_before > Date.now()) return false; return true; @@ -2164,7 +2164,7 @@ if(this.debug === true) 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); - this.current.force_update_at = new Date().getTime() + NETDATA.options.current.pan_and_zoom_delay; + this.current.force_update_at = Date.now() + NETDATA.options.current.pan_and_zoom_delay; this.current.force_after_ms = after; this.current.force_before_ms = before; NETDATA.globalPanAndZoom.setMaster(this, after, before); @@ -2900,7 +2900,7 @@ this.updates_since_last_unhide++; this.updates_since_last_creation++; - var started = new Date().getTime(); + var started = Date.now(); // if the result is JSON, find the latest update-every this.data_update_every = data.view_update_every * 1000; @@ -2978,7 +2978,7 @@ NETDATA.globalSelectionSync.stop(); // update the performance counters - var now = new Date().getTime(); + var now = Date.now(); this.tm.last_updated = now; // don't update last_autorefreshed if this chart is @@ -3103,7 +3103,7 @@ if(nocache === false && this.tm.last_visible_check > NETDATA.options.last_page_scroll) return this.___isVisible___; - this.tm.last_visible_check = new Date().getTime(); + this.tm.last_visible_check = Date.now(); var wh = window.innerHeight; var x = this.element.getBoundingClientRect(); @@ -3146,7 +3146,7 @@ }; this.canBeAutoRefreshed = function() { - var now = new Date().getTime(); + var now = Date.now(); if(this.running === true) { if(this.debug === true) @@ -3267,7 +3267,7 @@ this.chart_url = chart.url; this.data_update_every = chart.update_every * 1000; this.data_points = Math.round(this.chartWidth() / this.chartPixelsPerPoint()); - this.tm.last_info_downloaded = new Date().getTime(); + this.tm.last_info_downloaded = Date.now(); if(this.title === null) this.title = chart.title; @@ -3617,7 +3617,7 @@ }; NETDATA.parseDom = function(callback) { - NETDATA.options.last_page_scroll = new Date().getTime(); + NETDATA.options.last_page_scroll = Date.now(); NETDATA.options.updated_dom = false; var targets = $('div[data-netdata]'); //.filter(':visible'); @@ -4070,7 +4070,7 @@ dygraph.updateOptions(options); } - state.dygraph_last_rendered = new Date().getTime(); + state.dygraph_last_rendered = Date.now(); return true; }; @@ -4485,7 +4485,7 @@ // the internal default of dygraphs context.touchDirections = { x: true, y: false }; - state.dygraph_last_touch_start = new Date().getTime(); + state.dygraph_last_touch_start = Date.now(); state.dygraph_last_touch_move = 0; if(typeof event.touches[0].pageX === 'number') @@ -4500,7 +4500,7 @@ state.dygraph_user_action = true; Dygraph.defaultInteractionModel.touchmove(event, dygraph, context); - state.dygraph_last_touch_move = new Date().getTime(); + state.dygraph_last_touch_move = Date.now(); }, touchend: function(event, dygraph, context) { if(NETDATA.options.debug.dygraph === true || state.debug === true) @@ -4519,7 +4519,7 @@ } // if it was double tap within double click time, reset the charts - var now = new Date().getTime(); + var now = Date.now(); if(typeof state.dygraph_last_touch_end !== 'undefined') { if(state.dygraph_last_touch_move === 0) { var dt = now - state.dygraph_last_touch_end; @@ -4560,7 +4560,7 @@ state.dygraph_force_zoom = false; state.dygraph_user_action = false; - state.dygraph_last_rendered = new Date().getTime(); + state.dygraph_last_rendered = Date.now(); if(typeof state.dygraph_instance.axes_[0].extremeRange !== 'undefined') { state.__commonMin = self.data('common-min') || null; @@ -6211,7 +6211,7 @@ NETDATA.registry.machines = {}; NETDATA.registry.machines_array = new Array(); - var now = new Date().getTime(); + var now = Date.now(); var apu = person_urls; var i = apu.length; while(i--) { diff --git a/web/index.html b/web/index.html index e6079e2d..e8e0b18c 100644 --- a/web/index.html +++ b/web/index.html @@ -1604,7 +1604,7 @@ } // find the proper family of each alarm - var now = new Date().getTime(); + var now = Date.now(); var x; var count_active = 0; var count_all = 0; @@ -2166,7 +2166,7 @@ function notifyForUpdate(force) { versionLog('

checking for updates...

'); - var now = new Date().getTime(); + var now = Date.now(); if(typeof force === 'undefined' || force !== true) { var last = loadLocalStorage('last_update_check'); diff --git a/web/old/index.js b/web/old/index.js index 3a28daf7..370cf1bb 100644 --- a/web/old/index.js +++ b/web/old/index.js @@ -228,7 +228,7 @@ function refreshHiddenChart(doNext) { } // is it too soon for a refresh? - var now = new Date().getTime(); + var now = Date.now(); if((now - mainchart.hiddenchart.last_updated) < (mainchart.update_every * 10 * 1000) || (now - mainchart.hiddenchart.last_updated) < (mainchart.hiddenchart.group * mainchart.hiddenchart.update_every * 1000)) { if(typeof doNext == "function") doNext(); return; @@ -319,7 +319,7 @@ function refreshHiddenChart(doNext) { } mainchart.dashboard.draw(mainchart.control_data); - mainchart.hiddenchart.last_updated = new Date().getTime(); + mainchart.hiddenchart.last_updated = Date.now(); mainchart.hiddenchart.refreshCount++; }) .always(function() { @@ -583,7 +583,7 @@ function playGraphs() { $('.global_play_button').button('play'); // check if the thread died due to a javascript error - var now = new Date().getTime(); + var now = Date.now(); if((now - last_refresh) > 60000) { // it died or never started //mylog('It seems the refresh thread died. Restarting it.'); @@ -607,7 +607,7 @@ function checkRefreshThread() { return; } - var now = new Date().getTime(); + var now = Date.now(); if(now - last_refresh > 60000) { mylog('Refresh thread died. Restarting it.'); renderChartCallback(); @@ -619,7 +619,7 @@ function checkRefreshThread() { // never call it directly, or new javascript threads will be spawn var timeout = null; function renderChartCallback() { - last_refresh = new Date().getTime(); + last_refresh = Date.now(); if(!page_is_visible) { timeout = setTimeout(triggerRefresh, CHARTS_CHECK_NO_FOCUS); @@ -635,7 +635,7 @@ function renderChartCallback() { } if(last_user_scroll) { - var now = new Date().getTime(); + var now = Date.now(); if((now - last_user_scroll) >= CHARTS_SCROLL_IDLE) { last_user_scroll = 0; mylog('Scrolling: resuming refresh...'); @@ -672,7 +672,7 @@ function triggerRefresh() { //mylog('triggerRefresh()'); if(!page_is_visible || (refresh_mode == REFRESH_PAUSED && mode != MODE_MAIN)) { - last_refresh = new Date().getTime(); + last_refresh = Date.now(); timeout = setTimeout(triggerRefresh, CHARTS_REFRESH_IDLE); return; } @@ -1028,7 +1028,7 @@ function initCharts() { var height = TARGET_THUMB_GRAPH_HEIGHT; window.onscroll = function (e) { - last_user_scroll = new Date().getTime(); + last_user_scroll = Date.now(); mylog('Scrolling: detected'); } diff --git a/web/old/netdata.js b/web/old/netdata.js index f1af0a67..db0e4568 100644 --- a/web/old/netdata.js +++ b/web/old/netdata.js @@ -13,7 +13,7 @@ function canChartBeRefreshed(chart) { if(chart.chart && chart.chart.getSelection()[0]) return false; // is it too soon for a refresh? - var now = new Date().getTime(); + var now = Date.now(); if((now - chart.last_updated) < (chart.group * chart.update_every * 1000)) return false; // is the chart in the visible area? @@ -79,7 +79,7 @@ function renderChart(chart, doNext) { if(chart.chart) { chart.chart.draw(chart.datatable, chart.chartOptions); chart.refreshCount++; - chart.last_updated = new Date().getTime(); + chart.last_updated = Date.now(); } else console.log('Cannot create chart for ' + chart.url); }) @@ -89,7 +89,7 @@ function renderChart(chart, doNext) { chart.chart = null; chart.refreshCount = 0; showChartIsLoading(chart.div, chart.name, chart.chartOptions.width, chart.chartOptions.height, "failed to refresh"); - chart.last_updated = new Date().getTime(); + chart.last_updated = Date.now(); }) .always(function() { if(typeof doNext == "function") doNext(); @@ -128,7 +128,7 @@ function calculateChartPointsToShow(c, divisor, maxtime, group, enable_curve) { if(!divisor) divisor = 2; - var before = c.before?c.before:new Date().getTime() / 1000; + var before = c.before?c.before:Date.now() / 1000; var after = c.after?c.after:c.first_entry_t; var dt = before - after; -- 2.39.2