github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/api/ui/debug/js/utils.js (about) 1 // Copyright (c) 2017-2018 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Define format on string prototype. 16 if (!String.prototype.format) { 17 String.prototype.format = function () { 18 var args = [].slice.call(arguments); 19 return this.replace(/(\{\d+\})/g, function (a) { 20 return args[+(a.substr(1, a.length - 2)) || 0]; 21 }); 22 }; 23 } 24 25 // Define duration formatting on Number 26 if (!Number.prototype.toDuration) { 27 Number.prototype.toDuration = function () { 28 var sec = this / 1E9 // Nanoseconds to seconds. 29 var hours = Math.floor(sec / 3600) 30 var minutes = Math.floor((sec - (hours * 3600)) / 60) 31 var seconds = Math.floor(sec - (hours * 3600) - (minutes * 60)) 32 33 if (hours < 10) { 34 hours = "0" + hours 35 } 36 if (minutes < 10) { 37 minutes = "0" + minutes 38 } 39 if (seconds < 10) { 40 seconds = "0" + seconds 41 } 42 return hours + ':' + minutes + ':' + seconds 43 } 44 } 45 46 function reloadCurrentTab() { 47 var current_index = $("#tabs").tabs("option", "selected"); 48 location.reload() 49 $("#tabs").tabs('load', current_index); 50 } 51 52