mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-18 19:41:07 +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 isObject(value){ return value!=_null && typeof value == $object;}
|
||||||
function isString(value){ return typeof value == $string;}
|
function isString(value){ return typeof value == $string;}
|
||||||
function isNumber(value){ return typeof value == $number;}
|
function isNumber(value){ return typeof value == $number;}
|
||||||
|
function isDate(value){ return value instanceof Date; }
|
||||||
function isArray(value) { return value instanceof Array; }
|
function isArray(value) { return value instanceof Array; }
|
||||||
function isFunction(value){ return typeof value == $function;}
|
function isFunction(value){ return typeof value == $function;}
|
||||||
function isBoolean(value) { return typeof value == $boolean;}
|
function isBoolean(value) { return typeof value == $boolean;}
|
||||||
|
|
@ -431,7 +432,7 @@ function copy(source, destination){
|
||||||
if (source) {
|
if (source) {
|
||||||
if (isArray(source)) {
|
if (isArray(source)) {
|
||||||
destination = copy(source, []);
|
destination = copy(source, []);
|
||||||
} else if (source instanceof Date) {
|
} else if (isDate(source)) {
|
||||||
destination = new Date(source.getTime());
|
destination = new Date(source.getTime());
|
||||||
} else if (isObject(source)) {
|
} else if (isObject(source)) {
|
||||||
destination = copy(source, {});
|
destination = copy(source, {});
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ function toJsonArray(buf, obj, pretty, stack) {
|
||||||
sep = true;
|
sep = true;
|
||||||
}
|
}
|
||||||
buf.push("]");
|
buf.push("]");
|
||||||
} else if (obj instanceof Date) {
|
} else if (isDate(obj)) {
|
||||||
buf.push(angular['String']['quoteUnicode'](angular['Date']['toString'](obj)));
|
buf.push(angular['String']['quoteUnicode'](angular['Date']['toString'](obj)));
|
||||||
} else {
|
} else {
|
||||||
buf.push("{");
|
buf.push("{");
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ var angularGlobal = {
|
||||||
var type = typeof obj;
|
var type = typeof obj;
|
||||||
if (type == $object) {
|
if (type == $object) {
|
||||||
if (obj instanceof Array) return $array;
|
if (obj instanceof Array) return $array;
|
||||||
if (obj instanceof Date) return $date;
|
if (isDate(obj)) return $date;
|
||||||
if (obj.nodeType == 1) return $element;
|
if (obj.nodeType == 1) return $element;
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,9 @@ angularFilter.date = function(date, format) {
|
||||||
|
|
||||||
if (isNumber(date)) {
|
if (isNumber(date)) {
|
||||||
date = new Date(date);
|
date = new Date(date);
|
||||||
} else if (!(date instanceof Date)) {
|
}
|
||||||
|
|
||||||
|
if (!isDate(date)) {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -328,3 +328,16 @@ describe('angular service', function() {
|
||||||
expect(result.third).toBeTruthy();
|
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