Skip to content

Avoid including time_util in time.h #1447

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

Closed
Closed
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
33 changes: 33 additions & 0 deletions internal/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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(
Expand Down
43 changes: 7 additions & 36 deletions internal/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down