From 907b33454a4110d996cb05721ee80ab76805a1e7 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 22 Feb 2021 10:52:15 +0200 Subject: [PATCH] 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" --- api/js/etemplate/et2_widget_date.js | 14 ++++++++------ api/js/etemplate/et2_widget_date.ts | 15 +++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/api/js/etemplate/et2_widget_date.js b/api/js/etemplate/et2_widget_date.js index 7c1ece1e16..8e720de552 100644 --- a/api/js/etemplate/et2_widget_date.js +++ b/api/js/etemplate/et2_widget_date.js @@ -721,16 +721,18 @@ var et2_date_duration = /** @class */ (function (_super) { 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); // get value for given _unit switch (_unit) { case 's': - return _value % 60; + return _highest ? _value : _value % 60; case 'm': - return Math.floor(_value / 60) % 60; + _value = Math.floor(_value / 60); + return _highest ? _value : _value % 60; 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': 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; if (!this.options.select_unit && this.options.display_format.length > 1) { 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; } @@ -813,7 +815,7 @@ var et2_date_duration = /** @class */ (function (_super) { var vals = []; for (var i = 0; i < this.options.display_format.length; ++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') { vals.push(sprintf('%02d', val)); } diff --git a/api/js/etemplate/et2_widget_date.ts b/api/js/etemplate/et2_widget_date.ts index 48eaa27b36..14fb123b87 100644 --- a/api/js/etemplate/et2_widget_date.ts +++ b/api/js/etemplate/et2_widget_date.ts @@ -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); // get value for given _unit switch(_unit) { case 's': - return _value % 60; + return _highest ? _value : _value % 60; case 'm': - return Math.floor(_value / 60) % 60; + _value = Math.floor(_value / 60); + return _highest ? _value : _value % 60; 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': 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;) { - 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; } @@ -1010,7 +1013,7 @@ export class et2_date_duration extends et2_date for (let i=0; i < this.options.display_format.length; ++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' ) { vals.push(sprintf('%02d', val));