C5-8.3.2: how to handle DateTime between versions 8.0.0 and 8.3.2?
Permalink
The translate() method of the date_time helper returns a date-time string which is saved in the database:
http://documentation.concrete5.org/api/8.3.2/Concrete/Core/Form/Ser...
The problem is the time is saved in v8.0.0 based on the UTC but it's saved in v8.3.2 based on the user time.
To develop a package which will run without errors from Concrete5 versions 8.0.0 to 8.3.2, how can I make sure the date-time string is always displayed in the correct user time zone? How can I handle the date-time string saving and view so that they are correct regardless of the Concrete5 version? Is it possible at all?
Thank you.
public function save($args) { $args['valid_until'] = $this->app->make('helper/form/date_time')->translate('valid_until', null); parent::save($args); }
http://documentation.concrete5.org/api/8.3.2/Concrete/Core/Form/Ser...
The problem is the time is saved in v8.0.0 based on the UTC but it's saved in v8.3.2 based on the user time.
To develop a package which will run without errors from Concrete5 versions 8.0.0 to 8.3.2, how can I make sure the date-time string is always displayed in the correct user time zone? How can I handle the date-time string saving and view so that they are correct regardless of the Concrete5 version? Is it possible at all?
Thank you.
The following seems to work:
with the following test passing with different time zones on different servers:
Result:
$dh = $app->make('helper/date'); $fdt = $dh->formatDateTime($valid_until, true, true, 'user'); $fc = $dh->formatCustom("Y/m/d H:i:s", $valid_until, 'user', 'system'); if (version_compare(\Config::get('concrete.version_installed'), '8.1.0', '<')) { $td = strtotime($fc) - time(); } else { $td = strtotime($valid_until) - time(); }
with the following test passing with different time zones on different servers:
Result:
2018-05-24 14:00:00 2018/05/24 14:00:00 2018-05-24 14:00:00 May 25, 2018, 1:00:00 AM 2018/05/25 01:00:00 2018/05/25 00:17:45 42.25
I am selecting 2018-05-24 23:00 with the DateTime picker, 2018-05-24 15:00:00 is saved in the database.
I tried the following:
and I get the following result:
As you can see results No 1, 2, 4, 5 are what I need for the first string. The last result has the right date format but wrong time, it must be 23:00. If I get the right time format above 23:00, the date is in Russian, it must simply be 2018/05/24.
What else can I try?