From cfcd56fd00f0570be29df4c4a9cbb73dc1a42e53 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 23 Jun 2023 14:35:04 -0600 Subject: [PATCH] Projectmanager: Fix hoursPerDay was not properly considered for durations --- api/js/etemplate/Et2Date/Et2DateDuration.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/api/js/etemplate/Et2Date/Et2DateDuration.ts b/api/js/etemplate/Et2Date/Et2DateDuration.ts index 16d2f6adcb..ac53aa1131 100644 --- a/api/js/etemplate/Et2Date/Et2DateDuration.ts +++ b/api/js/etemplate/Et2Date/Et2DateDuration.ts @@ -50,7 +50,7 @@ export function formatDuration(value : number | string, options : formatOptions) for(let i = 0; i < options.displayFormat.length; ++i) { let unit = options.displayFormat[i]; - let val = this._unit_from_value(value, unit, i === 0); + let val = this._unit_from_value(value, unit, i === 0, options); if(unit === 's' || unit === 'm' || unit === 'h' && options.displayFormat[0] === 'd') { vals.push(sprintf('%02d', val)); @@ -432,7 +432,10 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) for(let i = 0; i < this.displayFormat.length; ++i) { let unit = this.displayFormat[i]; - let val = this._unit_from_value(_value, unit, i === 0); + let val = this._unit_from_value(_value, unit, i === 0, { + hoursPerDay: this.hoursPerDay, + dataFormat: this.dataFormat + }); if(unit === 's' || unit === 'm' || unit === 'h' && this.displayFormat[0] === 'd') { vals.push(sprintf('%02d', val)); @@ -505,9 +508,9 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) } } - private _unit_from_value(_value, _unit, _highest) + private _unit_from_value(_value, _unit, _highest, options) { - _value *= this._unit2seconds(this.dataFormat); + _value *= this._unit2seconds(options.dataFormat); // get value for given _unit switch(_unit) { @@ -518,9 +521,9 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) return _highest ? _value : _value % 60; case 'h': _value = Math.floor(_value / 3600); - return _highest ? _value : _value % this.hoursPerDay; + return _highest ? _value : _value % options.hoursPerDay; case 'd': - return Math.floor(_value / 3600 / this.hoursPerDay); + return Math.floor(_value / 3600 / options.hoursPerDay); } }