Skip to content

Commit

Permalink
Fix: rounding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
forabi committed Mar 18, 2019
1 parent 0b64889 commit 00a5448
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/RangeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const RangeBox = React.memo(function RangeBox({
return;
}

if (modifiedCell.endY >= grid.numVerticalCells - 2) {
if (Math.round(modifiedCell.endY) >= grid.numVerticalCells - 1) {
return;
}

Expand All @@ -156,7 +156,7 @@ export const RangeBox = React.memo(function RangeBox({
return;
}

if (modifiedCell.endY >= grid.numVerticalCells - 2) {
if (Math.round(modifiedCell.endY) >= grid.numVerticalCells - 1) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/TimeGridScheduler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
ScheduleType,
} from '../types';
import { createGrid } from '../utils/createGrid';
import { createMapCellInfoToContiguousDateRange } from '../utils/createMapCellInfoToContiguousDateRange';
import {
createMapCellInfoToRecurringTimeRange,
RecurringTimeRange,
Expand Down Expand Up @@ -271,7 +270,7 @@ export const TimeGridScheduler = React.memo(function TimeGridScheduler({

const getDateRangeForVisualGrid = useMemo(
() =>
createMapCellInfoToContiguousDateRange({
createMapCellInfoToRecurringTimeRange({
originDate,
fromX: toDay,
fromY: y => y * visualGridVerticalPrecision,
Expand Down
13 changes: 5 additions & 8 deletions src/utils/createMapCellInfoToRecurringTimeRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import addMinutes from 'date-fns/add_minutes';
import compareAsc from 'date-fns/compare_asc';
import endOfDay from 'date-fns/end_of_day';
import isBefore from 'date-fns/is_before';
import isEqual from 'date-fns/is_equal';
import startOfDay from 'date-fns/start_of_day';
import subDays from 'date-fns/sub_days';
import min from 'date-fns/min';
import range from 'lodash/range';
import { DateRange, MapCellInfoToDateRange } from '../types';
import { cellToDate } from './cellToDate';
Expand All @@ -25,11 +23,10 @@ export const createMapCellInfoToRecurringTimeRange: MapCellInfoToDateRange = ({
toDay,
originDate,
});
let endDate = addMinutes(startDate, toMin(spanY));

if (isEqual(endDate, startOfDay(endDate))) {
endDate = endOfDay(subDays(endDate, 1));
}
let endDate = min(
addMinutes(startDate, toMin(spanY)),
endOfDay(startDate),
);

const range: DateRange = isBefore(startDate, endDate)
? [startDate, endDate]
Expand Down

0 comments on commit 00a5448

Please sign in to comment.