@@ -170,5 +170,86 @@ void main() {
170170 );
171171 },
172172 );
173+
174+ group ('date parsing' , () {
175+ test ('createdAt and updatedAt should handle Map date format' , () {
176+ // Create a parse object and simulate server response with date as Map
177+ final parseObject = ParseObject ('TestClass' );
178+
179+ // This is what the server sometimes returns - date as Map
180+ parseObject.fromJson ({
181+ 'objectId' : 'testObjectId' ,
182+ 'createdAt' : {'__type' : 'Date' , 'iso' : '2023-01-01T00:00:00.000Z' },
183+ 'updatedAt' : {'__type' : 'Date' , 'iso' : '2023-01-02T00:00:00.000Z' },
184+ });
185+
186+ // These should not throw and return DateTime objects
187+ expect (parseObject.createdAt, isA <DateTime >());
188+ expect (parseObject.updatedAt, isA <DateTime >());
189+
190+ expect (parseObject.createdAt? .year, equals (2023 ));
191+ expect (parseObject.createdAt? .month, equals (1 ));
192+ expect (parseObject.createdAt? .day, equals (1 ));
193+
194+ expect (parseObject.updatedAt? .year, equals (2023 ));
195+ expect (parseObject.updatedAt? .month, equals (1 ));
196+ expect (parseObject.updatedAt? .day, equals (2 ));
197+ });
198+
199+ test ('createdAt and updatedAt should handle String date format' , () {
200+ final parseObject = ParseObject ('TestClass' );
201+
202+ parseObject.fromJson ({
203+ 'objectId' : 'testObjectId' ,
204+ 'createdAt' : '2023-01-01T00:00:00.000Z' ,
205+ 'updatedAt' : '2023-01-02T00:00:00.000Z' ,
206+ });
207+
208+ expect (parseObject.createdAt, isA <DateTime >());
209+ expect (parseObject.updatedAt, isA <DateTime >());
210+
211+ expect (parseObject.createdAt? .year, equals (2023 ));
212+ expect (parseObject.updatedAt? .year, equals (2023 ));
213+ });
214+
215+ test ('createdAt and updatedAt should handle DateTime objects' , () {
216+ final createdAt = DateTime (2023 , 1 , 1 );
217+ final updatedAt = DateTime (2023 , 1 , 2 );
218+
219+ final parseObject = ParseObject ('TestClass' );
220+ parseObject.fromJson ({
221+ 'objectId' : 'testObjectId' ,
222+ 'createdAt' : createdAt,
223+ 'updatedAt' : updatedAt,
224+ });
225+
226+ expect (parseObject.createdAt, equals (createdAt));
227+ expect (parseObject.updatedAt, equals (updatedAt));
228+ });
229+
230+ test ('toJson should work when date fields are stored as Maps' , () {
231+ final parseObject = ParseObject ('TestClass' );
232+
233+ // Simulate server response with date as Map
234+ parseObject.fromJson ({
235+ 'objectId' : 'testObjectId' ,
236+ 'createdAt' : {'__type' : 'Date' , 'iso' : '2023-01-01T00:00:00.000Z' },
237+ 'updatedAt' : {'__type' : 'Date' , 'iso' : '2023-01-02T00:00:00.000Z' },
238+ });
239+
240+ // toJson should work without throwing
241+ expect (() => parseObject.toJson (full: true ), returnsNormally);
242+ expect (() => parseObject.toString (), returnsNormally);
243+ });
244+
245+ test ('createdAt and updatedAt should return null for null values' , () {
246+ final parseObject = ParseObject ('TestClass' );
247+
248+ parseObject.fromJson ({'objectId' : 'testObjectId' });
249+
250+ expect (parseObject.createdAt, isNull);
251+ expect (parseObject.updatedAt, isNull);
252+ });
253+ });
173254 });
174255}
0 commit comments