summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-04-18 14:24:04 +0200
committerChristophe Matthieu <chm@odoo.com>2017-04-19 14:48:06 +0200
commit69ae6e2912aaf6190d9856f04069d725ef5ad5a4 (patch)
tree88b8a00bd5db483912ca6d0faee9e3241daa4914 /addons/web/static/src/js/fields
parent7ff8aa73e17b281b3e2bc4c7275d020eab0204e7 (diff)
[FIX] web: use correct timezone for date fields
before this commit when toggling allday flag in calendar form view, it was possible to have one day error. The input datetime is wrong when the user don't use the datepicker widget (insert date by keypress instead of click on datepicker) sometimes, the value could be null (crash because try to clone false)
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js18
-rw-r--r--addons/web/static/src/js/fields/field_utils.js58
2 files changed, 61 insertions, 15 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 9f37240e0cc..85cd0382ac2 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -283,6 +283,14 @@ var FieldDate = InputField.extend({
//--------------------------------------------------------------------------
/**
+ * @override
+ * @private
+ */
+ _doDebouncedAction: function () {
+ this.datewidget.change_datetime();
+ },
+
+ /**
* return the datepicker value
*
* @private
@@ -311,6 +319,16 @@ var FieldDate = InputField.extend({
this.$input = this.datewidget.$input;
},
+ /**
+ * FieldDateTime overrides _formatValue to use the session timezone
+ *
+ * @override
+ * @private
+ * @param {Moment} value
+ */
+ _formatValue: function (value) {
+ return field_utils.format.date(value, {timezone: true});
+ },
});
var FieldDateTime = FieldDate.extend({
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index d6677291d47..b00fca0048a 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -60,12 +60,20 @@ function formatChar(value) {
* an empty string. Note that this is dependant on the localization settings
*
* @param {Moment|false}
+ * @param {Object} [field]
+ * a description of the field (note: this parameter is ignored)
+ * @param {Object} [options] additional options
+ * @param {boolean} [options.timezone=true] use the user timezone when formating the
+ * date
* @returns {string}
*/
-function formatDate(value) {
+function formatDate(value, field, options) {
if (!value) {
return "";
}
+ if (!options || !('timezone' in options) || options.timezone) {
+ value = value.clone().add(session.tzOffset < 0 ? -1 : 0, 'days');
+ }
var l10n = core._t.database.parameters;
var date_format = time.strftime_to_moment_format(l10n.date_format);
return value.format(date_format);
@@ -77,9 +85,14 @@ function formatDate(value) {
* settings
*
* @params {Moment|false}
+ * @param {Object} [field]
+ * a description of the field (note: this parameter is ignored)
+ * @param {Object} [options] additional options
+ * @param {boolean} [options.timezone=true] use the user timezone when formating the
+ * date
* @returns {string}
*/
-function formatDateTime(value, options) {
+function formatDateTime(value, field, options) {
if (!value) {
return "";
}
@@ -264,23 +277,32 @@ function formatSelection(value, field) {
////////////////////////////////////////////////////////////////////////////////
/**
- * create an Date object
+ * Create an Date object
* The method toJSON return the formated value to send value server side
*
- * @params {string}
+ * @param {string}
+ * @param {Object} [field]
+ * a description of the field (note: this parameter is ignored)
+ * @param {Object} [options] additional options
+ * @param {boolean} [options.isUTC] the formatted date is utc
+ * @param {boolean} [options.timezone=false] format the date after apply the timezone
+ * offset
* @returns {Moment|false} Moment date object
*/
function parseDate(value, field, options) {
if (!value) {
return false;
}
- var date_pattern = time.strftime_to_moment_format(core._t.database.parameters.date_format);
- var date_pattern_wo_zero = date_pattern.replace('MM','M').replace('DD','D');
+ var datePattern = time.strftime_to_moment_format(core._t.database.parameters.date_format);
+ var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D');
var date;
if (options && options.isUTC) {
date = moment.utc(value);
} else {
- date = moment.utc(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true);
+ date = moment.utc(value, [datePattern, datePatternWoZero, moment.ISO_8601], true);
+ if (options && options.timezone) {
+ date.add(session.tzOffset > 0 ? -1 : 0, 'days');
+ }
}
if (date.isValid() && date.year() >= 1900) {
if (date.year() === 0) {
@@ -297,22 +319,28 @@ function parseDate(value, field, options) {
}
/**
- * create an Date object
+ * Create an Date object
* The method toJSON return the formated value to send value server side
*
- * @params {string}
+ * @param {string}
+ * @param {Object} [field]
+ * a description of the field (note: this parameter is ignored)
+ * @param {Object} [options] additional options
+ * @param {boolean} [options.isUTC] the formatted date is utc
+ * @param {boolean} [options.timezone=false] format the date after apply the timezone
+ * offset
* @returns {Moment|false} Moment date object
*/
function parseDateTime(value, field, options) {
if (!value) {
return false;
}
- var date_pattern = time.strftime_to_moment_format(core._t.database.parameters.date_format),
- time_pattern = time.strftime_to_moment_format(core._t.database.parameters.time_format);
- var date_pattern_wo_zero = date_pattern.replace('MM','M').replace('DD','D'),
- time_pattern_wo_zero = time_pattern.replace('HH','H').replace('mm','m').replace('ss','s');
- var pattern1 = date_pattern + ' ' + time_pattern;
- var pattern2 = date_pattern_wo_zero + ' ' + time_pattern_wo_zero;
+ var datePattern = time.strftime_to_moment_format(core._t.database.parameters.date_format),
+ timePattern = time.strftime_to_moment_format(core._t.database.parameters.time_format);
+ var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D'),
+ timePatternWoZero = timePattern.replace('HH','H').replace('mm','m').replace('ss','s');
+ var pattern1 = datePattern + ' ' + timePattern;
+ var pattern2 = datePatternWoZero + ' ' + timePatternWoZero;
var datetime;
if (options && options.isUTC) {
// phatomjs crash if we don't use this format