Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/utils/dataFormatters/__test__/formatUptime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ describe('formatUptimeInSeconds', () => {
const D = 24 * H;

it('should return days if value is more than 24h', () => {
expect(formatUptimeInSeconds(D)).toBe('1d' + UNBREAKABLE_GAP + '00:00:00');
expect(formatUptimeInSeconds(24 * H)).toBe('1d' + UNBREAKABLE_GAP + '00:00:00');
expect(formatUptimeInSeconds(D + H + M + 12)).toBe('1d' + UNBREAKABLE_GAP + '01:01:12');
expect(formatUptimeInSeconds(12 * D + 12 * H + 12 * M + 12)).toBe(
'12d' + UNBREAKABLE_GAP + '12:12:12',
// 1 week
expect(formatUptimeInSeconds(7 * D + H + M + 12)).toBe('7d' + UNBREAKABLE_GAP + '01:01:12');
// 1 month
expect(formatUptimeInSeconds(30 * D + 11 * H + 30 * M + 12)).toBe(
'30d' + UNBREAKABLE_GAP + '11:30:12',
);
expect(formatUptimeInSeconds(1234 * D + 12 * H + 12 * M + 12)).toBe(
'1234d' + UNBREAKABLE_GAP + '12:12:12',
Expand Down
4 changes: 3 additions & 1 deletion src/utils/dataFormatters/dataFormatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export function formatUptimeInSeconds(seconds: number) {

let value: string;

if (d.days() > 0) {
// Do not use just d.days(), since days could be rescaled up to weeks and more
// So for 7d we will have d.weeks() = 1 and d.days() = 0
if (Math.floor(d.asDays()) > 0) {
value = d.format(`d[${i18n('d')}${UNBREAKABLE_GAP}]hh:mm:ss`);
} else if (d.hours() > 0) {
value = d.format('h:mm:ss');
Expand Down
Loading