aboutsummaryrefslogtreecommitdiff
path: root/app/pipes.ts
diff options
context:
space:
mode:
Diffstat (limited to 'app/pipes.ts')
-rw-r--r--app/pipes.ts45
1 files changed, 40 insertions, 5 deletions
diff --git a/app/pipes.ts b/app/pipes.ts
index 214c87a..90ef59f 100644
--- a/app/pipes.ts
+++ b/app/pipes.ts
@@ -1,10 +1,45 @@
import {Pipe} from 'angular2/core';
/// <reference path="moment.d.ts" />
-@Pipe({name: 'momentDate'})
-
+@Pipe({ name: 'momentDate' })
export class MomentDatePipe {
- transform(value:string, args:string[]) : any {
- return moment(value).format('LLL');
- }
+ transform(value: string, args: string[]): any {
+ return moment(value).format('LLL');
+ }
+}
+
+@Pipe({ name: 'duration' })
+export class DurationPipe {
+ transform(value: number): string {
+ var duration: string = '';
+
+ if (value < 1) {
+ duration = '<1';
+ } else if (value > 1 && value < 1000) {
+ duration = _.round(value, 2).toString();
+ } else if (value >= 1000 && value < 60000) {
+ duration = _.round(value / 1000, 2).toString();
+ } else if (value >= 60000) {
+ duration = _.round(value / 60000, 2).toString();
+ }
+ return duration;
+ }
+}
+
+@Pipe({ name: 'durationUnit' })
+export class DurationUnitPipe {
+ transform(value: number) {
+ var unit: string = '';
+
+ if (value < 1) {
+ unit = 'ms';
+ } else if (value > 1 && value < 1000) {
+ unit = 'ms';
+ } else if (value >= 1000 && value < 60000) {
+ unit = 'secs';
+ } else if (value >= 60000) {
+ unit = 'mins';
+ }
+ return unit;
+ }
}