fix for negative timestamps

This commit is contained in:
Ari Lazier 2016-05-24 08:23:21 -07:00 committed by Scott Kyle
parent 64ae03512a
commit 9e05728dce
3 changed files with 29 additions and 3 deletions

View File

@ -1,3 +1,14 @@
0.13.1 Release notes (yyyy-MM-dd)
=============================================================
### Breaking changes
* None
### Enhancements
* None
### Bugfixes
* Fix for crash when inserting dates from before the epoch
0.13.0 Release notes (2016-5-19)
=============================================================
### Breaking changes

View File

@ -88,8 +88,8 @@ struct NativeAccessor {
static Timestamp to_timestamp(ContextType ctx, ValueType &value) {
ObjectType date = Value::validated_to_date(ctx, value, "Property");
double milliseconds = Value::to_number(ctx, date);
u_int64_t seconds = milliseconds / 1000;
u_int32_t nanoseconds = ((u_int64_t)milliseconds % 1000) * 1000000;
int64_t seconds = milliseconds / 1000;
int32_t nanoseconds = ((int64_t)milliseconds % 1000) * 1000000;
return Timestamp(seconds, nanoseconds);
}
static ValueType from_timestamp(ContextType ctx, Timestamp ts) {

View File

@ -474,15 +474,30 @@ module.exports = BaseTest.extend({
TestCase.assertEqual(obj.ignored, true);
},
testCurrentDate: function() {
testDates: function() {
Realm.copyBundledRealmFiles();
// 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')[0].currentDate.getTime(), 1462500087955);
// 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);
// test different dates
var realm = new Realm({schema: [schemas.DateObject]});
realm.write(function() {
realm.create('Date', { currentDate: new Date(10000) });
realm.create('Date', { currentDate: new Date(-10000) });
realm.create('Date', { currentDate: new Date(1000000000000) });
realm.create('Date', { currentDate: new Date(-1000000000000) });
});
TestCase.assertEqual(realm.objects('Date')[0].currentDate.getTime(), 10000);
TestCase.assertEqual(realm.objects('Date')[1].currentDate.getTime(), -10000);
TestCase.assertEqual(realm.objects('Date')[2].currentDate.getTime(), 1000000000000);
TestCase.assertEqual(realm.objects('Date')[3].currentDate.getTime(), -1000000000000);
}
});