From 7c01441392c00ab8fbffc29111b046c464de7e2c Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Thu, 5 Dec 2024 13:34:11 +0200 Subject: [PATCH] added yesterday and tomorrow date filter macros --- CHANGELOG.md | 5 +++++ tools/search/identifier_macros.go | 20 ++++++++++++++++++++ tools/search/identifier_macros_test.go | 2 ++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47a843c8..08b184ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.24.0 (WIP) + +- Added `@yesterday` and `@tomorrow` date filter macros (@todo docs). + + ## v0.23.5 (WIP) - Fixed UI logs search not properly accounting for the "Include requests by superusers" toggle when multiple search expressions are used. diff --git a/tools/search/identifier_macros.go b/tools/search/identifier_macros.go index aa3639ce..b0314de4 100644 --- a/tools/search/identifier_macros.go +++ b/tools/search/identifier_macros.go @@ -23,6 +23,26 @@ var identifierMacros = map[string]func() (any, error){ return d.String(), nil }, + "@yesterday": func() (any, error) { + yesterday := timeNow().UTC().AddDate(0, 0, -1) + + d, err := types.ParseDateTime(yesterday) + if err != nil { + return "", fmt.Errorf("@yesterday: %w", err) + } + + return d.String(), nil + }, + "@tomorrow": func() (any, error) { + tomorrow := timeNow().UTC().AddDate(0, 0, 1) + + d, err := types.ParseDateTime(tomorrow) + if err != nil { + return "", fmt.Errorf("@tomorrow: %w", err) + } + + return d.String(), nil + }, "@second": func() (any, error) { return timeNow().UTC().Second(), nil }, diff --git a/tools/search/identifier_macros_test.go b/tools/search/identifier_macros_test.go index 19a515c5..0c58df4b 100644 --- a/tools/search/identifier_macros_test.go +++ b/tools/search/identifier_macros_test.go @@ -14,6 +14,8 @@ func TestIdentifierMacros(t *testing.T) { testMacros := map[string]any{ "@now": "2023-02-03 04:05:06.000Z", + "@yesterday": "2023-02-02 04:05:06.000Z", + "@tomorrow": "2023-02-04 04:05:06.000Z", "@second": 6, "@minute": 5, "@hour": 4,