From dbe9329a378c92a13e9d8e949100115229862fc5 Mon Sep 17 00:00:00 2001 From: rudzon Date: Tue, 24 Feb 2015 13:55:57 +0200 Subject: [PATCH] enhance the coercion for boolean/date types --- lib/dao.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/dao.js b/lib/dao.js index 9527d17d..55846e7e 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -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) {