date-duration select_unit=false must show full value for highest display unit, not just the remainer

value=3600 with display_format=m:s must show "60:00" not "00:00"
This commit is contained in:
Ralf Becker 2021-02-22 10:52:15 +02:00
parent 319c0e6af4
commit 907b33454a
2 changed files with 17 additions and 12 deletions

View File

@ -721,16 +721,18 @@ var et2_date_duration = /** @class */ (function (_super) {
return 3600 * this.options.hours_per_day; return 3600 * this.options.hours_per_day;
} }
}; };
et2_date_duration.prototype._unit_from_value = function (_value, _unit) { et2_date_duration.prototype._unit_from_value = function (_value, _unit, _highest) {
_value *= this._unit2seconds(this.data_format); _value *= this._unit2seconds(this.data_format);
// get value for given _unit // get value for given _unit
switch (_unit) { switch (_unit) {
case 's': case 's':
return _value % 60; return _highest ? _value : _value % 60;
case 'm': case 'm':
return Math.floor(_value / 60) % 60; _value = Math.floor(_value / 60);
return _highest ? _value : _value % 60;
case 'h': case 'h':
return Math.floor(_value / 3600) % this.options.hours_per_day; _value = Math.floor(_value / 3600);
return _highest ? _value : _value % this.options.hours_per_day;
case 'd': case 'd':
return Math.floor(_value / 3600 * this.options.hours_per_day); return Math.floor(_value / 3600 * this.options.hours_per_day);
} }
@ -739,7 +741,7 @@ var et2_date_duration = /** @class */ (function (_super) {
this.options.value = _value; this.options.value = _value;
if (!this.options.select_unit && this.options.display_format.length > 1) { if (!this.options.select_unit && this.options.display_format.length > 1) {
for (var i = this.options.display_format.length; --i >= 0;) { for (var i = this.options.display_format.length; --i >= 0;) {
jQuery(this.duration[i]).val(this._unit_from_value(_value, this.options.display_format[i])); jQuery(this.duration[i]).val(this._unit_from_value(_value, this.options.display_format[i], i === this.options.display_format.length - 1));
} }
return; return;
} }
@ -813,7 +815,7 @@ var et2_date_duration = /** @class */ (function (_super) {
var vals = []; var vals = [];
for (var i = 0; i < this.options.display_format.length; ++i) { for (var i = 0; i < this.options.display_format.length; ++i) {
var unit = this.options.display_format[i]; var unit = this.options.display_format[i];
var val = this._unit_from_value(_value, unit); var val = this._unit_from_value(_value, unit, i === 0);
if (unit === 's' || unit === 'm' || unit === 'h' && this.options.display_format[0] === 'd') { if (unit === 's' || unit === 'm' || unit === 'h' && this.options.display_format[0] === 'd') {
vals.push(sprintf('%02d', val)); vals.push(sprintf('%02d', val));
} }

View File

@ -889,18 +889,20 @@ export class et2_date_duration extends et2_date
} }
} }
private _unit_from_value(_value, _unit) private _unit_from_value(_value, _unit, _highest)
{ {
_value *= this._unit2seconds(this.data_format); _value *= this._unit2seconds(this.data_format);
// get value for given _unit // get value for given _unit
switch(_unit) switch(_unit)
{ {
case 's': case 's':
return _value % 60; return _highest ? _value : _value % 60;
case 'm': case 'm':
return Math.floor(_value / 60) % 60; _value = Math.floor(_value / 60);
return _highest ? _value : _value % 60;
case 'h': case 'h':
return Math.floor(_value / 3600) % this.options.hours_per_day; _value = Math.floor(_value / 3600);
return _highest ? _value : _value % this.options.hours_per_day;
case 'd': case 'd':
return Math.floor(_value / 3600*this.options.hours_per_day); return Math.floor(_value / 3600*this.options.hours_per_day);
} }
@ -914,7 +916,8 @@ export class et2_date_duration extends et2_date
{ {
for (let i = this.options.display_format.length; --i >= 0;) for (let i = this.options.display_format.length; --i >= 0;)
{ {
jQuery(this.duration[i]).val(this._unit_from_value(_value, this.options.display_format[i])); jQuery(this.duration[i]).val(this._unit_from_value(_value, this.options.display_format[i],
i === this.options.display_format.length-1));
} }
return; return;
} }
@ -1010,7 +1013,7 @@ export class et2_date_duration extends et2_date
for (let i=0; i < this.options.display_format.length; ++i) for (let i=0; i < this.options.display_format.length; ++i)
{ {
let unit = this.options.display_format[i]; let unit = this.options.display_format[i];
let val = this._unit_from_value(_value, unit); let val = this._unit_from_value(_value, unit, i === 0);
if (unit === 's' || unit === 'm' || unit === 'h' && this.options.display_format[0] === 'd' ) if (unit === 's' || unit === 'm' || unit === 'h' && this.options.display_format[0] === 'd' )
{ {
vals.push(sprintf('%02d', val)); vals.push(sprintf('%02d', val));