Skip to content

Conversation

@lia-viam
Copy link
Collaborator

@lia-viam lia-viam commented Dec 3, 2024

Fixes the incorrect std::chrono::time_point type used throughout the SDK. I have opted to call this viam::sdk::time_pt so as not to create name clashes with time_point for anyone doing using namespace std::chrono.

@lia-viam lia-viam requested a review from a team as a code owner December 3, 2024 16:05
@lia-viam lia-viam requested review from purplenicole730 and stuqdog and removed request for a team December 3, 2024 16:05
Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just interested. I'm happy to see this is being fixed!

const std::string kRDK = "rdk";
const std::string kBuiltin = "builtin";

using time_pt = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What motivated the switch from calling it time_point to time_pt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find people do 'using namespace std::chrono' pretty often so I think this would be a name clash with our time_point and std::chrono::time_point<Clock, Duration>

const std::chrono::nanoseconds nanos(timestamp.nanos());
return time_point(std::chrono::duration_cast<std::chrono::system_clock::duration>(seconds) +
nanos);
time_pt timestamp_to_time_pt(const google::protobuf::Timestamp& timestamp) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this later be unified with #332 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I look forward to doing so haha

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a question and a nit, otherwise lgtm!

/// std::chrono::time_point<long long, std::chrono::nanoseconds>
std::chrono::time_point<long long, std::chrono::nanoseconds> timestamp_to_time_pt(
const google::protobuf::Timestamp& timestamp);
/// @brief convert a google::protobuf::Timestamp to time_point
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) s/time_point/time_pt

/// a google::protobuf::Timestamp.
google::protobuf::Timestamp time_pt_to_timestamp(
const std::chrono::time_point<long long, std::chrono::nanoseconds>& time_pt);
/// @brief convert a time_point to a google::protobuf::Timestamp.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) s/time_point/time_pt

@lia-viam lia-viam merged commit b9f2345 into viamrobotics:main Dec 4, 2024
4 checks passed
@lia-viam lia-viam deleted the chrono-fix branch December 4, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants