-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
* Adding amLocal pipe, per code found here: https://github.com/reberinformatik/angular2-moment/commit/0d545cc9a5e14913bddcb00221faaa7c4529ef17\#diff-bd4173df3baced7437261256a7041b36 * Fixing name in spec file. * Fixing bug found in Local Pipe code. * Fixing spec test. * Fixing more class names. * Ending file with new line per linter.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'es6-shim'; | ||
import 'reflect-metadata'; | ||
import * as moment from 'moment'; | ||
import { DateFormatPipe } from './date-format.pipe'; | ||
import { LocalTimePipe } from './local.pipe'; | ||
|
||
describe('LocalPipe', () => { | ||
|
||
describe('#transform', () => { | ||
|
||
let localPipe: LocalTimePipe; | ||
|
||
beforeEach(() => { | ||
localPipe = new LocalTimePipe(); | ||
}); | ||
|
||
it('should output an invalid momemt object for a null input', () => { | ||
const localDate = localPipe.transform(null); | ||
expect(localDate).toEqual(jasmine.any(moment)); | ||
expect(localDate.isValid()).toBe(false); | ||
}); | ||
|
||
it('should output a moment object for a moment input', () => { | ||
const momentDate = moment(); | ||
const localDate = localPipe.transform(momentDate); | ||
expect(localDate).toEqual(jasmine.any(moment)); | ||
expect(localDate.isValid()).toBe(true); | ||
}); | ||
|
||
it('should output a moment object for a date input', () => { | ||
const date = new Date(); | ||
const localDate = localPipe.transform(date); | ||
expect(localDate).toEqual(jasmine.any(moment)); | ||
expect(localDate.isValid()).toBe(true); | ||
}); | ||
|
||
it('should output a moment object for a string date', () => { | ||
const dateString = '2016-01-01'; | ||
const localDate = localPipe.transform(dateString); | ||
expect(localDate).toEqual(jasmine.any(moment)); | ||
expect(localDate.isValid()).toBe(true); | ||
}); | ||
|
||
it('should output a moment object for a timestamp', () => { | ||
const timestamp: number = Date.now(); | ||
const localDate = localPipe.transform(timestamp); | ||
expect(localDate).toEqual(jasmine.any(moment)); | ||
expect(localDate.isValid()).toBe(true); | ||
}); | ||
|
||
it('should be pipeable to amDateFormat', () => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
urish
Owner
|
||
const amDateFormat = new DateFormatPipe(); | ||
const datetimeString = '2015-12-31T23:00:00.000-01:00'; | ||
const momentFormatString = 'YYYY-MM-DD'; | ||
const localOutput = localPipe.transform(datetimeString); | ||
expect(amDateFormat.transform(localOutput, momentFormatString)).toEqual('2016-01-01'); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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: 'amLocal' }) | ||
export class LocalTimePipe implements PipeTransform { | ||
transform(value: Date | moment.Moment | string | number): moment.Moment { | ||
return moment(value).local(); | ||
} | ||
} |
Should this test pass locally? When I ran it, the expect failed and I got an output of 2015-12-31.