Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
EZP-29279: Fix value displayed by the Date Field Type being affected …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jacek-foremski authored and andrerom committed Dec 18, 2018
1 parent fc7f1fe commit b8dfa04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Resources/public/js/views/fields/ez-date-editview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
},

Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions Resources/public/js/views/fields/ez-date-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b8dfa04

Please # to comment.