From b8dfa0449e21626716699060d6e1449c27299d6f Mon Sep 17 00:00:00 2001 From: Jacek Foremski <8006126+jacek-foremski@users.noreply.github.com> Date: Tue, 18 Dec 2018 16:44:47 +0100 Subject: [PATCH] EZP-29279: Fix value displayed by the Date Field Type being affected by browser time zone (#984) * EZP-29279: Fix value displayed by the Date Field Type being affected by browser time zone * fixup! EZP-29279: Fix value displayed by the Date Field Type being affected by browser time zone --- Resources/public/js/views/fields/ez-date-editview.js | 10 ++++++++-- Resources/public/js/views/fields/ez-date-view.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Resources/public/js/views/fields/ez-date-editview.js b/Resources/public/js/views/fields/ez-date-editview.js index 1bcc894bc..b42dc9287 100644 --- a/Resources/public/js/views/fields/ez-date-editview.js +++ b/Resources/public/js/views/fields/ez-date-editview.js @@ -74,10 +74,14 @@ YUI.add('ez-date-editview', function (Y) { * @protected */ _syncDateAttribute: function () { - var field = this.get('field'); + var field = this.get('field'), + date; if ( this._containsValidTimestamp() ) { - this._set('date', Y.Date.format(new Date(field.fieldValue.timestamp * 1000))); + date = new Date(field.fieldValue.timestamp * 1000); + + date.setTime(date.getTime() + date.getTimezoneOffset() * 60 * 1000); + this._set('date', Y.Date.format(date)); } }, @@ -260,6 +264,8 @@ YUI.add('ez-date-editview', function (Y) { } if ( this._containsValidTimestamp() ) { date = new Date(field.fieldValue.timestamp * 1000); + + date.setTime(date.getTime() + date.getTimezoneOffset() * 60 * 1000); } calendar = new Y.Calendar({ showPrevMonth: true, diff --git a/Resources/public/js/views/fields/ez-date-view.js b/Resources/public/js/views/fields/ez-date-view.js index b22d2369c..46d05a39c 100644 --- a/Resources/public/js/views/fields/ez-date-view.js +++ b/Resources/public/js/views/fields/ez-date-view.js @@ -48,6 +48,18 @@ YUI.add('ez-date-view', function (Y) { } return ''; }, + + /** + * Formats the date part of the date object + * + * @method _formatDate + * @protected + * @param {Date} date + * @return {String} + */ + _formatDate: function (date) { + return date.toLocaleDateString(undefined, {timeZone: 'UTC'}); + }, }); Y.eZ.FieldView.registerFieldView('ezdate', Y.eZ.DateView);