Commit a2e78a1a616b6157d700b742d743c63f3a3d1ab3
1 parent
be5b00c2
Exists in
master
and in
32 other branches
Use angular moment filter to parse dates
Showing
2 changed files
with
6 additions
and
2 deletions
Show diff stats
src/app/components/noosfero/date-format/date-format.filter.spec.ts
... | ... | @@ -5,12 +5,13 @@ describe("Filters", () => { |
5 | 5 | describe("Date Format Filter", () => { |
6 | 6 | |
7 | 7 | beforeEach(angular.mock.module("templates")); |
8 | + beforeEach(angular.mock.module("angularMoment")); | |
8 | 9 | |
9 | 10 | it("convert date from the format returned by noosfero api to an ISO format", done => { |
10 | 11 | let date = "2016/03/10 10:46:47"; |
11 | 12 | let htmlTemplate = `{{ '${date}' | dateFormat }}`; |
12 | 13 | quickCreateComponent({ providers: [DateFormat], template: htmlTemplate }).then(fixture => { |
13 | - expect(fixture.debugElement.text()).toEqual('"2016-03-10T13:46:47.000Z"'); | |
14 | + expect(fixture.debugElement.text()).toEqual('2016-03-10T13:46:47.000Z'); | |
14 | 15 | done(); |
15 | 16 | }); |
16 | 17 | }); | ... | ... |
src/app/components/noosfero/date-format/date-format.filter.ts
1 | 1 | import {Pipe, Inject} from "ng-forward"; |
2 | 2 | |
3 | 3 | @Pipe("dateFormat") |
4 | +@Inject("amParseFilter") | |
4 | 5 | export class DateFormat { |
5 | 6 | |
7 | + constructor(private amParseFilter: any) { } | |
8 | + | |
6 | 9 | transform(date: string, options: any) { |
7 | - return moment(date, "YYYY/MM/DD HH:mm:ss"); | |
10 | + return this.amParseFilter(date, "YYYY/MM/DD HH:mm:ss").toISOString(); | |
8 | 11 | } |
9 | 12 | |
10 | 13 | } | ... | ... |