Skip to content

Commit 25aab0b

Browse files
authored
Merge 9d7fd55 into 1240ae7
2 parents 1240ae7 + 9d7fd55 commit 25aab0b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/ParseSchema.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ class ParseSchema {
241241
if (options.defaultValue !== undefined) {
242242
fieldOptions.defaultValue = options.defaultValue;
243243
}
244+
if (type === 'Date') {
245+
if (options && options.defaultValue) {
246+
fieldOptions.defaultValue = {
247+
__type: 'Date',
248+
iso: new Date(options.defaultValue),
249+
};
250+
}
251+
}
244252
this._fields[name] = fieldOptions;
245253
return this;
246254
}
@@ -310,12 +318,6 @@ class ParseSchema {
310318
* @returns {Parse.Schema} Returns the schema, so you can chain this call.
311319
*/
312320
addDate(name: string, options: FieldOptions) {
313-
if (options && options.defaultValue) {
314-
options.defaultValue = {
315-
__type: 'Date',
316-
iso: new Date(options.defaultValue),
317-
};
318-
}
319321
return this.addField(name, 'Date', options);
320322
}
321323

src/__tests__/ParseSchema-test.js

+9
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ describe('ParseSchema', () => {
194194
}
195195
});
196196

197+
it('can add date field with default value', () => {
198+
const schema = new ParseSchema('NewSchemaTest');
199+
const date = new Date();
200+
schema.addDate('testField', { defaultValue: date });
201+
schema.addField('testField2', 'Date', { defaultValue: date });
202+
expect(schema._fields.testField.defaultValue).toEqual({ __type: 'Date', iso: date });
203+
expect(schema._fields.testField2.defaultValue).toEqual({ __type: 'Date', iso: date });
204+
});
205+
197206
it('cannot add index with null name', done => {
198207
try {
199208
const schema = new ParseSchema('SchemaTest');

0 commit comments

Comments
 (0)