Skip to content

Commit

Permalink
Create elapsed time filter
Browse files Browse the repository at this point in the history
Accepts a value in seceonds, displays 00 hours 00 min 00 sec
  • Loading branch information
AllenBW committed Mar 10, 2017
1 parent 50aac67 commit b91ab67
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
24 changes: 24 additions & 0 deletions client/app/shared/elapsedTime.filter.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
28 changes: 15 additions & 13 deletions client/app/shared/shared.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -40,4 +41,5 @@ export const SharedModule = angular
.filter('formatBytes', formatBytes)
.filter('megaBytes', megaBytes)
.filter('substitute', substitute)
.filter('elapsedTime', ElapsedTime)
.name;

0 comments on commit b91ab67

Please sign in to comment.