Merge pull request #454 from realm/al-negative-dates
Fix for negative timestamps
This commit is contained in:
commit
ab69a4f910
|
@ -1,4 +1,4 @@
|
|||
x.x.x Release notes (yyyy-MM-dd)
|
||||
0.13.1 Release notes (yyyy-MM-dd)
|
||||
=============================================================
|
||||
### Breaking changes
|
||||
* None
|
||||
|
@ -7,7 +7,7 @@ x.x.x Release notes (yyyy-MM-dd)
|
|||
* Added `isValid()` method to `List` and `Results` to check for deleleted or invalidated objects
|
||||
|
||||
### Bugfixes
|
||||
* None
|
||||
* Fix for crash when inserting dates from before the epoch
|
||||
|
||||
0.13.0 Release notes (2016-5-19)
|
||||
=============================================================
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue