[8.16] Fix wrong date on a header of a report when generated from relative date (#197027) (#197203)

# Backport

This will backport the following commits from `main` to `8.16`:
- [Fix wrong date on a header of a report when generated from relative
date (#197027)](https://github.com/elastic/kibana/pull/197027)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Anton
Dosov","email":"anton.dosov@elastic.co"},"sourceCommit":{"committedDate":"2024-10-22T10:23:37Z","message":"Fix
wrong date on a header of a report when generated from relative date
(#197027)\n\n## Summary\r\n\r\nclose
https://github.com/elastic/kibana/issues/148224\r\n\r\nThere was an
issue when generating a PDF report from a dashboard with\r\nrelative
date with time range display in the header of the report. Note:\r\nthere
data was displayed correctly, the issue was only with the date in\r\nthe
header:\r\n\r\nDashboard: \r\n\r\n![Screenshot 2024-10-21 at 12
33\r\n21](https://github.com/user-attachments/assets/2bd09099-5375-447a-b829-49671cc3614f)\r\n\r\n\r\nReport
before the fix 👎 \r\n\r\n![Screenshot 2024-10-21 at 12
35\r\n19](https://github.com/user-attachments/assets/e114f6f1-ba46-4bec-bf97-f175d18dbcd1)\r\n\r\nReport
after the fix 👍 \r\n\r\n\r\n![Screenshot 2024-10-21 at 12
34\r\n17](https://github.com/user-attachments/assets/06fd2b4e-74af-4994-bf48-65903394f91e)","sha":"0ce828c470c43434343101ed22b45863d3ed68e9","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","SharedUX/fix-it-week","Team:SharedUX","backport:prev-major","Feature:Reporting:Screenshot"],"title":"Fix
wrong date on a header of a report when generated from relative
date","number":197027,"url":"https://github.com/elastic/kibana/pull/197027","mergeCommit":{"message":"Fix
wrong date on a header of a report when generated from relative date
(#197027)\n\n## Summary\r\n\r\nclose
https://github.com/elastic/kibana/issues/148224\r\n\r\nThere was an
issue when generating a PDF report from a dashboard with\r\nrelative
date with time range display in the header of the report. Note:\r\nthere
data was displayed correctly, the issue was only with the date in\r\nthe
header:\r\n\r\nDashboard: \r\n\r\n![Screenshot 2024-10-21 at 12
33\r\n21](https://github.com/user-attachments/assets/2bd09099-5375-447a-b829-49671cc3614f)\r\n\r\n\r\nReport
before the fix 👎 \r\n\r\n![Screenshot 2024-10-21 at 12
35\r\n19](https://github.com/user-attachments/assets/e114f6f1-ba46-4bec-bf97-f175d18dbcd1)\r\n\r\nReport
after the fix 👍 \r\n\r\n\r\n![Screenshot 2024-10-21 at 12
34\r\n17](https://github.com/user-attachments/assets/06fd2b4e-74af-4994-bf48-65903394f91e)","sha":"0ce828c470c43434343101ed22b45863d3ed68e9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197027","number":197027,"mergeCommit":{"message":"Fix
wrong date on a header of a report when generated from relative date
(#197027)\n\n## Summary\r\n\r\nclose
https://github.com/elastic/kibana/issues/148224\r\n\r\nThere was an
issue when generating a PDF report from a dashboard with\r\nrelative
date with time range display in the header of the report. Note:\r\nthere
data was displayed correctly, the issue was only with the date in\r\nthe
header:\r\n\r\nDashboard: \r\n\r\n![Screenshot 2024-10-21 at 12
33\r\n21](https://github.com/user-attachments/assets/2bd09099-5375-447a-b829-49671cc3614f)\r\n\r\n\r\nReport
before the fix 👎 \r\n\r\n![Screenshot 2024-10-21 at 12
35\r\n19](https://github.com/user-attachments/assets/e114f6f1-ba46-4bec-bf97-f175d18dbcd1)\r\n\r\nReport
after the fix 👍 \r\n\r\n\r\n![Screenshot 2024-10-21 at 12
34\r\n17](https://github.com/user-attachments/assets/06fd2b4e-74af-4994-bf48-65903394f91e)","sha":"0ce828c470c43434343101ed22b45863d3ed68e9"}}]}]
BACKPORT-->

Co-authored-by: Anton Dosov <anton.dosov@elastic.co>
This commit is contained in:
Kibana Machine 2024-10-22 23:08:00 +11:00 committed by GitHub
parent 27e881576e
commit c45c7d64dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -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 = <SharingMetaFields from={from} to={to} dateFormat="MMM D, YYYY @ HH:mm:ss" />;
expect(shallow(component)).toMatchInlineSnapshot(`
<div
data-shared-timefilter-duration="Oct 20, 2024 @ 00:00:00 to Oct 20, 2024 @ 23:59:59"
data-test-subj="dataSharedTimefilterDuration"
/>
`);
});
it('Should render the component without data-shared-timefilter-duration if time is not set correctly', () => {
const component = (
<SharingMetaFields from="boom" to="now" dateFormat="MMM D, YYYY @ HH:mm:ss.SSS" />

View file

@ -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,
});