mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-15 02:03:11 +00:00
fix date filter to igrone falsy input
This commit is contained in:
parent
a0ac6725ed
commit
c5cfe2b393
2 changed files with 7 additions and 1 deletions
|
|
@ -75,7 +75,7 @@ var DATE_FORMATS = {
|
||||||
var DATE_FORMATS_SPLIT = /([^yMdHhmsaZ]*)(y+|M+|d+|H+|h+|m+|s+|a|Z)(.*)/;
|
var DATE_FORMATS_SPLIT = /([^yMdHhmsaZ]*)(y+|M+|d+|H+|h+|m+|s+|a|Z)(.*)/;
|
||||||
|
|
||||||
angularFilter.date = function(date, format) {
|
angularFilter.date = function(date, format) {
|
||||||
if (!date instanceof Date) return date;
|
if (!(date instanceof Date)) return date;
|
||||||
var text = date.toLocaleDateString(), fn;
|
var text = date.toLocaleDateString(), fn;
|
||||||
if (format && isString(format)) {
|
if (format && isString(format)) {
|
||||||
text = '';
|
text = '';
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,12 @@ describe('filter', function(){
|
||||||
midnight.getTimezoneOffset =
|
midnight.getTimezoneOffset =
|
||||||
function() { return 7 * 60; };
|
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() {
|
it('should do basic filter', function() {
|
||||||
expect(filter.date(noon)).toEqual(noon.toLocaleDateString());
|
expect(filter.date(noon)).toEqual(noon.toLocaleDateString());
|
||||||
expect(filter.date(noon, '')).toEqual(noon.toLocaleDateString());
|
expect(filter.date(noon, '')).toEqual(noon.toLocaleDateString());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue