Skip to content

Commit b847032

Browse files
committed
rename calcNowOffset to calcTimeOffset
1 parent 91aa18c commit b847032

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/timeline/NowIndicator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import {View, TextStyle, ViewStyle} from 'react-native';
33
import {HOUR_BLOCK_HEIGHT} from './Packer';
4-
import {calcNowOffset} from './helpers/presenter';
4+
import {calcTimeOffset} from './helpers/presenter';
55

66
export interface NowIndicatorProps {
77
styles: {[key: string]: ViewStyle | TextStyle};
@@ -10,7 +10,7 @@ export interface NowIndicatorProps {
1010
const NowIndicator = (props: NowIndicatorProps) => {
1111
const {styles} = props;
1212

13-
const indicatorPosition = calcNowOffset(HOUR_BLOCK_HEIGHT);
13+
const indicatorPosition = calcTimeOffset(HOUR_BLOCK_HEIGHT);
1414

1515
return (
1616
<View style={[styles.nowIndicator, {top: indicatorPosition}]}>

src/timeline/Timeline.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import constants from '../commons/constants';
77
import {Theme} from '../types';
88
import styleConstructor, {HOURS_SIDEBAR_WIDTH} from './style';
99
import populateEvents, {HOUR_BLOCK_HEIGHT} from './Packer';
10-
import {calcNowOffset} from './helpers/presenter';
10+
import {calcTimeOffset} from './helpers/presenter';
1111
import TimelineHours, {TimelineHoursProps} from './TimelineHours';
1212
import EventBlock, {Event, PackedEvent} from './EventBlock';
1313
import NowIndicator from './NowIndicator';
@@ -120,11 +120,11 @@ const Timeline = (props: TimelineProps) => {
120120
useEffect(() => {
121121
let initialPosition = 0;
122122
if (scrollToNow) {
123-
initialPosition = calcNowOffset(HOUR_BLOCK_HEIGHT);
123+
initialPosition = calcTimeOffset(HOUR_BLOCK_HEIGHT);
124124
} else if (scrollToFirst && packedEvents.length > 0) {
125125
initialPosition = min(map(packedEvents, 'top')) ?? 0;
126126
} else if (initialTime) {
127-
initialPosition = calcNowOffset(HOUR_BLOCK_HEIGHT, initialTime.hour, initialTime.minutes);
127+
initialPosition = calcTimeOffset(HOUR_BLOCK_HEIGHT, initialTime.hour, initialTime.minutes);
128128
}
129129

130130
if (initialPosition) {

src/timeline/__tests__/presenter.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ describe('timeline presenter', () => {
6969
});
7070
});
7171

72-
describe('calcNowOffset', () => {
72+
describe('calcTimeOffset', () => {
7373
// NOTE: useFakeTimers API works only in jest 27, unfortunately, other tests fail in jest 27
7474
it.skip('should give offset based on current time', () => {
7575
jest.useFakeTimers().setSystemTime(new Date('2020-01-01 15:30').getTime());
76-
expect(uut.calcNowOffset(100)).toBe(1550);
76+
expect(uut.calcTimeOffset(100)).toBe(1550);
7777

7878
jest.useFakeTimers().setSystemTime(new Date('2020-01-01 12:10').getTime());
79-
expect(uut.calcNowOffset(100)).toBeCloseTo(1216.66, 1);
79+
expect(uut.calcTimeOffset(100)).toBeCloseTo(1216.66, 1);
8080
});
8181

8282
it('should give offset based on given time', () => {
83-
expect(uut.calcNowOffset(100, 15, 30)).toBe(1550);
84-
expect(uut.calcNowOffset(100, 12, 10)).toBeCloseTo(1216.66, 1);
83+
expect(uut.calcTimeOffset(100, 15, 30)).toBe(1550);
84+
expect(uut.calcTimeOffset(100, 12, 10)).toBeCloseTo(1216.66, 1);
8585
});
8686
});
8787
});

src/timeline/helpers/presenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function buildTimeString(hour = 0, minutes = 0, date = '') {
1111
return `${date} ${hour.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:00`.trimStart();
1212
}
1313

14-
export function calcNowOffset(hourBlockHeight: number, hour?: number, minutes?: number) {
14+
export function calcTimeOffset(hourBlockHeight: number, hour?: number, minutes?: number) {
1515
const now = new Date();
1616
const h = hour ?? now.getHours();
1717
const m = minutes ?? now.getMinutes();

0 commit comments

Comments
 (0)