From 4197ebfabc1329110b18aa4972b5317e739d4dc0 Mon Sep 17 00:00:00 2001 From: "Michael Mattiello (mcm)" Date: Mon, 8 Jun 2020 07:10:08 +0000 Subject: [IMP] web: add options to formatFloatTime This commit adds noLeadingZeroHour option to formatFloatTime. The noLeadingZeroHour option can be used to format the value like 1:30 instead of 01:30 This format behaviour is wanted for fields in web_grid module. Task 2261853 closes odoo/odoo#52217 Related: odoo/enterprise#10870 Signed-off-by: Aaron Bohy (aab) Co-authored-by: Hardik Prajapati Co-authored-by: Mohammed Shekha --- addons/web/static/src/js/fields/field_utils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/fields') diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 76fda4859e6..681a1eb3672 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -200,10 +200,16 @@ function formatFloatFactor(value, field, options) { * instead of 0.25. * * @param {float} value + * @param {Object} [field] + * a description of the field (note: this parameter is ignored) + * @param {Object} [options] + * @param {boolean} [options.noLeadingZeroHour] if true, format like 1:30 + * otherwise, format like 01:30 * @returns {string} */ -function formatFloatTime(value) { - var pattern = '%02d:%02d'; +function formatFloatTime(value, field, options) { + options = options || {}; + var pattern = options.noLeadingZeroHour ? '%1d:%02d' : '%02d:%02d'; if (value < 0) { value = Math.abs(value); pattern = '-' + pattern; -- cgit v1.2.3