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

Folder contents properties action does not set tzinfo for dates #178

Open
csanahuja opened this issue Apr 29, 2019 · 0 comments
Open

Folder contents properties action does not set tzinfo for dates #178

csanahuja opened this issue Apr 29, 2019 · 0 comments

Comments

@csanahuja
Copy link

BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)

What I did:

  1. Create a document and publish it.
  2. Change publish/effective date editing the document.
  3. Change the same date in the folder_contents properties action button

What I expect to happen:

Step 2 and 3 should set the date the same way

What actually happened:

Step 2 saves the timezone. Step 3 does not.

What version of Plone/ Addons I am using:

Clean installation

Plone 5.1.4 (5114)
CMF 2.2.12
Zope 2.13.27
Python 2.7.14
PIL 5.3.0 (Pillow)

More info:

Starting the client in debug mode:

Step 2 output:

>>> app['filesystem']['site'][document'].effective_date
DateTime('2019/04/30 10:00:00 GMT+2')

Step 3 output

>>> app['filesystem']['site'][document'].effective_date
DateTime('2019/04/29 10:00:00 GMT+0')

Making some testing with DateTime I got this results:

>>> from DateTime import DateTime
>>> from datetime import datetime
>>> # Creating DateTime w/o param sets GMT
>>> DateTime()
DateTime('2019/04/29 10:24:50.212822 GMT+2')
>>> # Creating DateTime with string does not set GMT (I guess we need to pass the GMT as part of the string)
>>> DateTime('2019-04-29 10:00')
DateTime('2019/04/29 10:00:00 GMT+0')
>>> # Creating DateTime with datetime instance sets GMT
>>> DateTime(datetime.strptime('2019-04-29 10:00:00', '%Y-%m-%d %H:%M:%S'))
DateTime('2019/04/29 10:00:00 GMT+2')

So my workaround was this:

# Need to import datetime
if self.effectiveDate and hasattr(obj, 'effective_date'):
    self.effectiveDate = datetime.strptime(self.effectiveDate, '%Y-%m-%d %H:%M')
    obj.effective_date = DateTime(self.effectiveDate)

The same applies to expiration date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant