From b91ab67e5949ad26c7333fdded3a80c7bdbcd367 Mon Sep 17 00:00:00 2001 From: Allen Wight Date: Fri, 10 Mar 2017 14:15:00 -0500 Subject: [PATCH] Create elapsed time filter Accepts a value in seceonds, displays 00 hours 00 min 00 sec --- client/app/shared/elapsedTime.filter.js | 24 +++++++++++++++++++++ client/app/shared/shared.module.js | 28 +++++++++++++------------ 2 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 client/app/shared/elapsedTime.filter.js diff --git a/client/app/shared/elapsedTime.filter.js b/client/app/shared/elapsedTime.filter.js new file mode 100644 index 000000000..6e6b98c92 --- /dev/null +++ b/client/app/shared/elapsedTime.filter.js @@ -0,0 +1,24 @@ +// Accepts a value of seconds, returns sting of hours minutes seconds +export function ElapsedTime() { + return function(time) { + if (!angular.isNumber(time) || time < 0) { + return "00:00:00"; + } + + const hours = Math.floor(time / 3600); + const minutes = Math.floor((time % 3600) / 60); + const seconds = Math.floor(time % 60); + + if (hours > 0) { + return padding(hours) + " hours " + padding(minutes) + " min " + padding(seconds) + " sec"; + } else if (minutes > 0) { + return padding(minutes) + " min " + padding(seconds) + " sec"; + } else { + return padding(seconds) + " sec"; + } + }; + + function padding(t) { + return t < 10 ? "0" + t : t; + } +} diff --git a/client/app/shared/shared.module.js b/client/app/shared/shared.module.js index c827a184f..e6aa6290c 100644 --- a/client/app/shared/shared.module.js +++ b/client/app/shared/shared.module.js @@ -2,19 +2,20 @@ import { formatBytes, megaBytes, } from './format-bytes.filter.js'; -import { AceEditorComponent } from './ace-editor/ace-editor.component.js'; -import { ActionButtonGroupComponent } from './action-button-group/action-button-group.component.js'; -import { AutofocusDirective } from './autofocus.directive.js'; -import { ConfirmationDirective } from './confirmation/confirmation.directive.js'; -import { CustomDropdownComponent } from './custom-dropdown/custom-dropdown.component.js'; -import { DialogContentComponent } from './dialog-content/dialog-content.component.js'; -import { IconListComponent } from './icon-list/icon-list.component.js'; -import { LoadingComponent } from './loading.component.js'; -import { PaginationComponent } from './pagination/pagination.component.js'; -import { SSCardComponent } from './ss-card/ss-card.component.js'; -import { SelectDropdownComponent } from './select-dropdown/select-dropdown.component.js'; -import { TaggingComponent } from './tagging/tagging.component.js'; -import { substitute } from './substitute.filter.js'; +import {AceEditorComponent} from './ace-editor/ace-editor.component.js'; +import {ActionButtonGroupComponent} from './action-button-group/action-button-group.component.js'; +import {AutofocusDirective} from './autofocus.directive.js'; +import {ConfirmationDirective} from './confirmation/confirmation.directive.js'; +import {CustomDropdownComponent} from './custom-dropdown/custom-dropdown.component.js'; +import {DialogContentComponent} from './dialog-content/dialog-content.component.js'; +import {ElapsedTime} from './elapsedTime.filter.js'; +import {IconListComponent} from './icon-list/icon-list.component.js'; +import {LoadingComponent} from './loading.component.js'; +import {PaginationComponent} from './pagination/pagination.component.js'; +import {SSCardComponent} from './ss-card/ss-card.component.js'; +import {SelectDropdownComponent} from './select-dropdown/select-dropdown.component.js'; +import {TaggingComponent} from './tagging/tagging.component.js'; +import {substitute} from './substitute.filter.js'; export const SharedModule = angular .module('app.shared', [ @@ -40,4 +41,5 @@ export const SharedModule = angular .filter('formatBytes', formatBytes) .filter('megaBytes', megaBytes) .filter('substitute', substitute) + .filter('elapsedTime', ElapsedTime) .name;