Skip to content

Commit

Permalink
Adding 1 time format. cleanup some switches (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly authored Oct 5, 2024
1 parent 7f6c55f commit 80b4838
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
10 changes: 5 additions & 5 deletions eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,15 @@ func (s *State) evalIndexRangeExpression(left object.Object, leftIdx, rightIdx a
}
l = min(l, int64(num))
r = min(r, int64(num))
switch {
case left.Type() == object.STRING:
switch left.Type() {
case object.STRING:
str := left.(object.String).Value
return object.String{Value: str[l:r]}
case left.Type() == object.ARRAY:
case object.ARRAY:
return object.NewArray(object.Elements(left)[l:r])
case left.Type() == object.MAP:
case object.MAP:
return object.Range(left, l, r) // could call that one for all of them...
case left.Type() == object.NIL:
case object.NIL:
return object.NULL
default:
return s.NewError("range index operator not supported: " + left.Type().String())
Expand Down
25 changes: 13 additions & 12 deletions extensions/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,18 +654,19 @@ func createTimeFunctions() {
var parseFormats = []string{
time.DateTime, // = "2006-01-02 15:04:05" // first as that's what time.info().str returns (with usec).
time.RFC3339,
time.ANSIC, // = "Mon Jan _2 15:04:05 2006"
time.UnixDate, // = "Mon Jan _2 15:04:05 MST 2006"
time.RFC822, // = "02 Jan 06 15:04 MST"
time.RFC822Z, // = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone
time.RFC850, // = "Monday, 02-Jan-06 15:04:05 MST"
time.RFC1123, // = "Mon, 02 Jan 2006 15:04:05 MST"
time.RFC1123Z, // = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
time.RFC3339, // = "2006-01-02T15:04:05Z07:00"
time.Kitchen, // = "3:04PM"
time.Stamp, // = "Jan _2 15:04:05"
time.DateOnly, // = "2006-01-02"
time.TimeOnly, // = "15:04:05"
time.ANSIC, // = "Mon Jan _2 15:04:05 2006"
time.UnixDate, // = "Mon Jan _2 15:04:05 MST 2006"
time.RFC822, // = "02 Jan 06 15:04 MST"
time.RFC822Z, // = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone
time.RFC850, // = "Monday, 02-Jan-06 15:04:05 MST"
time.RFC1123, // = "Mon, 02 Jan 2006 15:04:05 MST"
time.RFC1123Z, // = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
time.RFC3339, // = "2006-01-02T15:04:05Z07:00"
"2006-01-02T15:04:05", // ISO8601 without timezone
time.Kitchen, // = "3:04PM"
time.Stamp, // = "Jan _2 15:04:05"
time.DateOnly, // = "2006-01-02"
time.TimeOnly, // = "15:04:05"
"_2 Jan 2006",
"_2/1/2006", // try EU (ie sensible) style first.
"1/_2/2006",
Expand Down

0 comments on commit 80b4838

Please sign in to comment.