Skip to content

Commit

Permalink
Fixing duration field formatter showing 0 seconds instead of "few sec…
Browse files Browse the repository at this point in the history
…onds" (#164659)

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: 

<img width="1361" alt="Skærmbillede 2023-08-24 kl 10 36 15"
src="https://github.com/elastic/kibana/assets/108192783/cc9a4490-e8b3-48a6-952e-61e9cd0aff81">


Fixes  #101000

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Matthias Wilhelm <[email protected]>
Co-authored-by: Davis McPhee <[email protected]>
  • Loading branch information
4 people authored Aug 24, 2023
1 parent c66f58a commit 2d9b46d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/plugins/field_formats/common/converters/duration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe('Duration Format', () => {
outputPrecision: undefined,
showSuffix: undefined,
fixtures: [
{
input: 0,
output: '0 seconds',
},
{
input: -60,
output: 'minus a minute',
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/field_formats/common/converters/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit 2d9b46d

Please sign in to comment.