summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/core/time.js24
-rw-r--r--addons/web/static/src/js/fields/field_utils.js15
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_model.js4
-rw-r--r--addons/web/static/src/js/widgets/date_picker.js2
4 files changed, 32 insertions, 13 deletions
diff --git a/addons/web/static/src/js/core/time.js b/addons/web/static/src/js/core/time.js
index af13aa5a3b1..47a4c81465d 100644
--- a/addons/web/static/src/js/core/time.js
+++ b/addons/web/static/src/js/core/time.js
@@ -279,6 +279,27 @@ var normalize_format_table = {
};
var inverse_normalize_format_table = _.invert(normalize_format_table);
+/**
+ * Get date format of the user's language
+ */
+function getLangDateFormat() {
+ return this.strftime_to_moment_format(_t.database.parameters.date_format);
+}
+
+/**
+ * Get time format of the user's language
+ */
+function getLangTimeFormat() {
+ return this.strftime_to_moment_format(_t.database.parameters.time_format);
+}
+
+/**
+ * Get date time format of the user's language
+ */
+function getLangDatetimeFormat() {
+ return this.strftime_to_moment_format(_t.database.parameters.date_format + " " + _t.database.parameters.time_format);
+}
+
return {
@@ -293,6 +314,9 @@ return {
auto_date_to_str: auto_date_to_str,
strftime_to_moment_format: strftime_to_moment_format,
moment_to_strftime_format: moment_to_strftime_format,
+ getLangDateFormat: getLangDateFormat,
+ getLangTimeFormat: getLangTimeFormat,
+ getLangDatetimeFormat: getLangDatetimeFormat,
};
});
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index 7ba4122cccb..bca74acc088 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -97,8 +97,7 @@ function formatDate(value, field, options) {
value = value.clone().add(session.getTZOffset(value), 'minutes');
}
}
- var l10n = core._t.database.parameters;
- var date_format = time.strftime_to_moment_format(l10n.date_format);
+ var date_format = time.getLangDateFormat();
return value.format(date_format);
}
@@ -122,11 +121,7 @@ function formatDateTime(value, field, options) {
if (!options || !('timezone' in options) || options.timezone) {
value = value.clone().add(session.getTZOffset(value), 'minutes');
}
- var l10n = core._t.database.parameters;
- var date_format = time.strftime_to_moment_format(l10n.date_format);
- var time_format = time.strftime_to_moment_format(l10n.time_format);
- var datetime_format = date_format + ' ' + time_format;
- return value.format(datetime_format);
+ return value.format(time.getLangDatetimeFormat());
}
/**
@@ -349,7 +344,7 @@ function parseDate(value, field, options) {
if (!value) {
return false;
}
- var datePattern = time.strftime_to_moment_format(core._t.database.parameters.date_format);
+ var datePattern = time.getLangDateFormat();
var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D');
var date;
if (options && options.isUTC) {
@@ -388,8 +383,8 @@ function parseDateTime(value, field, options) {
if (!value) {
return false;
}
- 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 datePattern = time.getLangDateFormat(),
+ timePattern = time.getLangTimeFormat();
var datePatternWoZero = datePattern.replace('MM','M').replace('DD','D'),
timePatternWoZero = timePattern.replace('HH','H').replace('mm','m').replace('ss','s');
var pattern1 = datePattern + ' ' + timePattern;
diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js
index a0f6515b98c..fac6845a31f 100644
--- a/addons/web/static/src/js/views/calendar/calendar_model.js
+++ b/addons/web/static/src/js/views/calendar/calendar_model.js
@@ -382,8 +382,8 @@ return AbstractModel.extend({
allDayText: _t("All day"),
views: {
week: {
- columnFormat: 'ddd ' + time.strftime_to_moment_format(_t.database.parameters.date_format),
- titleFormat: time.strftime_to_moment_format(_t.database.parameters.time_format),
+ columnFormat: 'ddd ' + time.getLangDateFormat(),
+ titleFormat: time.getLangTimeFormat(),
}
},
monthNames: moment.months(),
diff --git a/addons/web/static/src/js/widgets/date_picker.js b/addons/web/static/src/js/widgets/date_picker.js
index 3573e9232e5..8d0b04332ad 100644
--- a/addons/web/static/src/js/widgets/date_picker.js
+++ b/addons/web/static/src/js/widgets/date_picker.js
@@ -26,7 +26,7 @@ var DateWidget = Widget.extend({
this.name = parent.name;
this.options = _.defaults(options || {}, {
- format : time.strftime_to_moment_format((this.type_of_date === 'datetime')? (l10n.date_format + ' ' + l10n.time_format) : l10n.date_format),
+ format : this.type_of_date === 'datetime' ? time.getLangDatetimeFormat() : time.getLangDateFormat(),
minDate: moment({ y: 1900 }),
maxDate: moment().add(200, "y"),
calendarWeeks: true,