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

Handle timezone in publication fields (effective and expires) #1192

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cekk
Copy link
Member

@cekk cekk commented Aug 9, 2021

This could fix plone/volto#2597

The failing test is because also if i customize env var, i can't save a DateTime value in that field with the wanted timezone.

Anyone have an idea on how to fix it? @buchi ?

@cekk cekk requested review from buchi and tisto August 9, 2021 14:43
@mister-roboto
Copy link

@cekk thanks for creating this Pull Request and help improve Plone!

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass.

Whenever you feel that the pull request is ready to be tested, either start all jenkins jobs pull requests by yourself, or simply add a comment in this pull request stating:

@jenkins-plone-org please run jobs

With this simple comment all the jobs will be started automatically.

Happy hacking!

@tisto
Copy link
Sponsor Member

tisto commented Aug 24, 2021

@jenkins-plone-org please run jobs

2 similar comments
@tisto
Copy link
Sponsor Member

tisto commented Aug 31, 2021

@jenkins-plone-org please run jobs

@cekk
Copy link
Member Author

cekk commented Oct 26, 2021

@jenkins-plone-org please run jobs

@netlify
Copy link

netlify bot commented Apr 7, 2023

Deploy Preview for plone-restapi canceled.

Name Link
🔨 Latest commit 25df696
🔍 Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/65a003808f8b4200087d704b

@avoinea
Copy link
Sponsor Member

avoinea commented Apr 7, 2023

Holy mother of... this is here for 2 years and nobody took care of it? 😄

I can confirm @cekk 's conclusions from here plone/volto#2597 (comment)

How to test and reproduce:

  1. Start plone backend with TZ env
docker run -it --rm -p 8080:8080 -e TZ="Europe/Berlin" plone/plone-backend
  1. In Volto publish a News items with publishing date and time after a half an hour
  2. In Volto add a listing block showing all news before today
  3. The News should not be listed yet, but it is.
  4. Play with the Publishing Date until the News item disappear from the listing block
  5. Check the portal_catalog entry and you'll notice the EffectiveDate is actually UTC - 2 😱

is_publication_field = self.field.interface == IPublication
if is_publication_field:
# because IPublication datamanager strips timezones
tzinfo = pytz.timezone(default_timezone())
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

@cekk While this is way better than assuming UTC always, it can still have issues if the server has different timezone than the one from registry, UTC for example (the default behavior of plone/plone-backend Docker image).

And I think @sneridagh can confirm that their installations doesn't provide the TZ environment variable to docker containers, thus UTC by default. While the default timezone registry entry when creating a new Plone instance is Europe/Berlin.

How to test:

docker run -it --rm -p 8080:8080 -e SITE=Plone plone/plone-backend bash

git clone https://github.com/plone/plone.restapi.git
cd plone.restapi
git checkout handle_tz_in_publication_fields
cd /app
bin/pip install -e ./plone.restapi --no-deps
./docker-entrypoint.sh start

Now add a News Item with Effective Date via Volto and check portal_catalog entry.

@erral
Copy link
Sponsor Member

erral commented Aug 28, 2023

We have been hit by this too, and I can confirm that with this changes the original datetime as entered in Volto interface is correctly saved in Plone.

We configure our Zope instance passing the TZ = Europe/Madrid environment variable.

In all cases here, I have Europe/Madrid configured as a default timezone in Plone.

Item saved with the following datetime through Volto: 2023-08-28 10:00:00

Previous scenario (without this branch):

>>> news = app.Plone.komunikazioa.albisteak['albistea-2023-08-28-10-00-00']
>>> news
<FolderishNewsItem at /Plone/komunikazioa/albisteak/albistea-2023-08-28-10-00-00>
>>> value = news.effective()
>>> value
DateTime('2023/08/28 08:00:00 GMT+2')
>>> value = value.asdatetime()
>>> value
datetime.datetime(2023, 8, 28, 8, 0, tzinfo=<StaticTzInfo 'GMT+2'>)

Current scenario (with this branch)

>>> news = app.Plone.komunikazioa.albisteak['albistea-2023-08-28-11-00']
>>> news
<FolderishNewsItem at /Plone/komunikazioa/albisteak/albistea-2023-08-28-11-00>
>>> news.effective()
DateTime('2023/08/28 10:00:00 GMT+2')
>>> news.effective().asdatetime()
datetime.datetime(2023, 8, 28, 10, 0, tzinfo=<StaticTzInfo 'GMT+2'>)

I have made a test without adding the TZ environment variable in the instance configuration and the behavior is the following:

Previous scenario (without this branch)

>>> news = app.Plone.komunikazioa.albisteak['albistea-2023-08-28-12-00']
>>> news
<FolderishNewsItem at /Plone/komunikazioa/albisteak/albistea-2023-08-28-12-00>
>>> value = news.effective()
>>> value
DateTime('2023/08/28 08:00:00 GMT+2')
>>> value.asdatetime()
datetime.datetime(2023, 8, 28, 8, 0, tzinfo=<StaticTzInfo 'GMT+2'>)

Current scenario (with this branch):

>>> news = app.Plone.komunikazioa.albisteak['albistea-2023-08-28-12-00']
>>> newd
<FolderishNewsItem at /Plone/komunikazioa/albisteak/albistea-2023-08-28-12-00>
>>> value = news.effective()
>>> value
DateTime('2023/08/28 10:00:00 GMT+2')
>>> value = value.asdatetime()
>>> value
datetime.datetime(2023, 8, 28, 10, 0, tzinfo=<StaticTzInfo 'GMT+2'>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Wrong Time displayed in DateTimeWidget
5 participants