Please help about last modified date and time

Hi Everyone
I have installed a Plone 5.0.8 on ubuntu server .

When I posted or modified the news, the last modified date was not a local time but a delay of 14 hours
How can I fix this as local time?

Can anyone help?

Thanks!!

Ethentu

Is the server in UTC (and up to date), and did you the correct timezone in Plone?

Hi Jaroel
Thank you for your reply
I check ubuntu server timezone is correct and plone Date and Time Settings is Asia/Taipei.
But post last modified date was not a local time and always delay 14 hours.
Local time: Thu 2018-01-04 09:56:03 CST
Universal time: Thu 2018-01-04 01:56:03 UTC
RTC time: Thu 2018-01-04 02:03:20
Time zone: Asia/Taipei (CST, +0800)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

EThentu

What is the server timezone set to?

Hi T.Kim Nguyen,
The server timezone is set to Asis/Taipei
Local time is now: Thu Jan 4 14:28:23 CST 2018.
Universal Time is now: Thu Jan 4 06:28:23 UTC 2018.
ubuntu_servertime

Thanks

Ethen

cat /etc/timezone ?

You can also set the timezone per user or per process with the TZ environment variable.

LC_ALL="en_US.UTF-8" TZ="UTC" date
Thu Jan  4 15:20:53 UTC 2018

LC_ALL="en_US.UTF-8" TZ="Asia/Taipei" date
Thu Jan  4 23:20:58 CST 2018

You can specifically set the TZ environment variable for your instance.

You need to edit your buildout and in your [instance] part add it in the environment-vars option, something like this:

[instance]
...
environment-vars =
TZ Asia/Taipei

You can check this stackoverflow question for more reference: https://stackoverflow.com/questions/14983923/plone-4-2-4-shows-incorrect-local-time-3-5-hours-ahead

Check that your zope.conf does NOT contain something like that:

<environment>
TZ UTC

if yes delete the 'TZ UTC' part, save the file (take care to preserve owner and group) and restart your instance(s) (if you have several instances you have several zope.conf files to check and edit of course)

After some thinking I am not sure this is correct. I tried this because I compared my test install done with Ansible Plone (problem) with a test install done with the stand-alone installer (no problem). In the stand alone installer there is no TZ variable in the zope.conf, and no date problem.
However, things are not so simple. When there is no TZ variable in the zope.conf environment, dates are written to the Plone database (the Zodb) in local format. So in both cases (Ansible Plone install and standalone installer) the time format set up in the control panel has no effect, the value is displayed as it is in the Zodb. With my Ansible install the value displayed is wrong, in the standalone installer it seems correct.

But it does NOT seem right to me that the date values written in the DB are in local format.
I have not seen any indications in the docs about that, but I would not never design a system to manage dates across users of different time zones with values written in local format in the db, the proper way seems obviously to write in an universal format and to display according to user preferences.

So the aforementioned 'fix' may be a configuration mistake that hides a bug without fixing it.

Hi Mikel Larreategi,
Thank you for your reply .
After add TZ Asia/Taipei into instance buildout.cfg and base.cfg and restart instance.
I post a test news but the situation remains the same.

:Is my configure wrong?

Thank you

Ethenbuildoutcfg
basecfg
testpost

After modifying the buildout, you need to run the buildout and then restart the instance.

Am I misunderstanding ? I would think you just needs to set the timezone in plone control panel

you are not misunderstanding, there are cases where your suggestion is just not working...not for the byline at least.

Hi Mikel Larreategi,

Thank for your help.
After run the buildout. Appears Unused options for buildout: 'environment-vars'
I tried to search the relevant documents at this time is still unable to solve this problem.
unusedoption

Ethen

That must mean that you put it in the wrong place. It must go under the [instance] part on your buildout.cfg file.

Anyway, with the screenshots you provided it looks that it's in the correct place, did you try to restart the instance after running buildout and checking that the datetimes are correct?

Hi Mikel Larreategi,
I reinstalled Plone 5.0.0 for cluster mode.
The previously installed mode is standalone mode.
I edit buildout.cfg and [instance] part add environment-vars = TZ Asia/Taipei.
then run the buildout and restart instance.
zeocluster

I post a test news the last modified time remains delay.
local time

Thank you

Ethen

In addition, I found that management interface last modified is not local time. Is this normal?

I don't know what else to say, when we had problems with timezones we have changed the value of the TZ environment for the variable and things were fixed.

well, after some looking at code and docs (I am not a Plone contributor remember that), I think that your predicament is the result of a decision taken with Plone 5 to establish a timezone management on the client side using the javascript library moment.js. Unfortunately this has consequences on templates and some (many) have not been updated. I think the reason is that for each template the developer needs to lookup the time zone for the server/user preference and send the correct offset to the client. This is not easy to do I guess.
The advice you have received is to it the Plone 4 way, that is, switch the local server timezone. I don't know why this has not worked for you (and well I don't care as this is not the way forward)
My 2 cents is that a stopgap solution would be to send the date as an iso date and rely for now on the date settings in the client (maybe this is the plan anyway ? but I don't think so because why add timezone settings to the Plone interface)
So in your case, the strict minimum would be the Plone listing:

  1. buildout-cachedbg/eggs/plone.app.contenttypes-1.2.23-py2.7.egg/plone/app/contenttypes/browser/templates/listing.pt
    Edit (after backup of the listing.pt file !) so:
--- listing.pt.ori	2017-06-09 19:19:03.000000000 +0200
+++ listing.pt	2018-01-09 13:35:29.477445487 +0100
@@ -85,7 +85,7 @@
                           <tal:modified condition="python: item_type != 'Event'">
                             &mdash;
                             <tal:mod i18n:translate="box_last_modified">last modified</tal:mod>
-                            <span tal:replace="python:view.toLocalizedTime(item_modified,long_format=1)">
+                            <span class="pat-moment" data-pat-moment="format:LLL;" tal:content="python:obj.modified().ISO8601()">
                               August 16, 2001 at 23:35:59
                             </span>
                           </tal:modified>

take care about user and group ownership if this applies to your computer, then restart your Plone instance (of hit Ctrl F5 in the browser if you are running in development mode aka bin/instance fg)
If things go pear-shaped restore the file from backup and restart Plone.
If the date is displayed 'correctly' (the hour should be in accord to the time zone of your computer, note that the local formatting will still be controlled by the Plone language setting - if you change the computer time zone usually the browser needs to be restarted), then you can try to follow the more involved step, the 'byline' (this is the part displayed below the title when a particular page or object is displayed)

  1. the byline
    beware, this first change is to python code. It need a restart of Plone (even in development mode) and if you don't know that, Python is very sensitive, a single space missing or in excess can stop Plone to start. So backup the file first, try it (lookup Gnu Patch, if you have to use a text editor use cut & paste and if you want absolutely to type the instruction take care)
    change to plone.app.layout-2.5.23-py2.7.egg/plone/app/layout/viewlets/content.py
--- content.py.ori	2017-03-16 23:09:18.000000000 +0100
+++ content.py	2018-01-09 14:32:15.749755015 +0100
@@ -136,6 +136,12 @@
         return util.ulocalized_time(time, long_format, time_only, self.context,
                                     domain='plonelocales')
 
+    def mod_date(self):
+        date = self.context.modified()
+        x = DateTime(date).ISO8601()
+        print(x)
+        return x
+
     def pub_date(self):
         """Return object effective date.
 

then the second change, to change to plone.app.layout-2.5.23-py2.7.egg/plone/app/layout/viewlets/document_byline.pt (save the file first)

--- document_byline.pt.ori	2018-01-02 10:26:43.331683077 +0100
+++ document_byline.pt	2018-01-09 00:28:14.270921505 +0100
@@ -28,13 +28,13 @@
   </tal:creator>
 
   <tal:dates define="published view/pub_date;
-                     modified context/ModificationDate">
+                     modified view/mod_date">
   <span class="documentPublished"
         tal:condition="published">
     <span i18n:translate="box_published">
       published
     </span>
-    <span class="pat-moment" data-pat-moment="format:DD MM YYYY;"
+    <span class="pat-moment" data-pat-moment="format:LLL;"
           tal:content="published">
       Published
     </span><tal:sep condition="modified">,</tal:sep>
@@ -45,7 +45,7 @@
     <span i18n:translate="box_last_modified">
       last modified
     </span>
-    <span class="pat-moment" data-pat-moment="format:DD MM YYYY;"
+    <span class="pat-moment" data-pat-moment="format:LLL;"
           tal:content="modified">
       Modified
     </span>

HTH

Hi GP54321
Thank you very much for your help.
Although I still don't know why "environment-vars = TZ Asia / Taipei" run buildout not working.
After changing these three files, the last modified time has been synchronized with the local time.
timecorrect

server setting the time
timezonecentra

If I change the server time the last modified date will change as well.
lastmotime
taipritime

Thank you for your solution

Ethen