Skip to content

Commit

Permalink
fix: fixed modifyDateBlocksToFitRange() to fit to 0-0 range
Browse files Browse the repository at this point in the history
- fixed issue with modifyDateBlocksToFitRange() that prevented it from properly reducing a range to 0-0
  • Loading branch information
dereekb committed Apr 19, 2023
1 parent a1f0bb9 commit 4803132
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion packages/date/src/lib/date/date.block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import {
getRelativeIndexForDateTiming,
groupToDateBlockRanges,
groupUniqueDateBlocks,
isDateBlockWithinDateBlockRangeFunction,
isValidDateBlockTiming,
isValidDateBlockTimingStartDate,
modifyDateBlocksToFitRange,
modifyDateBlocksToFitRangeFunction,
sortDateBlockRanges,
UniqueDateBlockRange
Expand Down Expand Up @@ -983,7 +985,7 @@ describe('dateBlockIndexRange()', () => {
});
});

describe('dateBlocksInDateBlockRange', () => {
describe('dateBlocksInDateBlockRange()', () => {
it('should filter values that are within the range.', () => {
const range = { i: 0, to: 5 };
const input = [{ i: 0 }, { i: 1 }, { i: 2 }];
Expand Down Expand Up @@ -1017,6 +1019,24 @@ describe('dateBlocksInDateBlockRange', () => {
});
});

describe('isDateBlockWithinDateBlockRangeFunction()', () => {
describe('function', () => {
describe('range 0-0', () => {
const fn = isDateBlockWithinDateBlockRangeFunction({ i: 0, to: 0 });

it('should return false for the range 0-1000', () => {
const result = fn({ i: 0, to: 1000 });
expect(result).toBe(false);
});

it('should return true for the range 0-0', () => {
const result = fn({ i: 0, to: 0 });
expect(result).toBe(true);
});
});
});
});

describe('dateBlockRangeIncludedByRangeFunction()', () => {
describe('function', () => {
const range = dateBlockRange(5, 10);
Expand Down Expand Up @@ -1828,3 +1848,12 @@ describe('modifyDateBlocksToFitRangeFunction()', () => {
});
});
});

describe('modifyDateBlocksToFitRange()', () => {
it('should fit an input range of 0-1000 within a range of 0-0', () => {
const result = modifyDateBlocksToFitRange({ i: 0, to: 0 }, [{ i: 0, to: 1000 }]);
expect(result.length).toBe(1);
expect(result[0].i).toBe(0);
expect(result[0].to).toBe(0);
});
});
2 changes: 1 addition & 1 deletion packages/date/src/lib/date/date.block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ export function modifyDateBlocksToFitRangeFunction(range: DateBlockRange): Modif

if (!inRange) {
const asRange = dateBlockRangeWithRange(x);
const rangesOverlap = asRange.i < to && asRange.to > i;
const rangesOverlap = asRange.i <= to && asRange.to >= i;

if (rangesOverlap) {
result = {
Expand Down

0 comments on commit 4803132

Please sign in to comment.