Skip to content

Commit

Permalink
Fix wrong date on a header of a report when generated from relative d…
Browse files Browse the repository at this point in the history
…ate (#197027)

## Summary

close #148224

There was an issue when generating a PDF report from a dashboard with
relative date with time range display in the header of the report. Note:
there data was displayed correctly, the issue was only with the date in
the header:

Dashboard: 

![Screenshot 2024-10-21 at 12 33
21](https://github.com/user-attachments/assets/2bd09099-5375-447a-b829-49671cc3614f)


Report before the fix 👎 

![Screenshot 2024-10-21 at 12 35
19](https://github.com/user-attachments/assets/e114f6f1-ba46-4bec-bf97-f175d18dbcd1)

Report after the fix 👍 


![Screenshot 2024-10-21 at 12 34
17](https://github.com/user-attachments/assets/06fd2b4e-74af-4994-bf48-65903394f91e)
  • Loading branch information
Dosant authored Oct 22, 2024
1 parent 5c51e78 commit 0ce828c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down

0 comments on commit 0ce828c

Please sign in to comment.