[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) <aab@odoo.com> Co-authored-by: Hardik Prajapati <hap@odoo.com> Co-authored-by: Mohammed Shekha <msh@openerp.com>
This commit is contained in:
co-authored by
Hardik Prajapati
Mohammed Shekha
parent
beccf82e09
commit
4197ebfabc
@@ -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;
|
||||
|
||||
@@ -166,6 +166,23 @@ QUnit.test('format percentage', function (assert) {
|
||||
core._t.database.parameters = originalParameters;
|
||||
});
|
||||
|
||||
QUnit.test('format float time', function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
assert.strictEqual(fieldUtils.format.float_time(2), '02:00');
|
||||
assert.strictEqual(fieldUtils.format.float_time(3.5), '03:30');
|
||||
assert.strictEqual(fieldUtils.format.float_time(0.25), '00:15');
|
||||
|
||||
assert.strictEqual(fieldUtils.format.float_time(-0.5), '-00:30');
|
||||
|
||||
const options = {
|
||||
noLeadingZeroHour: true,
|
||||
};
|
||||
assert.strictEqual(fieldUtils.format.float_time(2, null, options), '2:00');
|
||||
assert.strictEqual(fieldUtils.format.float_time(3.5, null, options), '3:30');
|
||||
assert.strictEqual(fieldUtils.format.float_time(-0.5, null, options), '-0:30');
|
||||
});
|
||||
|
||||
QUnit.test('parse float', function(assert) {
|
||||
assert.expect(10);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user