比较google::protobuf::Timestamp的最正确的方法是什么?对于这种类型,没有为时间戳"<“定义最自然的(对我来说)操作器。
例如,我应该将这两个值转换为nano并进行比较吗?还是还有其他方便的功能?此外,我没有找到类似"t.isLarger(t2)“之类的方法,也没有为这种类型定义其他比较方法。
发布于 2022-03-22 14:23:40
自然的事情似乎是直接比较秒和nanos字段:
bool operator<(
const google::protobuf::Timestamp &left,
const google::protobuf::Timestamp &right )
{
return left.seconds() == right.seconds() ?
left.nanos() < right.nanos() :
left.seconds() < right.seconds();
}
您可能还想看看:https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.util.time_util
发布于 2022-03-29 06:37:40
google::protobuf::util包含重载的操作符<,>,==,!= .
https://stackoverflow.com/questions/71570599
复制