-
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
a0978d4
commit 2d33056
Showing
8 changed files
with
85 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'es6-shim'; | ||
import 'reflect-metadata'; | ||
import * as moment from 'moment'; | ||
import { DateFormatPipe } from './date-format.pipe'; | ||
import { LocalePipe } from './locale.pipe'; | ||
|
||
describe('LocalePipe', () => { | ||
|
||
describe('#transform', () => { | ||
|
||
let localePipe: LocalePipe; | ||
|
||
beforeEach(() => { | ||
localePipe = new LocalePipe(); | ||
}); | ||
|
||
it('should output a moment object for a string date', () => { | ||
const datetimeString = '2016-01-24 01:23:45'; | ||
const langKeyString1 = 'en'; | ||
const langKeyString2 = 'de'; | ||
const parsedMoment1 = localePipe.transform(datetimeString, langKeyString1); | ||
const parsedMoment2 = localePipe.transform(datetimeString, langKeyString2); | ||
expect(parsedMoment1).toEqual(jasmine.any(moment)); | ||
expect(parsedMoment2).toEqual(jasmine.any(moment)); | ||
expect(parsedMoment1.isValid()).toBe(true); | ||
expect(parsedMoment2.isValid()).toBe(true); | ||
}); | ||
|
||
it('should be pipeable to amDateFormat', () => { | ||
const amDateFormat = new DateFormatPipe(); | ||
const datetimeString = '2016-01-24 14:23:45'; | ||
const langKeyString1 = 'en'; | ||
const langKeyString2 = 'de'; | ||
const momentFormatString1 = 'MMMM Do YYYY, h:mm:ss a'; | ||
const momentFormatString2 = 'MMMM Do YYYY, HH:mm:ss'; | ||
const parseOutput1 = localePipe.transform(datetimeString, langKeyString1); | ||
const parseOutput2 = localePipe.transform(datetimeString, langKeyString2); | ||
expect(amDateFormat.transform(parseOutput1, momentFormatString1)).toEqual('January 24th 2016, 2:23:45 pm'); | ||
expect(amDateFormat.transform(parseOutput2, momentFormatString2)).toEqual('Januar 24. 2016, 14:23:45'); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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 '@angular/core'; | ||
import * as moment from 'moment'; | ||
|
||
// under systemjs, moment is actually exported as the default export, so we account for that | ||
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment; | ||
|
||
@Pipe({ name: 'amLocale' }) | ||
export class LocalePipe implements PipeTransform { | ||
transform(value: string, locale: string): moment.Moment { | ||
return moment(value).locale(locale); | ||
} | ||
} |
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