Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/expressions/stdlib/funcsTime.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func smartDateParseWrapper(format string, tz *time.Location, dateStage KeyBuilde
atomicFormat.Store("")
const FORMAT_UNIX = "UNIX"

staticResult, isStaticResult := EvalStaticStage(dateStage)

return KeyBuilderStage(func(context KeyBuilderContext) string {
strTime := dateStage(context)
if strTime == "" { // This is important for future optimization efforts (so an empty string won't be remembered as a valid format)
Expand All @@ -102,7 +104,10 @@ func smartDateParseWrapper(format string, tz *time.Location, dateStage KeyBuilde
return ErrorParsing
}

atomicFormat.Store(liveFormat)
// HACK: Check if this looks like a cache-check, and if so, don't update the cached format
if strTime != staticResult || isStaticResult {
atomicFormat.Store(liveFormat)
}
}

if liveFormat == FORMAT_UNIX {
Expand Down
5 changes: 5 additions & 0 deletions pkg/expressions/stdlib/funcsTime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func TestTimeExpressionErr(t *testing.T) {
testExpressionErr(t, mockContext(""), "{time a b c d e}", "<ARGN>", ErrArgCount)
}

func TestTimeExpressionDetectionWithConcat(t *testing.T) {
testExpression(t, mockContext("12:19:22"), `{time "2026-01-02 {0}"}`, "1767356362")
}

func TestCachedParsingTimestamp(t *testing.T) {
kb, err := NewStdKeyBuilder().Compile("{time {0} cache}")
assert.Nil(t, err)
Expand Down Expand Up @@ -311,6 +315,7 @@ func TestLoadingTimezone(t *testing.T) {
// BenchmarkTimeParseExpression/{time_"14/Apr/2016:19:12:25_+0200"_auto}-4 761017 1645 ns/op 336 B/op 4 allocs/op
func BenchmarkTimeParseExpression(b *testing.B) {
benchmarkExpression(b, mockContext(), `{time "14/Apr/2016:19:12:25 +0200" auto}`, "1460653945")
benchmarkExpression(b, mockContext(), `{time "14/Apr/2016:19:12:25 +0200"}`, "1460653945")
}

// BenchmarkTimeParse-4 1686390 654.7 ns/op 120 B/op 4 allocs/op
Expand Down
Loading