Skip to content

Commit

Permalink
fix asTime api
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Aug 21, 2024
1 parent adf6a0e commit 6186ab6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit 6186ab6

Please sign in to comment.