mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
Add isDate method + fix old code
This commit is contained in:
parent
1c305dc67a
commit
1a43f36e23
5 changed files with 20 additions and 4 deletions
|
|
@ -317,6 +317,7 @@ function isDefined(value){ return typeof value != $undefined; }
|
|||
function isObject(value){ return value!=_null && typeof value == $object;}
|
||||
function isString(value){ return typeof value == $string;}
|
||||
function isNumber(value){ return typeof value == $number;}
|
||||
function isDate(value){ return value instanceof Date; }
|
||||
function isArray(value) { return value instanceof Array; }
|
||||
function isFunction(value){ return typeof value == $function;}
|
||||
function isBoolean(value) { return typeof value == $boolean;}
|
||||
|
|
@ -431,7 +432,7 @@ function copy(source, destination){
|
|||
if (source) {
|
||||
if (isArray(source)) {
|
||||
destination = copy(source, []);
|
||||
} else if (source instanceof Date) {
|
||||
} else if (isDate(source)) {
|
||||
destination = new Date(source.getTime());
|
||||
} else if (isObject(source)) {
|
||||
destination = copy(source, {});
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ function toJsonArray(buf, obj, pretty, stack) {
|
|||
sep = true;
|
||||
}
|
||||
buf.push("]");
|
||||
} else if (obj instanceof Date) {
|
||||
} else if (isDate(obj)) {
|
||||
buf.push(angular['String']['quoteUnicode'](angular['Date']['toString'](obj)));
|
||||
} else {
|
||||
buf.push("{");
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ var angularGlobal = {
|
|||
var type = typeof obj;
|
||||
if (type == $object) {
|
||||
if (obj instanceof Array) return $array;
|
||||
if (obj instanceof Date) return $date;
|
||||
if (isDate(obj)) return $date;
|
||||
if (obj.nodeType == 1) return $element;
|
||||
}
|
||||
return type;
|
||||
|
|
|
|||
|
|
@ -199,7 +199,9 @@ angularFilter.date = function(date, format) {
|
|||
|
||||
if (isNumber(date)) {
|
||||
date = new Date(date);
|
||||
} else if (!(date instanceof Date)) {
|
||||
}
|
||||
|
||||
if (!isDate(date)) {
|
||||
return date;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -328,3 +328,16 @@ describe('angular service', function() {
|
|||
expect(result.third).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('isDate', function() {
|
||||
it('should return true for Date object', function() {
|
||||
expect(isDate(new Date())).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for non Date objects', function() {
|
||||
expect(isDate([])).toBe(false);
|
||||
expect(isDate('')).toBe(false);
|
||||
expect(isDate(23)).toBe(false);
|
||||
expect(isDate({})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue