Skip to content

Commit 1ba20d8

Browse files
committed
Fix event time round logic to round it down
1 parent 2c863bd commit 1ba20d8

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/timeline/__tests__/presenter.spec.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ describe('timeline presenter', () => {
1414
expect(minutes).toBe(30);
1515
});
1616

17-
it('should round time to nearest 30 minutes block', () => {
17+
it('should round down time to nearest 30 minutes block', () => {
1818
const time1 = uut.calcTimeByPosition(310, 100);
1919
expect(time1.hour).toBe(3);
2020
expect(time1.minutes).toBe(0);
2121

2222
const time2 = uut.calcTimeByPosition(280, 100);
23-
expect(time2.hour).toBe(3);
24-
expect(time2.minutes).toBe(0);
23+
expect(time2.hour).toBe(2);
24+
expect(time2.minutes).toBe(30);
2525

2626
const time3 = uut.calcTimeByPosition(440, 100);
2727
expect(time3.hour).toBe(4);
28-
expect(time3.minutes).toBe(30);
28+
expect(time3.minutes).toBe(0);
2929

3030
const time4 = uut.calcTimeByPosition(1488, 100);
31-
expect(time4.hour).toBe(15);
32-
expect(time4.minutes).toBe(0);
31+
expect(time4.hour).toBe(14);
32+
expect(time4.minutes).toBe(30);
3333
});
3434

3535
it('should handle different hour block heights', () => {
@@ -39,7 +39,11 @@ describe('timeline presenter', () => {
3939

4040
const time2 = uut.calcTimeByPosition(350, 145);
4141
expect(time2.hour).toBe(2);
42-
expect(time2.minutes).toBe(30);
42+
expect(time2.minutes).toBe(0);
43+
44+
const time3 = uut.calcTimeByPosition(350, 135);
45+
expect(time3.hour).toBe(2);
46+
expect(time3.minutes).toBe(30);
4347
});
4448
});
4549

src/timeline/helpers/presenter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export function calcTimeByPosition(yPosition: number, hourBlockHeight: number) {
2-
const halfHourBlockHeight = hourBlockHeight / 2;
32
let time = yPosition / hourBlockHeight;
4-
time = Math.round(time * 2) / 2;
3+
time = Math.floor(time * 2) / 2;
54

65
const hour = Math.floor(time);
76
const minutes = (time - Math.floor(time)) * 60;

0 commit comments

Comments
 (0)