Skip to content

Commit

Permalink
Only allow system_clock timepoints when creating a Timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Aug 1, 2023
1 parent fb5bdcc commit 64be331
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-----------

### Internals
* None.
* Timestamp objects can now only be created from a system clock timepoint. ([#6112](https://github.com/realm/realm-core/issues/6112))

----------------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions src/realm/timestamp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class Timestamp {
constexpr Timestamp(const Timestamp&) = default;
constexpr Timestamp& operator=(const Timestamp&) = default;

template <typename C = std::chrono::system_clock, typename D = typename C::duration>
constexpr Timestamp(std::chrono::time_point<C, D> tp)
constexpr Timestamp(std::chrono::time_point<std::chrono::system_clock, std::chrono::system_clock::duration> tp)
: m_is_null(false)
{
int64_t native_nano = std::chrono::duration_cast<std::chrono::nanoseconds>(tp.time_since_epoch()).count();
Expand Down
4 changes: 2 additions & 2 deletions test/test_object_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ TEST(ObjectId_PrimaryKey)
{
SHARED_GROUP_TEST_PATH(path);
DBRef db = DB::create(path);
Timestamp now{std::chrono::steady_clock::now()};
Timestamp now{std::chrono::system_clock::now()};
ObjectId id{now, 0, 0};
ObjKey key;
{
Expand Down Expand Up @@ -314,7 +314,7 @@ TEST_TYPES(ObjectId_Query, WithIndex, WithoutIndex)
{
SHARED_GROUP_TEST_PATH(path);
DBRef db = DB::create(path);
auto now = std::chrono::steady_clock::now();
auto now = std::chrono::system_clock::now();
ObjectId t0;
ObjectId t25;
ObjectId alternative_id("000004560000000000170232");
Expand Down

0 comments on commit 64be331

Please sign in to comment.