Skip to content

Commit 9ec5176

Browse files
committed
Avoid including time_util in time.h
Unfortunately, due to protocolbuffers/protobuf#21301, including time_util inside of a header will cause a lot of headaches on MSVC/Windows. While that can and should be resolved separately of this, in the interim there will be a lot of people using protobuf versions without a fix for this for the foreseeable future. This leaves us with only a couple of obvious options: either inline the constants, or move the function definitions into time.cc. I chose the latter since it doesn't seem like there is likely to be a substantial performance hit for this, as these are only used in a couple of locations that don't appear to be very hot paths.
1 parent b9648d4 commit 9ec5176

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

internal/time.cc

+33
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "absl/strings/string_view.h"
2525
#include "absl/time/time.h"
2626
#include "internal/status_macros.h"
27+
#include "google/protobuf/util/time_util.h"
2728

2829
namespace cel::internal {
2930

@@ -36,6 +37,38 @@ std::string RawFormatTimestamp(absl::Time timestamp) {
3637

3738
} // namespace
3839

40+
absl::Duration MaxDuration() {
41+
// This currently supports a larger range then the current CEL spec. The
42+
// intent is to widen the CEL spec to support the larger range and match
43+
// google.protobuf.Duration from protocol buffer messages, which this
44+
// implementation currently supports.
45+
// TODO(google/cel-spec/issues/214): revisit
46+
return absl::Seconds(google::protobuf::util::TimeUtil::kDurationMaxSeconds) +
47+
absl::Nanoseconds(google::protobuf::util::TimeUtil::kDurationMaxNanoseconds);
48+
}
49+
50+
absl::Duration MinDuration() {
51+
// This currently supports a larger range then the current CEL spec. The
52+
// intent is to widen the CEL spec to support the larger range and match
53+
// google.protobuf.Duration from protocol buffer messages, which this
54+
// implementation currently supports.
55+
// TODO(google/cel-spec/issues/214): revisit
56+
return absl::Seconds(google::protobuf::util::TimeUtil::kDurationMinSeconds) +
57+
absl::Nanoseconds(google::protobuf::util::TimeUtil::kDurationMinNanoseconds);
58+
}
59+
60+
absl::Time MaxTimestamp() {
61+
return absl::UnixEpoch() +
62+
absl::Seconds(google::protobuf::util::TimeUtil::kTimestampMaxSeconds) +
63+
absl::Nanoseconds(google::protobuf::util::TimeUtil::kTimestampMaxNanoseconds);
64+
}
65+
66+
absl::Time MinTimestamp() {
67+
return absl::UnixEpoch() +
68+
absl::Seconds(google::protobuf::util::TimeUtil::kTimestampMinSeconds) +
69+
absl::Nanoseconds(google::protobuf::util::TimeUtil::kTimestampMinNanoseconds);
70+
}
71+
3972
absl::Status ValidateDuration(absl::Duration duration) {
4073
if (duration < MinDuration()) {
4174
return absl::InvalidArgumentError(

internal/time.h

+7-36
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,16 @@
2121
#include "absl/status/statusor.h"
2222
#include "absl/strings/string_view.h"
2323
#include "absl/time/time.h"
24-
#include "google/protobuf/util/time_util.h"
2524

2625
namespace cel::internal {
2726

28-
inline absl::Duration
29-
MaxDuration() {
30-
// This currently supports a larger range then the current CEL spec. The
31-
// intent is to widen the CEL spec to support the larger range and match
32-
// google.protobuf.Duration from protocol buffer messages, which this
33-
// implementation currently supports.
34-
// TODO(google/cel-spec/issues/214): revisit
35-
return absl::Seconds(google::protobuf::util::TimeUtil::kDurationMaxSeconds) +
36-
absl::Nanoseconds(google::protobuf::util::TimeUtil::kDurationMaxNanoseconds);
37-
}
38-
39-
inline absl::Duration
40-
MinDuration() {
41-
// This currently supports a larger range then the current CEL spec. The
42-
// intent is to widen the CEL spec to support the larger range and match
43-
// google.protobuf.Duration from protocol buffer messages, which this
44-
// implementation currently supports.
45-
// TODO(google/cel-spec/issues/214): revisit
46-
return absl::Seconds(google::protobuf::util::TimeUtil::kDurationMinSeconds) +
47-
absl::Nanoseconds(google::protobuf::util::TimeUtil::kDurationMinNanoseconds);
48-
}
49-
50-
inline absl::Time
51-
MaxTimestamp() {
52-
return absl::UnixEpoch() +
53-
absl::Seconds(google::protobuf::util::TimeUtil::kTimestampMaxSeconds) +
54-
absl::Nanoseconds(google::protobuf::util::TimeUtil::kTimestampMaxNanoseconds);
55-
}
56-
57-
inline absl::Time
58-
MinTimestamp() {
59-
return absl::UnixEpoch() +
60-
absl::Seconds(google::protobuf::util::TimeUtil::kTimestampMinSeconds) +
61-
absl::Nanoseconds(google::protobuf::util::TimeUtil::kTimestampMinNanoseconds);
62-
}
27+
absl::Duration MaxDuration();
28+
29+
absl::Duration MinDuration();
30+
31+
absl::Time MaxTimestamp();
32+
33+
absl::Time MinTimestamp();
6334

6435
absl::Status ValidateDuration(absl::Duration duration);
6536

0 commit comments

Comments
 (0)