forked from jaegertracing/jaeger-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve human-readable duration formatting (jaegertracing#647)
* Add more units to duration formatting Expands the number of units that the formatDuration function displays. Previously the function only used milliseconds and seconds to display durations, now it will support all units up to days. This is to make it easier to read very long durations in the UI that would have previously only been displayed in seconds. As a side effect of this change, there are a few changes to the way existing durations are displayed: * 0ms -> 0μs * 1.5μs * 1.5ms * 1.5s * 1m 30s * 1h 30m * 1d 12h Resolves jaegertracing#319 Signed-off-by: James Ferguson <jamesferguson497@gmail.com> * Remove inputUnit parameter of formatDuration The inputUnit parameter was not used anywhere and significantly complicated the implementation of the formatDuration function. Now, all inputs are assumed to be in microseconds which is consistent with a few other methods in the date.tsx file. Signed-off-by: James Ferguson <jamesferguson497@gmail.com> * Reduce date format units to 2 Reduces the number of units displayed by the dateFormat function to a maximum of 2. So "2d 5h 20m" will now be "2d 5h". Signed-off-by: James Ferguson <jamesferguson497@gmail.com> * Use decimals when formating μs, ms and s durations This change will display durations less than a minute using decimals as 1.3s is easier to comprehend than 1s 300ms as it was being displayed before. Durations larger than a minute will still use multiple units. Eg. 5m 27s Signed-off-by: James Ferguson <jamesferguson497@gmail.com> * Fix date.test.js licence Signed-off-by: James Ferguson <jamesferguson497@gmail.com> Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
- Loading branch information
1 parent
6e43af5
commit d5ca4fe
Showing
4 changed files
with
98 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2020 The Jaeger Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { formatDuration, ONE_MILLISECOND, ONE_SECOND, ONE_MINUTE, ONE_HOUR, ONE_DAY } from './date.tsx'; | ||
|
||
describe('formatDuration', () => { | ||
it('keeps microseconds the same', () => { | ||
expect(formatDuration(1)).toBe('1μs'); | ||
}); | ||
|
||
it('displays a maximum of 2 units and rounds the last one', () => { | ||
const input = 10 * ONE_DAY + 13 * ONE_HOUR + 30 * ONE_MINUTE; | ||
expect(formatDuration(input)).toBe('10d 14h'); | ||
}); | ||
|
||
it('skips units that are empty', () => { | ||
const input = 2 * ONE_DAY + 5 * ONE_MINUTE; | ||
expect(formatDuration(input)).toBe('2d'); | ||
}); | ||
|
||
it('displays milliseconds in decimals', () => { | ||
const input = 2 * ONE_MILLISECOND + 357; | ||
expect(formatDuration(input)).toBe('2.36ms'); | ||
}); | ||
|
||
it('displays seconds in decimals', () => { | ||
const input = 2 * ONE_SECOND + 357 * ONE_MILLISECOND; | ||
expect(formatDuration(input)).toBe('2.36s'); | ||
}); | ||
|
||
it('displays minutes in split units', () => { | ||
const input = 2 * ONE_MINUTE + 30 * ONE_SECOND + 555 * ONE_MILLISECOND; | ||
expect(formatDuration(input)).toBe('2m 31s'); | ||
}); | ||
|
||
it('displays hours in split units', () => { | ||
const input = 2 * ONE_HOUR + 30 * ONE_MINUTE + 30 * ONE_SECOND; | ||
expect(formatDuration(input)).toBe('2h 31m'); | ||
}); | ||
|
||
it('displays times less than a μs', () => { | ||
const input = 0.1; | ||
expect(formatDuration(input)).toBe('0.1μs'); | ||
}); | ||
|
||
it('displays times of 0', () => { | ||
const input = 0; | ||
expect(formatDuration(input)).toBe('0μs'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters