-
Notifications
You must be signed in to change notification settings - Fork 5
Store Date as UTC and show it in server time zone #57
Conversation
{ | ||
if ((int) $result->created_date) | ||
{ | ||
$created_date = new Date($result->created_date); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what for a timezone is $result->created_date?
@@ -336,10 +336,8 @@ private function saveOverrides($pks) | |||
{ | |||
$insertQuery->clear('values'); | |||
|
|||
$tz = new \DateTimeZone(Factory::getApplication()->get('offset')); | |||
$date = new Date('now'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laoneo If I am right the timezone of $date = new Date('now');
is UTC as this is the default time zone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so too.
@astridx Can we do this without creating a new loop ? Mean, here gsoc18_override_management/administrator/components/com_templates/Model/TemplateModel.php Line 202 in 2c393ff
|
// Get timezone for converting the created and modified date. | ||
$tz = new \DateTimeZone(Factory::getApplication()->get('offset')); | ||
|
||
foreach ($results as $result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop
@Anu1601CS I have put the code in the already existing loop. @laoneo Is the handling of the date now like it should be done in Joomla? |
if ((int) $pk->created_date) | ||
{ | ||
$created_date = new Date($pk->created_date); | ||
$created_date->setTimezone($tz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These setTimezone
calls should not be necessary. Instantiating a new Joomla\CMS\Date\Date
object internally converts the timestamp to UTC.
{ | ||
$created_date = new Date($pk->created_date); | ||
$created_date->setTimezone($tz); | ||
$pk->created_date = $created_date->toSql(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toSql(true)
means you're getting the timestamp in the correct SQL format but localized, so this is converting from UTC to whatever timezone you're setting above.
Look at the check
methods of various Joomla\CMS\Table\Table
subclasses for how created and modified dates are handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbabker Thank you for your help. But if I do not set the timezone, the date will be displayed in UTC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, missed this wasn't a save operation.
The timezone shouldn't be normalized in models. This should be done in views/layouts. So you should use the JHtml::date()
helper (as is done elsewhere in core) for this, as that will adjust the timezone for the user's configuration.
I moved normalizing of the timezone to the view |
@dgrammatiko Javascript test fails with. ReferenceError: customElements is not defined |
@@ -57,13 +57,15 @@ | |||
<a class="hasTooltip" href="<?php echo Route::_('index.php?option=com_templates&view=template&id=' . (int) $value->extension_id . '&file=' . $value->hash_id); ?>" title="<?php echo Text::_('JACTION_EDIT'); ?>"><?php echo base64_decode($value->hash_id); ?></a> | |||
</td> | |||
<td> | |||
<?php echo $value->created_date; ?> | |||
<?php $created_date = $value->created_date; ?> | |||
<?php echo $created_date > 0 ? HTMLHelper::_('date', $created_date, 'Y-m-d H:i:s') : '-'; ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are language constants for date formats. I'm not sure but the custom field is using them.
Now I use language constants for date format. |
@Anu1601CS the js tests should be ok for now |
Thanks. |
@astridx Thank you very much :) |
Thanks. And now I understand why we store date in UTC. Up to know this was not clear to me. (I even found this unnecessary work to store a value in UTC just to convert the value back to the time zone later).
I hope I understood this right. @laoneo Is everything in this repo correct again? I mean, are all issues you see here are now OK: #52 (comment) By the way: Is there a documentation about that? I only found: https://docs.joomla.org/How_to_use_JDate what is not very detailed .... |
Yes, that's the way to go with dates, always UTC. |
* Load correct core files of override files (#2) Start implements loadcorefile() in administrator/components/com_templates/Model/TemplateModel.php * CS (#3) Coding Standards * codingstandards * codingstandards (#4) * Test (#6) Phase 2 (2 part) Mechanism to find correct core file and implementation. * Remove Notice: Only available for html-folder * Remove Warning if core file not found (#11) Thanks. So one part of the issue #12 is done. * Implement the diff view in template manager Implement the diff view in template manager * coding standard (#17) * fix diff (#18) Fix bug in path in case of administrator template override. Fix bug in path in case of administrator template override. * Notification after update and TEST (#16) Find changed files of overridden files and show message. * coding standard (#21) * correction * correction (#26) * Correcthtmlpath (#27) * correction * change oldhtml to newhtml * List of updated override files. (#30) * addcss (#34) * Final Product (#39) Core and Diff view Updated override history list. Quick icon notification plugin. Override control plugin. * save 3 lines :) * New feature show status. (#47) show status in com_template view templates * link * corrected namespace * Button to Switch (#35) * wip add Switcher * wip style switcher * wip style switch make inline and change on off text * wip start with js * wip js * wip delete buttons and make js more robust * wip save to storage * wip delete old code * wip * wip lint * wip css * set default value for switcher * wip make switcher blue * wip * wip * build * correct names * create new functions * fist test code * use onchange * undo installer.min.js * add forgotten new line at the end of css file * correct align * correct compare.es6 - only deleted the toggle part * correct compare.js - only deleted the toggle part * wip * reduce timeout * wrap in funcitons * wip * add use strict to both js-files(compare and toggle) * add the timeout value of 500 again, because 200 are not enought in my case * use css class 'active' for toggle views * add strict * time out for editor * wip * improvments use newActive and switch * correction * width of switcher-spans * correct align * do not use global * wip * removed timeouts * JTEXT to TEXT * forgotton last line * deleted duplicated comments * css fix align * use unnamed functions in es6 * Sql files for fix database (#50) * sql files for database fix * delete space * Suggestion for displaying Dates in view updates files (#52) Correct Dates and do not use date of file any more * Store Date as UTC and show it in server time zone (#57) * modified and created date are created and stored in UTC * convert dates for displaying in model * spar a loop * normalize timezone in view * use language constants for dateformat * JToolbarHelper to ToolbarHelper * CS * namespace * plural * name * clean * text * fx * sin * files * s * Suggestion for language strings (#60) * language strings * correct typo * delete media folder plg_quickicon * add folder plg_quickicon to build/media_src * delete files in media folder * Move media folder - System (#66) * multi * cs * delete files in media folder for joomla toolbar (#67) * Fix button switchers style. (#70) * button * CS * changed uitab.addTab for updated files * Bring back core.js changes. (#69) * core.js * const * fix * form * core * hound * CS * scopr * grid * alpha * cs * lang * only override file * lang * override lang installer * Cs * sub * Update list of core extensions (#71) * Language changes (#76) * update * Update en-GB.com_templates.ini * override JLIB_HTML_PUBLISH_ITEM this is the hover text on the publish icon in the list of files * Change icon (#74) change the icon to use an outline for more consistency * lang * not core (#75) * not core * Update en-GB.plg_installer_override.ini * namespace * cs * Updated files (#82) * Update default_updated_files.php * Update en-GB.com_templates.ini * Update en-GB.com_templates.ini (#81) * Update en-GB.plg_quickicon_overridecheck.ini (#80) * Update en-GB.plg_quickicon_overridecheck.ini (#79) * remove space (#78) * Update en-GB.plg_quickicon_overridecheck.ini * Update en-GB.plg_quickicon_overridecheck.sys.ini * remove hardcoded id * null get function * state * clean * More changes "core" to "original" (#85) * cs * update * plural
Pull Request for Issue #52 (comment).
Summary of Changes
The values for modified and created date are stored in UTC, but shown in server time zone.
![global configuration test administration](https://user-images.githubusercontent.com/9974686/43251296-d8d51688-90bf-11e8-9242-7b761b31c32f.png)
![templates customise cassiopeia test administration 4](https://user-images.githubusercontent.com/9974686/43251297-d8f41ea2-90bf-11e8-93b9-223052539907.png)
![global configuration test administration 1](https://user-images.githubusercontent.com/9974686/43251298-d910b684-90bf-11e8-9c57-21469969066e.png)
![templates customise cassiopeia test administration 5](https://user-images.githubusercontent.com/9974686/43251299-d92c4cd2-90bf-11e8-84a3-f8eaef3c347d.png)
If your server time zone is Australia
you see this time:
If your server time zone is in Europe
you see this time:
For Europe you see in the view this values:
![templates customise cassiopeia test administration 6](https://user-images.githubusercontent.com/9974686/43251300-d947cee4-90bf-11e8-940c-6242939d9374.png)
![localhost localhost joomla_db a_template_overrides phpmyadmin 4 5 4 1deb2ubuntu2](https://user-images.githubusercontent.com/9974686/43251302-d964eff6-90bf-11e8-874d-ffb167ae09b3.png)
In the database the UTC values are stored