diff --git a/docs/en_US/release_notes_4_2.rst b/docs/en_US/release_notes_4_2.rst index dc46fdbba..e0f117909 100644 --- a/docs/en_US/release_notes_4_2.rst +++ b/docs/en_US/release_notes_4_2.rst @@ -15,5 +15,6 @@ Bug fixes ********* | `Bug #3453 `_ - Fixed SQL for foreign table options. +| `Bug #3475 `_ - Fixed execution time to show Hours part for long running queries in Query Tool. | `Bug #3693 `_ - Proper error should be thrown when server group is created with existing name. | `Bug #3695 `_ - Ensure long string should be wrap in alertify dialogs. \ No newline at end of file diff --git a/web/pgadmin/static/js/sqleditor/calculate_query_run_time.js b/web/pgadmin/static/js/sqleditor/calculate_query_run_time.js index b163aac53..ba3905110 100644 --- a/web/pgadmin/static/js/sqleditor/calculate_query_run_time.js +++ b/web/pgadmin/static/js/sqleditor/calculate_query_run_time.js @@ -10,24 +10,25 @@ import moment from 'moment'; export function calculateQueryRunTime(startTime, endTime) { - const tempEndDate = moment(endTime); - let miliseconds = tempEndDate.diff(startTime); - let seconds = tempEndDate.diff(startTime, 'seconds'); - const minutes = tempEndDate.diff(startTime, 'minutes'); - + let total_ms = moment(endTime).diff(startTime); let result = ''; - if (minutes > 0) { - result += minutes + ' min '; - seconds -= minutes * 60; - } + let secs, mins, hrs; - if (seconds > 0) { - result += seconds + ' secs '; - miliseconds -= seconds * 1000; - } + /* Extract seconds from millisecs */ + secs = parseInt(total_ms/1000); + total_ms = total_ms%1000; - if(minutes <= 0) { - result += miliseconds + ' msec'; - } + /* Extract mins from seconds */ + mins = parseInt(secs/60); + secs = secs%60; + + /* Extract hrs from mins */ + hrs = parseInt(mins/60); + mins = mins%60; + + result = (hrs>0 ? hrs + ' hr ': '') + + (mins>0 ? mins + ' min ': '') + + (hrs<=0 && secs>0 ? secs + ' secs ': '') + + (hrs<=0 && mins<=0 ? total_ms + ' msec ':''); return result.trim(); } diff --git a/web/regression/javascript/sqleditor/calculate_query_run_time_spec.js b/web/regression/javascript/sqleditor/calculate_query_run_time_spec.js index e5a58fe98..5d41813f6 100644 --- a/web/regression/javascript/sqleditor/calculate_query_run_time_spec.js +++ b/web/regression/javascript/sqleditor/calculate_query_run_time_spec.js @@ -79,4 +79,27 @@ describe('#calculateQueryRunTime', () => { .toEqual('9 min 54 secs'); }); }); + + describe('time difference is bigger then 1 hour', () => { + it('displays seconds, milliseconds', () => { + let startDate = moment({ + years:2018, + months:4, + date:2, + hours:10, + minutes:30, + seconds:20, + milliseconds:123}).toDate(); + let endDate = moment({ + years:2018, + months:4, + date:2, + hours:11, + minutes:40, + seconds:15, + milliseconds:70}).toDate(); + expect(calculateQueryRunTime(startDate, endDate)) + .toEqual('1 hr 9 min'); + }); + }); });