Skip to content

Commit

Permalink
Respect the user's timezone in the version preview and in CSV exports (
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-moser authored Jun 18, 2024
1 parent 2f20f5a commit a764725
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
5 changes: 4 additions & 1 deletion public/js/pimcore/asset/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ pimcore.asset.versions = Class.create({
var data = grid.getStore().getAt(rowIndex).data;

var versionId = data.id;
var url = Routing.generate('pimcore_admin_asset_showversion', {id: versionId});
var url = Routing.generate('pimcore_admin_asset_showversion', {
id: versionId,
userTimezone: getUserTimezone()
});
Ext.get(this.frameId).dom.src = url;
},

Expand Down
1 change: 1 addition & 0 deletions public/js/pimcore/element/helpers/gridColumnConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ pimcore.element.helpers.gridColumnConfig = {
this.exportParameters.initial = initial ? 1 : 0;
this.exportParameters.language = this.gridLanguage;
this.exportParameters.context = Ext.encode(this.context);
this.exportParameters.userTimezone = getUserTimezone();

Ext.Ajax.request({
url: this.exportProcessUrl,
Expand Down
4 changes: 4 additions & 0 deletions public/js/pimcore/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,10 @@ function htmlspecialchars (string, quoteStyle, charset, doubleEncode) {
return string
}

function getUserTimezone() {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
}

function dateToServerTimezone(date) {

let utcDate = new Date(date.toLocaleString('en-US', {
Expand Down
12 changes: 9 additions & 3 deletions public/js/pimcore/object/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ pimcore.object.versions = Class.create({

var selections = grid.getSelectionModel().getSelection();

var url = Routing.generate('pimcore_admin_dataobject_dataobject_diffversions', {from: selections[0].data.id, to: selections[1].data.id});
var url = Routing.generate('pimcore_admin_dataobject_dataobject_diffversions', {
from: selections[0].data.id,
to: selections[1].data.id,
userTimezone: getUserTimezone()
});
Ext.get(this.iframeId).dom.src = url;
}
},
Expand All @@ -211,8 +215,10 @@ pimcore.object.versions = Class.create({
var store = grid.getStore();
var data = store.getAt(rowIndex).data;
var versionId = data.id;

var url = Routing.generate('pimcore_admin_dataobject_dataobject_previewversion', {id: versionId});
var url = Routing.generate('pimcore_admin_dataobject_dataobject_previewversion', {
id: versionId,
userTimezone: getUserTimezone()
});
Ext.get(this.iframeId).dom.src = url;
},

Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Admin/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,8 @@ public function showVersionAction(Request $request): Response
}
}

Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone'));

$loader = \Pimcore::getContainer()->get('pimcore.implementation_loader.asset.metadata.data');

return $this->render(
Expand Down
5 changes: 5 additions & 0 deletions src/Controller/Admin/DataObject/DataObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,9 @@ public function previewVersionAction(Request $request): Response
$object = $version?->loadData();

if ($object) {

Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone'));

if (method_exists($object, 'getLocalizedFields')) {
/** @var DataObject\Localizedfield $localizedFields */
$localizedFields = $object->getLocalizedFields();
Expand Down Expand Up @@ -1651,6 +1654,8 @@ public function diffVersionsAction(Request $request, int $from, int $to): Respon
throw $this->createNotFoundException('Version with id [' . $id2 . "] doesn't exist");
}

Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone'));

if (method_exists($object2, 'getLocalizedFields')) {
/** @var DataObject\Localizedfield $localizedFields2 */
$localizedFields2 = $object2->getLocalizedFields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ public function doExportAction(
$settings = json_decode($request->get('settings'), true);
$delimiter = $settings['delimiter'] ?? ';';
$header = $settings['header'] ?? 'title';
Tool\UserTimezone::setUserTimezone($request->request->get('userTimezone'));

$allParams = array_merge($request->request->all(), $request->query->all());

Expand Down

0 comments on commit a764725

Please sign in to comment.