File tree 2 files changed +17
-6
lines changed
2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -241,6 +241,14 @@ class ParseSchema {
241
241
if ( options . defaultValue !== undefined ) {
242
242
fieldOptions . defaultValue = options . defaultValue ;
243
243
}
244
+ if ( type === 'Date' ) {
245
+ if ( options && options . defaultValue ) {
246
+ fieldOptions . defaultValue = {
247
+ __type : 'Date' ,
248
+ iso : new Date ( options . defaultValue ) ,
249
+ } ;
250
+ }
251
+ }
244
252
this . _fields [ name ] = fieldOptions ;
245
253
return this ;
246
254
}
@@ -310,12 +318,6 @@ class ParseSchema {
310
318
* @returns {Parse.Schema } Returns the schema, so you can chain this call.
311
319
*/
312
320
addDate ( name : string , options : FieldOptions ) {
313
- if ( options && options . defaultValue ) {
314
- options . defaultValue = {
315
- __type : 'Date' ,
316
- iso : new Date ( options . defaultValue ) ,
317
- } ;
318
- }
319
321
return this . addField ( name , 'Date' , options ) ;
320
322
}
321
323
Original file line number Diff line number Diff line change @@ -194,6 +194,15 @@ describe('ParseSchema', () => {
194
194
}
195
195
} ) ;
196
196
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
+
197
206
it ( 'cannot add index with null name' , done => {
198
207
try {
199
208
const schema = new ParseSchema ( 'SchemaTest' ) ;
You can’t perform that action at this time.
0 commit comments