fix for upgrading optional date properties

This commit is contained in:
Ari Lazier 2016-05-26 13:17:19 -07:00 committed by Scott Kyle
parent 47776d9b0a
commit 027d4fd153
8 changed files with 27 additions and 9 deletions

View File

@ -1,3 +1,14 @@
x.x.x Release notes (yyyy-MM-dd)
=============================================================
### Breaking changes
* None
### Enhancements
* None
### Bugfixes
* Fix for crash when updating Realms with optional date properties to the new file format
0.13.1 Release notes (2016-5-24)
=============================================================
### Breaking changes

View File

@ -13,7 +13,4 @@
<FileRef
location = "group:examples/ReactExample/ios/ReactExample.xcodeproj">
</FileRef>
<FileRef
location = "group:src/node/RealmNode.xcodeproj">
</FileRef>
</Workspace>

View File

@ -267,6 +267,9 @@ static void convert_outdated_datetime_columns(const SharedRealm &realm) {
}
for (size_t row_index = 0; row_index < table->size(); row_index++) {
if (table->is_null(property.table_column, row_index)) {
continue;
}
auto milliseconds = table->get_timestamp(property.table_column, row_index).get_seconds();
table->set_timestamp(property.table_column, row_index, Timestamp(milliseconds / 1000, (milliseconds % 1000) * 1000000));
}

Binary file not shown.

Binary file not shown.

View File

@ -479,14 +479,20 @@ module.exports = BaseTest.extend({
// test file format upgrade
var realm_v3 = new Realm({path: 'dates-v3.realm', schema: [schemas.DateObject]});
TestCase.assertEqual(realm_v3.objects('Date').length, 1);
TestCase.assertEqual(realm_v3.objects('Date').length, 2);
TestCase.assertEqual(realm_v3.objects('Date')[0].currentDate.getTime(), 1462500087955);
TestCase.assertEqual(realm_v3.objects('Date')[0].nullDate.getTime(), 1462500087955);
TestCase.assertEqual(realm_v3.objects('Date')[1].currentDate.getTime(), -10000);
TestCase.assertEqual(realm_v3.objects('Date')[1].nullDate, null);
// get new file format is not upgraded
var realm_v5 = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]});
TestCase.assertEqual(realm_v5.objects('Date').length, 1);
TestCase.assertEqual(realm_v5.objects('Date')[0].currentDate.getTime(), 1462500087955);
TestCase.assertEqual(realm_v5.objects('Date').length, 2);
TestCase.assertEqual(realm_v3.objects('Date')[0].currentDate.getTime(), 1462500087955);
TestCase.assertEqual(realm_v3.objects('Date')[0].nullDate.getTime(), 1462500087955);
TestCase.assertEqual(realm_v3.objects('Date')[1].currentDate.getTime(), -10000);
TestCase.assertEqual(realm_v3.objects('Date')[1].nullDate, null);
// test different dates
var realm = new Realm({schema: [schemas.DateObject]});
realm.write(function() {

View File

@ -739,7 +739,7 @@ module.exports = BaseTest.extend({
Realm.copyBundledRealmFiles();
var realm = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]});
TestCase.assertEqual(realm.objects('Date').length, 1);
TestCase.assertEqual(realm.objects('Date').length, 2);
TestCase.assertEqual(realm.objects('Date')[0].currentDate.getTime(), 1462500087955);
var newDate = new Date(1);

View File

@ -174,6 +174,7 @@ exports.NullQueryObject = {
exports.DateObject = {
name: 'Date',
properties: {
currentDate: 'date'
currentDate: 'date',
nullDate: { type: 'date', optional: true }
}
};