| 63 | } |
| 64 | |
| 65 | absl::Status EncodeDuration(absl::Duration duration, |
| 66 | google::protobuf::Duration* proto) { |
| 67 | CEL_RETURN_IF_ERROR(CelValidateDuration(duration)); |
| 68 | // s and n may both be negative, per the Duration proto spec. |
| 69 | const int64_t s = absl::IDivDuration(duration, absl::Seconds(1), &duration); |
| 70 | const int64_t n = |
| 71 | absl::IDivDuration(duration, absl::Nanoseconds(1), &duration); |
| 72 | proto->set_seconds(s); |
| 73 | proto->set_nanos(n); |
| 74 | return absl::OkStatus(); |
| 75 | } |
| 76 | |
| 77 | absl::StatusOr<std::string> EncodeDurationToString(absl::Duration duration) { |
| 78 | google::protobuf::Duration d; |