[FIX] website: use user timezone when handling date in page property

Before this commit:
1. The date would be displayed as UTC regardless of the user timezone.
2. The date would be sent to the backend in the browser timezone

Now we correctly take the user timezone into consideration when handling date.

Step to reproduce:
  - Install a second language where time format is: %H.%M.%S or %H,%M,%S
    (eg: Finnish, Bulgarian, Albanian )
  - Set it as website default's language
  - Open page properties dialog on any page
  - The date looks correctly displayed but it is in fact the UTC hour and not
    the user timezone date. (eg: 2 hours missing in Albanian case, it would
    show '2018-Pri-05 02.11.02.' instead of '2018-Pri-05 04.11.02.')
  - If you save, it will crash since it will send the wrong date format to the
    backend that is expecting 'YYYY-MM-DD HH:MM:SS' format.

Closes #23500, closes #23566
This commit is contained in:
Romain Derie
2018-03-12 12:06:55 +01:00
parent 6f18af73e0
commit f02cd2977e
2 changed files with 37 additions and 3 deletions
@@ -155,6 +155,12 @@
border-radius: 0;
}
.has-error {
.form-control {
border-color: @state-danger-text;
}
}
select.form-control {
.o-appearance(none);
background: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPScxLjEnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZycgeG1 sbnM6eGxpbms9J2h0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsnIHdpZHRoPScyNCcgaGVpZ2 h0PScyNCcgdmlld0JveD0nMCAwIDI0IDI0Jz48cGF0aCBpZD0nc3ZnXzEnIGQ9J203LjQwNiw3L jgyOGw0LjU5NCw0LjU5NGw0LjU5NCwtNC41OTRsMC40MDYsMS40MDZsLTUsNC43NjZsLTUsLTQu NzY2bDAuNDA2LC0xLjQwNnonIGZpbGw9JyM4ODgnLz48L3N2Zz4=');
+31 -3
View File
@@ -147,7 +147,7 @@ var PagePropertiesDialog = widget.Dialog.extend({
},
};
if (self.page.date_publish) {
datepickersOptions.defaultDate = self.page.date_publish;
datepickersOptions.defaultDate = time.str_to_datetime(self.page.date_publish);
}
this.$("#date_publish_container").datetimepicker(datepickersOptions);
@@ -174,9 +174,15 @@ var PagePropertiesDialog = widget.Dialog.extend({
var context = weContext.get();
var url = $(".o_page_management_info #page_url").val();
var date_publish = $(".o_page_management_info #date_publish").val();
var $date_publish = $(".o_page_management_info #date_publish");
$date_publish.closest(".form-group").removeClass('has-error');
var date_publish = $date_publish.val();
if (date_publish != "") {
date_publish = time.datetime_to_str(new Date(date_publish));
date_publish = this._parse_date(date_publish);
if (!date_publish) {
$date_publish.closest(".form-group").addClass('has-error');
return;
}
}
var params = {
id: self.page.id,
@@ -271,6 +277,28 @@ var PagePropertiesDialog = widget.Dialog.extend({
id: m[2] | 0,
};
},
/**
* Converts a string representing the browser datetime
* (exemple: Albanian: '2018-Qer-22 15.12.35.')
* to a string representing UTC in Odoo's datetime string format
* (exemple: '2018-04-22 13:12:35').
*
* The time zone of the datetime string is assumed to be the one of the
* browser and it will be converted to UTC (standard for Odoo).
*
* @private
* @param {String} value A string representing a datetime.
* @returns {String|false} A string representing an UTC datetime if the given value is valid, false otherwise.
*/
_parse_date: function (value) {
var datetime = moment(value, time.getLangDatetimeFormat(), true);
if (datetime.isValid()) {
return time.datetime_to_str(datetime.toDate());
}
else {
return false;
}
},
//--------------------------------------------------------------------------
// Handlers