aboutsummaryrefslogtreecommitdiff
path: root/app/pipes.ts
blob: 7c08f0b8d44a9ea7f274ebbaf8964fa96ba9a4ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {Pipe} from 'angular2/core';
/// <reference path="moment.d.ts" />

@Pipe({ name: 'momentDate' })
export class MomentDatePipe {
    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 = 's';
        } else if (value >= 60000) {
            unit = 'min';
        }
        return unit;
    }
}