| 52 | } |
| 53 | |
| 54 | func (s *Strftime) Call(args []super.Value) super.Value { |
| 55 | formatArg, timeArg := args[0], args[1] |
| 56 | if formatArg.IsNull() || timeArg.IsNull() { |
| 57 | return super.Null |
| 58 | } |
| 59 | if !formatArg.IsString() { |
| 60 | return s.sctx.WrapError("strftime: string value required for format arg", formatArg) |
| 61 | } |
| 62 | if super.TypeUnder(timeArg.Type()) != super.TypeTime { |
| 63 | return s.sctx.WrapError("strftime: time value required for time arg", args[1]) |
| 64 | } |
| 65 | format := formatArg.AsString() |
| 66 | if s.formatter == nil || s.formatter.Pattern() != format { |
| 67 | var err error |
| 68 | if s.formatter, err = strftime.New(format); err != nil { |
| 69 | return s.sctx.WrapError("strftime: "+err.Error(), formatArg) |
| 70 | } |
| 71 | } |
| 72 | out := s.formatter.FormatString(timeArg.AsTime().Time()) |
| 73 | return super.NewString(out) |
| 74 | } |