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,12 +5,13 @@ describe("Filters", () => { | ||
5 | describe("Date Format Filter", () => { | 5 | describe("Date Format Filter", () => { |
6 | 6 | ||
7 | beforeEach(angular.mock.module("templates")); | 7 | beforeEach(angular.mock.module("templates")); |
8 | + beforeEach(angular.mock.module("angularMoment")); | ||
8 | 9 | ||
9 | it("convert date from the format returned by noosfero api to an ISO format", done => { | 10 | it("convert date from the format returned by noosfero api to an ISO format", done => { |
10 | let date = "2016/03/10 10:46:47"; | 11 | let date = "2016/03/10 10:46:47"; |
11 | let htmlTemplate = `{{ '${date}' | dateFormat }}`; | 12 | let htmlTemplate = `{{ '${date}' | dateFormat }}`; |
12 | quickCreateComponent({ providers: [DateFormat], template: htmlTemplate }).then(fixture => { | 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 | done(); | 15 | done(); |
15 | }); | 16 | }); |
16 | }); | 17 | }); |
src/app/components/noosfero/date-format/date-format.filter.ts
1 | import {Pipe, Inject} from "ng-forward"; | 1 | import {Pipe, Inject} from "ng-forward"; |
2 | 2 | ||
3 | @Pipe("dateFormat") | 3 | @Pipe("dateFormat") |
4 | +@Inject("amParseFilter") | ||
4 | export class DateFormat { | 5 | export class DateFormat { |
5 | 6 | ||
7 | + constructor(private amParseFilter: any) { } | ||
8 | + | ||
6 | transform(date: string, options: any) { | 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 | } |