Fix incorrect hour/minute calculation in simpleTimeLabel()
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -131,8 +131,8 @@ export function simpleTimeLabel(second, fixedNumber = 0) {
|
||||
const hour = 60 * 60;
|
||||
const minutes = 60;
|
||||
const dd = Math.floor(second / day);
|
||||
const hh = Math.floor((second / hour) / day);
|
||||
const mm = Math.floor((second / hour) / minutes);
|
||||
const hh = Math.floor((second % day) / hour);
|
||||
const mm = Math.floor((second % hour) / minutes);
|
||||
|
||||
if(dd > 0){
|
||||
return (second / day).toFixed(fixedNumber) + "d";
|
||||
|
||||
@@ -48,6 +48,16 @@ describe('simpleTimeLabel', () => {
|
||||
expect(simpleTimeLabel(86400)).toBe('1d');
|
||||
});
|
||||
|
||||
it('returns hours with h suffix', () => {
|
||||
expect(simpleTimeLabel(3600)).toBe('1h');
|
||||
expect(simpleTimeLabel(7200)).toBe('2h');
|
||||
});
|
||||
|
||||
it('returns minutes with m suffix', () => {
|
||||
expect(simpleTimeLabel(60)).toBe('1m');
|
||||
expect(simpleTimeLabel(120)).toBe('2m');
|
||||
});
|
||||
|
||||
it('returns seconds with s suffix for small values', () => {
|
||||
expect(simpleTimeLabel(30)).toBe('30s');
|
||||
});
|
||||
@@ -55,6 +65,16 @@ describe('simpleTimeLabel', () => {
|
||||
it('returns 0s for zero', () => {
|
||||
expect(simpleTimeLabel(0)).toBe('0s');
|
||||
});
|
||||
|
||||
it('correctly calculates hours for values between 1h and 1d', () => {
|
||||
// 5 hours = 18000 seconds -> should be "5h"
|
||||
expect(simpleTimeLabel(18000)).toBe('5h');
|
||||
});
|
||||
|
||||
it('correctly calculates minutes for values between 1m and 1h', () => {
|
||||
// 30 minutes = 1800 seconds -> should be "30m"
|
||||
expect(simpleTimeLabel(1800)).toBe('30m');
|
||||
});
|
||||
});
|
||||
|
||||
describe('followTimeLabel', () => {
|
||||
|
||||
Reference in New Issue
Block a user