From 56eba71407e5b0a29f7135e172f2f88740590e9b Mon Sep 17 00:00:00 2001 From: Jonathan Tatum Date: Wed, 7 May 2025 08:35:50 -0700 Subject: [PATCH] internal PiperOrigin-RevId: 755867419 --- internal/time.cc | 33 +++++++++++++++++++++++++++++++++ internal/time.h | 43 +++++++------------------------------------ 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/internal/time.cc b/internal/time.cc index fb48dd164..45945613d 100644 --- a/internal/time.cc +++ b/internal/time.cc @@ -24,6 +24,7 @@ #include "absl/strings/string_view.h" #include "absl/time/time.h" #include "internal/status_macros.h" +#include "google/protobuf/util/time_util.h" namespace cel::internal { @@ -36,6 +37,38 @@ std::string RawFormatTimestamp(absl::Time timestamp) { } // namespace +absl::Duration MaxDuration() { + // This currently supports a larger range then the current CEL spec. The + // intent is to widen the CEL spec to support the larger range and match + // google.protobuf.Duration from protocol buffer messages, which this + // implementation currently supports. + // TODO(google/cel-spec/issues/214): revisit + return absl::Seconds(google::protobuf::util::TimeUtil::kDurationMaxSeconds) + + absl::Nanoseconds(google::protobuf::util::TimeUtil::kDurationMaxNanoseconds); +} + +absl::Duration MinDuration() { + // This currently supports a larger range then the current CEL spec. The + // intent is to widen the CEL spec to support the larger range and match + // google.protobuf.Duration from protocol buffer messages, which this + // implementation currently supports. + // TODO(google/cel-spec/issues/214): revisit + return absl::Seconds(google::protobuf::util::TimeUtil::kDurationMinSeconds) + + absl::Nanoseconds(google::protobuf::util::TimeUtil::kDurationMinNanoseconds); +} + +absl::Time MaxTimestamp() { + return absl::UnixEpoch() + + absl::Seconds(google::protobuf::util::TimeUtil::kTimestampMaxSeconds) + + absl::Nanoseconds(google::protobuf::util::TimeUtil::kTimestampMaxNanoseconds); +} + +absl::Time MinTimestamp() { + return absl::UnixEpoch() + + absl::Seconds(google::protobuf::util::TimeUtil::kTimestampMinSeconds) + + absl::Nanoseconds(google::protobuf::util::TimeUtil::kTimestampMinNanoseconds); +} + absl::Status ValidateDuration(absl::Duration duration) { if (duration < MinDuration()) { return absl::InvalidArgumentError( diff --git a/internal/time.h b/internal/time.h index 38b5c076e..402cb6c8b 100644 --- a/internal/time.h +++ b/internal/time.h @@ -21,45 +21,16 @@ #include "absl/status/statusor.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" -#include "google/protobuf/util/time_util.h" namespace cel::internal { - inline absl::Duration - MaxDuration() { - // This currently supports a larger range then the current CEL spec. The - // intent is to widen the CEL spec to support the larger range and match - // google.protobuf.Duration from protocol buffer messages, which this - // implementation currently supports. - // TODO(google/cel-spec/issues/214): revisit - return absl::Seconds(google::protobuf::util::TimeUtil::kDurationMaxSeconds) + - absl::Nanoseconds(google::protobuf::util::TimeUtil::kDurationMaxNanoseconds); -} - - inline absl::Duration - MinDuration() { - // This currently supports a larger range then the current CEL spec. The - // intent is to widen the CEL spec to support the larger range and match - // google.protobuf.Duration from protocol buffer messages, which this - // implementation currently supports. - // TODO(google/cel-spec/issues/214): revisit - return absl::Seconds(google::protobuf::util::TimeUtil::kDurationMinSeconds) + - absl::Nanoseconds(google::protobuf::util::TimeUtil::kDurationMinNanoseconds); -} - - inline absl::Time - MaxTimestamp() { - return absl::UnixEpoch() + - absl::Seconds(google::protobuf::util::TimeUtil::kTimestampMaxSeconds) + - absl::Nanoseconds(google::protobuf::util::TimeUtil::kTimestampMaxNanoseconds); -} - - inline absl::Time - MinTimestamp() { - return absl::UnixEpoch() + - absl::Seconds(google::protobuf::util::TimeUtil::kTimestampMinSeconds) + - absl::Nanoseconds(google::protobuf::util::TimeUtil::kTimestampMinNanoseconds); -} +absl::Duration MaxDuration(); + +absl::Duration MinDuration(); + +absl::Time MaxTimestamp(); + +absl::Time MinTimestamp(); absl::Status ValidateDuration(absl::Duration duration);