enhance the coercion for boolean/date types

This commit is contained in:
rudzon 2015-02-24 13:55:57 +02:00
parent 35825f5e53
commit dbe9329a37
1 changed files with 19 additions and 8 deletions

View File

@ -768,17 +768,28 @@ DataAccessObject._normalize = function (filter) {
};
function DateType(arg) {
return new Date(arg);
var d = new Date(arg);
if (isNaN(d.getTime())) {
throw new Error('Invalid date: ' + arg);
}
return d;
}
function BooleanType(val) {
if (val === 'true') {
return true;
} else if (val === 'false') {
return false;
} else {
return Boolean(val);
function BooleanType(arg) {
if (typeof arg === 'string') {
switch (arg) {
case 'true':
case '1':
return true;
case 'false':
case '0':
return false;
}
}
if (arg == null) {
return null;
}
return Boolean(arg);
}
function NumberType(val) {