From 8fc366913fce18c389a3c2a3bf085b7f5494e4e7 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 22 Oct 2024 23:11:27 +1100 Subject: [PATCH] [8.x] Fix wrong date on a header of a report when generated from relative date (#197027) (#197204) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [Fix wrong date on a header of a report when generated from relative date (#197027)](https://github.com/elastic/kibana/pull/197027) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Anton Dosov --- .../query_string_input/query_bar_top_row.test.tsx | 15 +++++++++++++++ .../query_string_input/query_bar_top_row.tsx | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/plugins/unified_search/public/query_string_input/query_bar_top_row.test.tsx b/src/plugins/unified_search/public/query_string_input/query_bar_top_row.test.tsx index 9297b84de6dbc..9b95e58baac38 100644 --- a/src/plugins/unified_search/public/query_string_input/query_bar_top_row.test.tsx +++ b/src/plugins/unified_search/public/query_string_input/query_bar_top_row.test.tsx @@ -415,6 +415,21 @@ describe('SharingMetaFields', () => { `); }); + it('Should convert to absolute correctly', () => { + jest.useFakeTimers().setSystemTime(new Date('2024-10-21T10:19:31.254Z')); + + const from = 'now-1d/d'; + const to = 'now-1d/d'; + const component = ; + + expect(shallow(component)).toMatchInlineSnapshot(` +
+ `); + }); + it('Should render the component without data-shared-timefilter-duration if time is not set correctly', () => { const component = ( diff --git a/src/plugins/unified_search/public/query_string_input/query_bar_top_row.tsx b/src/plugins/unified_search/public/query_string_input/query_bar_top_row.tsx index 8321ca9130f54..4d4db4438d74d 100644 --- a/src/plugins/unified_search/public/query_string_input/query_bar_top_row.tsx +++ b/src/plugins/unified_search/public/query_string_input/query_bar_top_row.tsx @@ -209,7 +209,7 @@ export const SharingMetaFields = React.memo(function SharingMetaFields({ try { const dateRangePretty = usePrettyDuration({ timeFrom: toAbsoluteString(from), - timeTo: toAbsoluteString(to), + timeTo: toAbsoluteString(to, true), quickRanges: [], dateFormat, });