-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00a5396
commit 43718e4
Showing
7 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {DurationPipe} from './DurationPipe'; | ||
|
||
describe('DurationPipe', () => { | ||
var pipe: DurationPipe; | ||
|
||
beforeEach(() => pipe = new DurationPipe()); | ||
|
||
describe('#transform', () => { | ||
it('should throw when provided no arguments', () => { | ||
expect(() => pipe.transform(128)).toThrow(new Error('DurationPipe: missing required time unit argument')); | ||
}); | ||
|
||
it('should convert a duration to a human-readable string', () => { | ||
expect(pipe.transform(24, ['hours'])).toEqual('a day'); | ||
expect(pipe.transform(27, ['days'])).toEqual('a month'); | ||
expect(pipe.transform(365, ['seconds'])).toEqual('6 minutes'); | ||
expect(pipe.transform(365, ['days'])).toEqual('a year'); | ||
expect(pipe.transform(86400, ['seconds'])).toEqual('a day'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Pipe, PipeTransform} from 'angular2/core'; | ||
import * as moment from 'moment'; | ||
|
||
@Pipe({ name: 'amDuration' }) | ||
export class DurationPipe implements PipeTransform { | ||
transform(value: any, args?: string[]): string { | ||
if (typeof args === 'undefined' || args.length !== 1) { | ||
throw new Error('DurationPipe: missing required time unit argument'); | ||
} | ||
return moment.duration(value, args[0]).humanize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters