Skip to content
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

Fix asTime API #239

Merged
merged 1 commit into from
Aug 21, 2024
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
2 changes: 1 addition & 1 deletion grpc/federation/cel/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (lib *TimeLibrary) CompileOptions() []cel.EnvOption {
"asTime",
MemberOverloadFunc(createTimeID("asTime_timestamp_int_time"), cel.TimestampType, []*cel.Type{}, TimeType,
func(_ context.Context, self ref.Val, args ...ref.Val) ref.Val {
return lib.toTimeValue(self.(*types.Timestamp).Time)
return lib.toTimeValue(self.(types.Timestamp).Time)
},
),
),
Expand Down
16 changes: 16 additions & 0 deletions grpc/federation/cel/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,22 @@ func TestTime(t *testing.T) {
return nil
},
},
{
name: "asTime",
expr: "google.protobuf.Timestamp{seconds: 1560000000}.asTime()",
cmp: func(got ref.Val) error {
gotV, ok := got.Value().(*cellib.Time)
if !ok {
return fmt.Errorf("invalid result type: %T", got)
}
gotSecond := gotV.GetTimestamp().GetSeconds()
expected := 1560000000
if diff := cmp.Diff(int(gotSecond), expected); diff != "" {
return fmt.Errorf("(-got, +want)\n%s", diff)
}
return nil
},
},
}
reg, err := types.NewRegistry(new(cellib.Time), new(cellib.Location))
if err != nil {
Expand Down
Loading