File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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' ) ;
You can’t perform that action at this time.
0 commit comments