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) { 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) { function BooleanType(arg) {
if (val === 'true') { if (typeof arg === 'string') {
return true; switch (arg) {
} else if (val === 'false') { case 'true':
return false; case '1':
} else { return true;
return Boolean(val); case 'false':
case '0':
return false;
}
} }
if (arg == null) {
return null;
}
return Boolean(arg);
} }
function NumberType(val) { function NumberType(val) {