Skip to content

Commit f0496be

Browse files
committed
Fixed big issue with date cloning.
1 parent e461776 commit f0496be

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

builders.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ function clone(obj) {
19051905
return obj;
19061906

19071907
var type = typeof(obj);
1908-
if (type !== OBJECT)
1908+
if (type !== OBJECT || obj instanceof Date)
19091909
return obj;
19101910

19111911
var length;
@@ -1918,7 +1918,7 @@ function clone(obj) {
19181918

19191919
for (var i = 0; i < length; i++) {
19201920
type = typeof(obj[i]);
1921-
if (type !== OBJECT) {
1921+
if (type !== OBJECT || obj[i] instanceof Date) {
19221922
if (type === FUNCTION)
19231923
continue;
19241924
o[i] = obj[i];
@@ -1945,7 +1945,7 @@ function clone(obj) {
19451945
}
19461946

19471947
var type = typeof(val);
1948-
if (type !== OBJECT) {
1948+
if (type !== OBJECT || val instanceof Date) {
19491949
if (type === FUNCTION)
19501950
continue;
19511951
o[m] = val;

test/test-builders.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ function test_Schema() {
286286
q.define('name', String, true);
287287
q.define('arr', '[x]', true);
288288
q.define('ref', x);
289+
q.define('created', Date);
289290
x.define('age', Number, true);
290291
x.define('note', String, true);
291292

@@ -299,6 +300,8 @@ function test_Schema() {
299300

300301
var qi = q.create();
301302

303+
assert.ok(qi.created.getTime() === Date.now(), 'A problem with problem a default value of date');
304+
302305
var xi = x.create();
303306
xi.age = 30;
304307
xi.note = 'Peter';
@@ -407,6 +410,11 @@ function test_ErrorBuilder() {
407410
builder.add('name');
408411

409412
assert.ok(builder.errors === 2, name + 'transform()');
413+
414+
NEWSCHEMA('default').make(function(schema) {
415+
schema.define('created', Date);
416+
});
417+
410418
};
411419

412420
function test_TransformBuilder() {

utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ exports.clone = function(obj, skip, skipFunctions) {
10851085

10861086
var type = typeof(obj);
10871087

1088-
if (type !== OBJECT)
1088+
if (type !== OBJECT || obj instanceof Date)
10891089
return obj;
10901090

10911091
var length;
@@ -1098,7 +1098,7 @@ exports.clone = function(obj, skip, skipFunctions) {
10981098

10991099
for (var i = 0; i < length; i++) {
11001100
type = typeof(obj[i]);
1101-
if (type !== OBJECT) {
1101+
if (type !== OBJECT || obj[i] instanceof Date) {
11021102
if (skipFunctions && type === FUNCTION)
11031103
continue;
11041104
o[i] = obj[i];
@@ -1119,7 +1119,7 @@ exports.clone = function(obj, skip, skipFunctions) {
11191119

11201120
var val = obj[m];
11211121
var type = typeof(val);
1122-
if (type !== OBJECT) {
1122+
if (type !== OBJECT || val instanceof Date) {
11231123
if (skipFunctions && type === FUNCTION)
11241124
continue;
11251125
o[m] = val;

0 commit comments

Comments
 (0)