From 2d9b46dd0b89670f2a3c592d66d9e7bc7e2b0490 Mon Sep 17 00:00:00 2001 From: Ninoslav Miskovic <108192783+ninoslavmiskovic@users.noreply.github.com> Date: Thu, 24 Aug 2023 21:14:36 +0200 Subject: [PATCH] Fixing duration field formatter showing 0 seconds instead of "few seconds" (#164659) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR solves the issue when a user is formatting fields that are "0" to be Human Friendly, then it shows "a few seconds" instead of "0.00 seconds" This PR changes it to say: "0.00 seconds". I have also updated the test-case for it. Video of the issue - tested on 8.11 snapshot: https://github.com/elastic/kibana/assets/108192783/082329bf-6c62-4eb5-b28e-212a848f6f65 Screenshot of the fix: Skærmbillede 2023-08-24 kl 10 36 15 Fixes https://github.com/elastic/kibana/issues/101000 --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Matthias Wilhelm Co-authored-by: Davis McPhee --- .../field_formats/common/converters/duration.test.ts | 4 ++++ src/plugins/field_formats/common/converters/duration.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/plugins/field_formats/common/converters/duration.test.ts b/src/plugins/field_formats/common/converters/duration.test.ts index 58e3fb4f3a967..52fb64888f5ac 100644 --- a/src/plugins/field_formats/common/converters/duration.test.ts +++ b/src/plugins/field_formats/common/converters/duration.test.ts @@ -15,6 +15,10 @@ describe('Duration Format', () => { outputPrecision: undefined, showSuffix: undefined, fixtures: [ + { + input: 0, + output: '0 seconds', + }, { input: -60, output: 'minus a minute', diff --git a/src/plugins/field_formats/common/converters/duration.ts b/src/plugins/field_formats/common/converters/duration.ts index 1579d6058e98c..1ed6ec014ed47 100644 --- a/src/plugins/field_formats/common/converters/duration.ts +++ b/src/plugins/field_formats/common/converters/duration.ts @@ -99,6 +99,12 @@ export class DurationFormat extends FieldFormat { const human = this.isHuman(); const humanPrecise = this.isHumanPrecise(); + if (human && val === 0) { + return i18n.translate('fieldFormats.duration.zeroSecondsLabel', { + defaultMessage: '0 seconds', + }); // Handle the case of 0 value for "Human Friendly" + } + const prefix = val < 0 && human ? i18n.translate('fieldFormats.duration.negativeLabel', {