Skip to content
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

[FIX] web: date field in calendar no tz issue #32795

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions addons/web/static/src/js/views/calendar/calendar_model.js
Expand Up @@ -15,7 +15,17 @@ var scales = [
'month'
];

function dateToServer (date) {
/**
* Transform moment object in format expected by the server
*
* @param {Moment} date Date in UTC
* @param {string} [fieldType=datetime] Field type of data sent to server
* @returns {string} date in format expected by server
*/
function dateToServer (date, fieldType) {
if (fieldType === "date") {
return date.clone().local().locale('en').format('YYYY-MM-DD');
}
return date.clone().utc().locale('en').format('YYYY-MM-DD HH:mm:ss');
}

Expand Down Expand Up @@ -142,7 +152,7 @@ return AbstractModel.extend({
var data = this.calendarEventToRecord(event.data.data);
for (var k in data) {
if (data[k] && data[k]._isAMomentObject) {
data[k] = dateToServer(data[k]);
data[k] = dateToServer(data[k], this.fields[k].type);
}
}
return this._rpc({
Expand Down Expand Up @@ -317,7 +327,7 @@ return AbstractModel.extend({
var data = _.omit(this.calendarEventToRecord(record), 'name');
for (var k in data) {
if (data[k] && data[k]._isAMomentObject) {
data[k] = dateToServer(data[k]);
data[k] = dateToServer(data[k], this.fields[k].type);
}
}
var context = new Context(this.data.context, {from_ui: true});
Expand Down