Skip to content

Commit 160ef61

Browse files
committed
Fixed U.isDate() and fixed Date Type in SchemaBuilder.
1 parent b6e8ce9 commit 160ef61

2 files changed

Lines changed: 10 additions & 31 deletions

File tree

builders.js

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,27 +1280,17 @@ SchemaBuilderEntity.prototype.prepare = function(model, dependencies) {
12801280
tmp = null;
12811281

12821282
if (typeval === 'string') {
1283-
if (val === '')
1284-
tmp = null;
1285-
else
1283+
if (val)
12861284
tmp = val.trim().parseDate();
1287-
} else if (typeval === 'object') {
1288-
if (framework_utils.isDate(val))
1289-
tmp = val;
1290-
else
1291-
tmp = null;
1292-
} else if (typeval === 'number') {
1285+
} else if (typeval === 'number')
12931286
tmp = new Date(val);
1294-
}
1295-
1296-
if (tmp !== null && typeof(tmp) === 'object' && tmp.toString() === 'Invalid Date')
1297-
tmp = null;
12981287

1299-
if (tmp)
1300-
item[property] = self.$onprepare(property, tmp, undefined, model);
1288+
if (framework_utils.isDate(tmp))
1289+
tmp = self.$onprepare(property, tmp, undefined, model)
13011290
else
1302-
item[property] = (defaults ? isUndefined(defaults(property, false, self.name), null) : null);
1291+
tmp = (defaults ? isUndefined(defaults(property, false, self.name), null) : null);
13031292

1293+
item[property] = tmp;
13041294
break;
13051295

13061296
// object
@@ -1413,23 +1403,12 @@ SchemaBuilderEntity.prototype.prepare = function(model, dependencies) {
14131403
case 5:
14141404

14151405
if (typeval === 'string') {
1416-
if (tmp === '')
1417-
tmp = null;
1418-
else
1406+
if (tmp)
14191407
tmp = tmp.trim().parseDate();
1420-
} else if (typeval === 'object') {
1421-
if (framework_utils.isDate(tmp))
1422-
tmp = tmp;
1423-
else
1424-
tmp = null;
1425-
} else if (typeval === 'number') {
1408+
} else if (typeval === 'number')
14261409
tmp = new Date(tmp);
1427-
}
1428-
1429-
if (tmp !== null && typeof(tmp) === 'object' && tmp.toString() === 'Invalid Date')
1430-
tmp = null;
14311410

1432-
if (tmp)
1411+
if (framework_utils.isDate(tmp))
14331412
tmp = self.$onprepare(property, tmp, j, model);
14341413
else
14351414
tmp = undefined;

utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ exports.isRegExp = function(obj) {
14471447
* @return {Boolean}
14481448
*/
14491449
exports.isDate = function(obj) {
1450-
return obj instanceof Date && typeof(obj.getTime) === 'function' ? true : false;
1450+
return obj instanceof Date && obj.getTime() > -1 ? true : false;
14511451
};
14521452

14531453
/**

0 commit comments

Comments
 (0)