Skip to content

Commit 5ce9117

Browse files
artemmufazalovastandrik
authored andcommitted
fix: fix 1 week uptime formatting (#1759)
1 parent b5c61cd commit 5ce9117

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/utils/dataFormatters/__test__/formatUptime.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ describe('formatUptimeInSeconds', () => {
3131
const D = 24 * H;
3232

3333
it('should return days if value is more than 24h', () => {
34-
expect(formatUptimeInSeconds(D)).toBe('1d' + UNBREAKABLE_GAP + '00:00:00');
34+
expect(formatUptimeInSeconds(24 * H)).toBe('1d' + UNBREAKABLE_GAP + '00:00:00');
3535
expect(formatUptimeInSeconds(D + H + M + 12)).toBe('1d' + UNBREAKABLE_GAP + '01:01:12');
36-
expect(formatUptimeInSeconds(12 * D + 12 * H + 12 * M + 12)).toBe(
37-
'12d' + UNBREAKABLE_GAP + '12:12:12',
36+
// 1 week
37+
expect(formatUptimeInSeconds(7 * D + H + M + 12)).toBe('7d' + UNBREAKABLE_GAP + '01:01:12');
38+
// 1 month
39+
expect(formatUptimeInSeconds(30 * D + 11 * H + 30 * M + 12)).toBe(
40+
'30d' + UNBREAKABLE_GAP + '11:30:12',
3841
);
3942
expect(formatUptimeInSeconds(1234 * D + 12 * H + 12 * M + 12)).toBe(
4043
'1234d' + UNBREAKABLE_GAP + '12:12:12',

src/utils/dataFormatters/dataFormatters.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export function formatUptimeInSeconds(seconds: number) {
5757

5858
let value: string;
5959

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

0 commit comments

Comments
 (0)