MCPcopy Create free account
hub / github.com/brimdata/super / Eval

Method Eval

runtime/sam/expr/cast.go:169–197  ·  view source on GitHub ↗
(val super.Value)

Source from the content-addressed store, hash-verified

167}
168
169func (c *casterTime) Eval(val super.Value) super.Value {
170 id := val.Type().ID()
171 var ts nano.Ts
172 switch {
173 case id == super.IDTime:
174 return val
175 case id == super.IDString:
176 gotime, err := dateparse.ParseAny(byteconv.UnsafeString(val.Bytes()))
177 if err != nil {
178 v, err := byteconv.ParseFloat64(val.Bytes())
179 if err != nil {
180 return c.sctx.WrapError("cannot cast to time", val)
181 }
182 ts = nano.Ts(v)
183 } else {
184 ts = nano.Ts(gotime.UnixNano())
185 }
186 case super.IsNumber(id):
187 //XXX we call coerce on integers here to avoid unsigned/signed decode
188 v, ok := coerce.ToInt(val, super.TypeTime)
189 if !ok {
190 return c.sctx.WrapError("cannot cast to time", val)
191 }
192 ts = nano.Ts(v)
193 default:
194 return c.sctx.WrapError("cannot cast to time", val)
195 }
196 return super.NewTime(ts)
197}
198
199type casterString struct {
200 sctx *super.Context

Callers

nothing calls this directly

Calls 10

UnsafeStringFunction · 0.92
ParseFloat64Function · 0.92
TsTypeAlias · 0.92
IsNumberFunction · 0.92
ToIntFunction · 0.92
NewTimeFunction · 0.92
WrapErrorMethod · 0.80
IDMethod · 0.65
TypeMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected