Skip to content

Commit

Permalink
Add default time format as empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
zix99 committed Jul 21, 2022
1 parent 1f5f343 commit 395a9d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/expressions/stdlib/funcsTime.go
Expand Up @@ -14,6 +14,7 @@ import (
const defaultTimeFormat = time.RFC3339

var timeFormats = map[string]string{
"": defaultTimeFormat,
// Standard formats
"ASNIC": time.ANSIC,
"UNIX": time.UnixDate,
Expand Down
7 changes: 7 additions & 0 deletions pkg/expressions/stdlib/funcsTime_test.go
Expand Up @@ -20,14 +20,21 @@ func TestTimeExpression(t *testing.T) {
}

func TestFormatExpression(t *testing.T) {
// Defined type
testExpression(t,
mockContext("14/Apr/2016:19:12:25 +0200"),
"{timeformat {time {0} NGINX} RFC3339 utc}",
"2016-04-14T17:12:25Z")
// Explicit
testExpression(t,
mockContext("14/Apr/2016:19:12:25 +0200"),
`{timeformat {time {0} "_2/Jan/2006:15:04:05 -0700"} RFC3339 utc}`,
"2016-04-14T17:12:25Z")
// Default/empty-string
testExpression(t,
mockContext("14/Apr/2016:19:12:25 +0200"),
`{timeformat {time {0}} "" utc}`,
"2016-04-14T17:12:25Z")
}

func TestTimeExpressionDetection(t *testing.T) {
Expand Down

0 comments on commit 395a9d3

Please sign in to comment.