mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-05-15 17:18:09 +08:00
fix date filter to igrone falsy input
This commit is contained in:
@@ -75,7 +75,7 @@ var DATE_FORMATS = {
|
||||
var DATE_FORMATS_SPLIT = /([^yMdHhmsaZ]*)(y+|M+|d+|H+|h+|m+|s+|a|Z)(.*)/;
|
||||
|
||||
angularFilter.date = function(date, format) {
|
||||
if (!date instanceof Date) return date;
|
||||
if (!(date instanceof Date)) return date;
|
||||
var text = date.toLocaleDateString(), fn;
|
||||
if (format && isString(format)) {
|
||||
text = '';
|
||||
|
||||
@@ -100,6 +100,12 @@ describe('filter', function(){
|
||||
midnight.getTimezoneOffset =
|
||||
function() { return 7 * 60; };
|
||||
|
||||
it('should ignore falsy inputs', function() {
|
||||
expect(filter.date(null)).toEqual(null);
|
||||
expect(filter.date('')).toEqual('');
|
||||
expect(filter.date(123)).toEqual(123);
|
||||
});
|
||||
|
||||
it('should do basic filter', function() {
|
||||
expect(filter.date(noon)).toEqual(noon.toLocaleDateString());
|
||||
expect(filter.date(noon, '')).toEqual(noon.toLocaleDateString());
|
||||
|
||||
Reference in New Issue
Block a user