(val super.Value)
| 167 | } |
| 168 | |
| 169 | func (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 | |
| 199 | type casterString struct { |
| 200 | sctx *super.Context |
nothing calls this directly
no test coverage detected