Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

process ISO 8601 formatted date/time strings with date filter #125

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ angularFilter.date = function(date, format) {
date = parseInt(date, 10);
}

if (isNumber(date)) {
if (date instanceof Date) {
} else if (date && (isNumber(date) || Date.parse(date.toString()))) {
date = new Date(date);
} else if (!(date instanceof Date)) {
} else {
return date;
}

Expand Down
4 changes: 4 additions & 0 deletions test/FiltersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ describe('filter', function(){
expect(filter.date(noon.getTime() + "")).toEqual(noon.toLocaleDateString());
});

it('should be able to parse ISO 8601 dates/times using', function() {
expect(filter.date(noon.toISOString())).toEqual(noon.toLocaleDateString());
});

it('should accept format', function() {
expect(filter.date(morning, "yy-MM-dd HH:mm:ss")).
toEqual('10-09-03 07:05:08');
Expand Down
4 changes: 4 additions & 0 deletions test/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ function TzDate(offset, timestamp) {
return offset * 60;
};

this.toISOString = function() {
return this.date.toISOString();
};

//hide all methods not implemented in this mock that the Date prototype exposes
var unimplementedMethods = ['getDay', 'getMilliseconds', 'getTime', 'getUTCDate', 'getUTCDay',
'getUTCFullYear', 'getUTCHours', 'getUTCMilliseconds', 'getUTCMinutes', 'getUTCMonth',
Expand Down