From f5d8779fb891b12c4b9eb2bbc1a337515d32d259 Mon Sep 17 00:00:00 2001 From: Anton Plebanovich Date: Tue, 3 Dec 2024 23:27:54 +0600 Subject: [PATCH 1/3] - Fix `Datetime` rounding in `RLMConvertBsonToRLMBSON` --- Realm/RLMBSON.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Realm/RLMBSON.mm b/Realm/RLMBSON.mm index 4abf8d8f6c..a5cbd920ef 100644 --- a/Realm/RLMBSON.mm +++ b/Realm/RLMBSON.mm @@ -386,7 +386,7 @@ BsonDocument RLMConvertRLMBSONArrayToBsonDocument(NSArray> *array) { case realm::bson::Bson::Type::Timestamp: return [[NSDate alloc] initWithTimeIntervalSince1970:static_cast(b).seconds]; case realm::bson::Bson::Type::Datetime: - return [[NSDate alloc] initWithTimeIntervalSince1970:static_cast(b).get_seconds()]; + return [[NSDate alloc] initWithTimeIntervalSince1970:double(static_cast(b).get_seconds()) + double(static_cast(b).get_nanoseconds()) / Timestamp::nanoseconds_per_second]; case realm::bson::Bson::Type::ObjectId: return [[RLMObjectId alloc] initWithValue:static_cast(b)]; case realm::bson::Bson::Type::Decimal128: From 0d44e96e604ca8c3fd410472c79ddc957163fbda Mon Sep 17 00:00:00 2001 From: Anton Plebanovich Date: Tue, 3 Dec 2024 23:48:48 +0600 Subject: [PATCH 2/3] - Rounding fix --- Realm/RLMBSON.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Realm/RLMBSON.mm b/Realm/RLMBSON.mm index a5cbd920ef..17f77f3f8e 100644 --- a/Realm/RLMBSON.mm +++ b/Realm/RLMBSON.mm @@ -386,7 +386,7 @@ BsonDocument RLMConvertRLMBSONArrayToBsonDocument(NSArray> *array) { case realm::bson::Bson::Type::Timestamp: return [[NSDate alloc] initWithTimeIntervalSince1970:static_cast(b).seconds]; case realm::bson::Bson::Type::Datetime: - return [[NSDate alloc] initWithTimeIntervalSince1970:double(static_cast(b).get_seconds()) + double(static_cast(b).get_nanoseconds()) / Timestamp::nanoseconds_per_second]; + return [[NSDate alloc] initWithTimeIntervalSince1970:double(static_cast(b).get_seconds()) + double(static_cast(b).get_nanoseconds() / USEC_PER_SEC) / 1000]; case realm::bson::Bson::Type::ObjectId: return [[RLMObjectId alloc] initWithValue:static_cast(b)]; case realm::bson::Bson::Type::Decimal128: From 34fa204d5d4294313691ad8bb39b80b114949044 Mon Sep 17 00:00:00 2001 From: Anton Plebanovich Date: Wed, 4 Dec 2024 00:01:09 +0600 Subject: [PATCH 3/3] - Use hardcoded constants instead of macro --- Realm/RLMBSON.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Realm/RLMBSON.mm b/Realm/RLMBSON.mm index 17f77f3f8e..e3d3788f1a 100644 --- a/Realm/RLMBSON.mm +++ b/Realm/RLMBSON.mm @@ -386,7 +386,7 @@ BsonDocument RLMConvertRLMBSONArrayToBsonDocument(NSArray> *array) { case realm::bson::Bson::Type::Timestamp: return [[NSDate alloc] initWithTimeIntervalSince1970:static_cast(b).seconds]; case realm::bson::Bson::Type::Datetime: - return [[NSDate alloc] initWithTimeIntervalSince1970:double(static_cast(b).get_seconds()) + double(static_cast(b).get_nanoseconds() / USEC_PER_SEC) / 1000]; + return [[NSDate alloc] initWithTimeIntervalSince1970:double(static_cast(b).get_seconds()) + double(static_cast(b).get_nanoseconds() / 1000) / 1000000]; case realm::bson::Bson::Type::ObjectId: return [[RLMObjectId alloc] initWithValue:static_cast(b)]; case realm::bson::Bson::Type::Decimal128: