Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdf: fix picasso rendering in other timezones than Europe/Zurich #4329

Merged
merged 6 commits into from Dec 29, 2023

Conversation

BacLuc
Copy link
Contributor

@BacLuc BacLuc commented Dec 26, 2023

GRGR Picasso in Europe/Zurich GRGR Picasso in Pacific/Tongatapu
grafik grafik
GRGR-picasso-pdf_europe_zuerich.pdf GRGR_tongatonga.pdf

Some time ago i detected that the pdf tests yielded another snapshot in the docker container than when ran locally.
The scary part was that some ScheduleEntries were not displayed.
After a lot of digging a could pin it to the wrong usage of timestampUtcString and utcStringToTimestamp.

In print it was no problem, because there our containers ran anyway in UTC.
But in pdf this is a problem because we use the browser timezone.
Because we don't use vCalendar anymore in print and pdf, we don't need the hack to convert UTC strings into timestamps which represent the same (numeric) time in the local timezone.

The refactoring is done step by step by first reproducing the problem in the test, and then refactoring it.
Finally dateHelperVCalendar.js is moved to the frontend, that we don't reuse it anymore where we don't need it.

It's best to review the commits one by one.

Superseeds #4317

According to comment #4317 (comment)

A simple way to reproduce it is to set the TZ variable in the e2e container, and generate the picasso there.

  e2e:
    image: cypress/included:13.6.1
    profiles: ['e2e']
    container_name: 'ecamp3-e2e'
    environment:
      - DISPLAY
      - TZ=Pacific/Tongatapu #add this line

The frontend seems to work in this timezone, but i could not yet produce a test why.

This allows to test if the different timezones render the same snapshot.
It also makes it easier to review the diff, because the diff only applies to one snapshot.
Else if a new snapshot is added or some parts move, the diff is difficult to read.
This allows to run some tests in different timezones.
(if dayjs.tz is used instead of dayjs)
Also add jsdoc to the export, that we know that the utc and the tz property exist.
To show that it fails.
Use the .tz variant in dateHelperVCalendar.js that it is possible to change tz at runtime.
@BacLuc BacLuc added the deploy! Creates a feature branch deployment for this PR label Dec 26, 2023
Copy link

github-actions bot commented Dec 26, 2023

Feature branch deployment currently inactive.

If the PR is still open, you can add the deploy! label to this PR to trigger a feature branch deployment.

@BacLuc BacLuc changed the title pdf: fix rendering in other timezones than Europe/Zurich pdf: fix picasso rendering in other timezones than Europe/Zurich Dec 26, 2023
Copy link
Member

@carlobeltrame carlobeltrame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for debugging this!

)
})
}

/**
* Calculates the visible day start timestamp
* @param day a day object of the api
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe keep the prose descriptions from before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@usu usu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks

@@ -312,13 +329,13 @@ export function positionStyles(scheduleEntries, day, times) {
const left = leftAndWidth[scheduleEntry.id]?.left || 0
const width = leftAndWidth[scheduleEntry.id]?.width || 0
const top = positionPercentage(
utcStringToTimestamp(scheduleEntry.start) - utcStringToTimestamp(day.start),
dayjs.utc(scheduleEntry.start).valueOf() - dayjs.utc(day.start).valueOf(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of resorting to valueOf(), we could also use the the diff function:

dayjs.utc(scheduleEntry.start).diff( dayjs.utc(day.start), 'hours', true)

Then we get the difference in hours directly and don't need to divide by (3600.0 * 1000) again within positionPercentage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but i will leave that for another PR.

times
)
const bottom =
100 -
positionPercentage(
utcStringToTimestamp(scheduleEntry.end) - utcStringToTimestamp(day.start),
dayjs.utc(scheduleEntry.end).valueOf() - dayjs.utc(day.start).valueOf(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but i will leave that for another PR.


dayjs.extend(utc)
dayjs.extend(timezone)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really use this extension? Everything should be done with utc now, shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, but it makes it easier to always use the dayjs.tz object which uses the changed timezone instead of the dayjs object.
so i would leave it here.

In the picasso render logic in pdf and in print, we can use the utc dayjs objects directly, instead
of converting them to the timestamps which represent the same time in the local timezone.
This fixes the render bugs of the picasso in the pdf module if you render it in another timezone.
Changed functions:
- positionStyles: only used in pdf and print
- filterScheduleEntriesByDay: ony used in pdf and print

Also remove the other usages in pdf (DayColumn) and print (CalendarDay).
This was only needed to run the tests in multiple timezones.
Now this is not needed anymore.
(in a later pr we may export dayjs.tz instead of the dayjs object
which does not allow to change the timezone between tests).
That nobody has the idea to reuse it in pdf or print.
We only need to calculate a timestamp representing the DateTime
received in UTC as the same DateTime in the local timezone.
@BacLuc BacLuc added this pull request to the merge queue Dec 29, 2023
Merged via the queue into ecamp:devel with commit 9efc85f Dec 29, 2023
32 checks passed
@BacLuc BacLuc deleted the fix-pdf-in-other-timezones branch December 29, 2023 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy! Creates a feature branch deployment for this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants