diff options
| author | Romain Derie <rde@odoo.com> | 2018-03-09 14:01:47 +0100 |
|---|---|---|
| committer | Romain Derie <rde@odoo.com> | 2018-03-12 12:06:55 +0100 |
| commit | f02cd2977efa524b2acaa489bc5c114de69a8e88 (patch) | |
| tree | ea1b745c61e005013ae9fe731910e52ee2be0144 /addons/website/static | |
| parent | 6f18af73e0ed04fc4211cb06bad551adb8d8824d (diff) | |
[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
Diffstat (limited to 'addons/website/static')
| -rw-r--r-- | addons/website/static/src/js/menu/content.js | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/addons/website/static/src/js/menu/content.js b/addons/website/static/src/js/menu/content.js index 2221eba4024..a4145c41241 100644 --- a/addons/website/static/src/js/menu/content.js +++ b/addons/website/static/src/js/menu/content.js @@ -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 |
