|
21 | 21 | #include "absl/strings/match.h"
|
22 | 22 | #include "absl/strings/str_replace.h"
|
23 | 23 | #include "absl/strings/string_view.h"
|
| 24 | +#include "absl/time/time.h" |
24 | 25 | #include "base/builtins.h"
|
25 | 26 | #include "base/function_adapter.h"
|
26 | 27 | #include "base/handle.h"
|
@@ -169,6 +170,24 @@ Handle<Value> GetMilliseconds(ValueFactory& value_factory, absl::Time timestamp,
|
169 | 170 | });
|
170 | 171 | }
|
171 | 172 |
|
| 173 | +Handle<Value> GetMicroseconds(ValueFactory& value_factory, absl::Time timestamp, |
| 174 | + absl::string_view tz) { |
| 175 | + return GetTimeBreakdownPart( |
| 176 | + value_factory, timestamp, tz, |
| 177 | + [](const absl::TimeZone::CivilInfo& breakdown) { |
| 178 | + return absl::ToInt64Microseconds(breakdown.subsecond); |
| 179 | + }); |
| 180 | +} |
| 181 | + |
| 182 | +Handle<Value> GetNanoseconds(ValueFactory& value_factory, absl::Time timestamp, |
| 183 | + absl::string_view tz) { |
| 184 | + return GetTimeBreakdownPart( |
| 185 | + value_factory, timestamp, tz, |
| 186 | + [](const absl::TimeZone::CivilInfo& breakdown) { |
| 187 | + return absl::ToInt64Nanoseconds(breakdown.subsecond); |
| 188 | + }); |
| 189 | +} |
| 190 | + |
172 | 191 | absl::Status RegisterTimestampFunctions(FunctionRegistry& registry,
|
173 | 192 | const RuntimeOptions& options) {
|
174 | 193 | CEL_RETURN_IF_ERROR(registry.Register(
|
@@ -333,6 +352,24 @@ absl::Status RegisterTimestampFunctions(FunctionRegistry& registry,
|
333 | 352 | return GetMilliseconds(value_factory, ts, tz.ToString());
|
334 | 353 | })));
|
335 | 354 |
|
| 355 | + CEL_RETURN_IF_ERROR(registry.Register( |
| 356 | + BinaryFunctionAdapter<Handle<Value>, absl::Time, const StringValue&>:: |
| 357 | + CreateDescriptor(builtin::kMicroseonds, true), |
| 358 | + BinaryFunctionAdapter<Handle<Value>, absl::Time, const StringValue&>:: |
| 359 | + WrapFunction([](ValueFactory& value_factory, absl::Time ts, |
| 360 | + const StringValue& tz) -> Handle<Value> { |
| 361 | + return GetMicroseconds(value_factory, ts, tz.ToString()); |
| 362 | + }))); |
| 363 | + |
| 364 | + CEL_RETURN_IF_ERROR(registry.Register( |
| 365 | + BinaryFunctionAdapter<Handle<Value>, absl::Time, const StringValue&>:: |
| 366 | + CreateDescriptor(builtin::kNanoseconds, true), |
| 367 | + BinaryFunctionAdapter<Handle<Value>, absl::Time, const StringValue&>:: |
| 368 | + WrapFunction([](ValueFactory& value_factory, absl::Time ts, |
| 369 | + const StringValue& tz) -> Handle<Value> { |
| 370 | + return GetNanoseconds(value_factory, ts, tz.ToString()); |
| 371 | + }))); |
| 372 | + |
336 | 373 | return registry.Register(
|
337 | 374 | UnaryFunctionAdapter<Handle<Value>, absl::Time>::CreateDescriptor(
|
338 | 375 | builtin::kMilliseconds, true),
|
|
0 commit comments