Projectmanager: Fix hoursPerDay was not properly considered for durations

This commit is contained in:
nathan 2023-06-23 14:35:04 -06:00
parent ab4d9a1446
commit cfcd56fd00

View File

@ -50,7 +50,7 @@ export function formatDuration(value : number | string, options : formatOptions)
for(let i = 0; i < options.displayFormat.length; ++i) for(let i = 0; i < options.displayFormat.length; ++i)
{ {
let unit = options.displayFormat[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') if(unit === 's' || unit === 'm' || unit === 'h' && options.displayFormat[0] === 'd')
{ {
vals.push(sprintf('%02d', val)); 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) for(let i = 0; i < this.displayFormat.length; ++i)
{ {
let unit = this.displayFormat[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') if(unit === 's' || unit === 'm' || unit === 'h' && this.displayFormat[0] === 'd')
{ {
vals.push(sprintf('%02d', val)); 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 // get value for given _unit
switch(_unit) switch(_unit)
{ {
@ -518,9 +521,9 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement)
return _highest ? _value : _value % 60; return _highest ? _value : _value % 60;
case 'h': case 'h':
_value = Math.floor(_value / 3600); _value = Math.floor(_value / 3600);
return _highest ? _value : _value % this.hoursPerDay; return _highest ? _value : _value % options.hoursPerDay;
case 'd': case 'd':
return Math.floor(_value / 3600 / this.hoursPerDay); return Math.floor(_value / 3600 / options.hoursPerDay);
} }
} }