Skip to content

Fix date attributes without timezone support when server timezone is configured #565

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

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions public/js/pimcore/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1794,10 +1794,10 @@ function htmlspecialchars (string, quoteStyle, charset, doubleEncode) {
return string
}

function dateToUTC(date) {
function dateToServerTimezone(date) {

let utcDate = new Date(date.toLocaleString('en-US', {
timeZone: 'UTC'
timeZone: pimcore.settings.timezone ?? 'UTC'
}));

let diff = date.getTime() - utcDate.getTime();
Expand Down
13 changes: 13 additions & 0 deletions public/js/pimcore/object/tags/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ pimcore.object.tags.date = Class.create(pimcore.object.tags.abstract, {
} else {
let timestamp = intval(value) * 1000;
date = new Date(timestamp);

if (!this.isRespectTimezone()) {
date = dateToServerTimezone(date);
}
}

return Ext.Date.format(date, "Y-m-d");
Expand Down Expand Up @@ -92,6 +96,11 @@ pimcore.object.tags.date = Class.create(pimcore.object.tags.abstract, {

if (this.data) {
var tmpDate = new Date(intval(this.data) * 1000);

if (!this.isRespectTimezone()) {
tmpDate = dateToServerTimezone(tmpDate);
}

date.value = tmpDate;
}

Expand Down Expand Up @@ -157,6 +166,10 @@ pimcore.object.tags.date = Class.create(pimcore.object.tags.abstract, {
}

return false;
},

isRespectTimezone: function() {
return this.fieldConfig.columnType !== "date";
}

});
5 changes: 2 additions & 3 deletions public/js/pimcore/object/tags/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pimcore.object.tags.datetime = Class.create(pimcore.object.tags.abstract, {
date = new Date(timestamp);

if (!this.isRespectTimezone()) {
date = dateToUTC(date);
date = dateToServerTimezone(date);
}
}

Expand Down Expand Up @@ -90,8 +90,7 @@ pimcore.object.tags.datetime = Class.create(pimcore.object.tags.abstract, {
var tmpDate = new Date(intval(this.data) * 1000);

if (!this.isRespectTimezone()) {
debugger;
tmpDate = dateToUTC(tmpDate);
tmpDate = dateToServerTimezone(tmpDate);
}

date.value = tmpDate;
Expand Down
Loading