Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow system_clock timepoints when creating a Timestamp #6847

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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