Skip to content
Merged
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
9 changes: 9 additions & 0 deletions cel-c/duration.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ static CEL_INLINE void cel_Duration_ToUnix(cel_Duration d,
}
}

// cel_Duration_ToUnixSeconds
//
// Returns the seconds part of the cel_Duration.
CEL_ATTRIBUTE_NODISCARD
static CEL_INLINE int64_t cel_Duration_ToUnixSeconds(cel_Duration d) {
CEL_ASSERT(cel_Duration_Valid(d.sec, d.nsec));
return d.sec;
}

// cel_Duration_Equals
//
// Tests the two durations for equality.
Expand Down
1 change: 1 addition & 0 deletions cel-c/src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ cc_test(
"//cel-c:arena",
"//cel-c:ast",
"//cel-c:config",
"//cel-c:duration",
"//cel-c:error",
"//cel-c:error_code",
"//cel-c:runtime",
Expand Down
3 changes: 2 additions & 1 deletion cel-c/src/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "cel-c/arena.h"
#include "cel-c/ast.h"
#include "cel-c/config.h"
#include "cel-c/duration.h"
#include "cel-c/error.h"
#include "cel-c/error_code.h"
#include "cel-c/program.h"
Expand Down Expand Up @@ -796,7 +797,7 @@ TEST_F(RuntimeTest, CallDuration) {
_cel_ActivationPtr act(Activate(prog.get(), &var_resolver));
cel_Value value = Execute(act.get());
ASSERT_TRUE(cel_Value_IsDuration(&value));
EXPECT_EQ(cel_Value_GetDuration(&value).sec, 3600);
EXPECT_EQ(cel_Duration_ToUnixSeconds(cel_Value_GetDuration(&value)), 3600);

prog = Parse(R"cel(duration("invalid"))cel");
act = Activate(prog.get(), &var_resolver);
Expand Down