Skip to content

Commit

Permalink
feat(react-scheduler): time scale should take fractional startDayHour…
Browse files Browse the repository at this point in the history
…/endDayHour values
  • Loading branch information
Andrey Churkin committed Oct 4, 2019
1 parent ccdfc4e commit 153ce52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 23 additions & 0 deletions packages/dx-scheduler-core/src/plugins/common/computeds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,34 @@ describe('#timeScale', () => {
const currentDate = new Date(2018, 5, 28);
const firstDateOfWeek = new Date(2018, 5, 25);
const format = date => `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;

it('should start calculation from start view date', () => {
const units = timeScale(currentDate, 1, 0, 1, 30);
expect(format(units[0].start))
.toEqual(format(firstDateOfWeek));
});

it('should process fractional startDayHour/endDayHour values', () => {
const units = timeScale(currentDate, 0, 8.5, 9.5, 23);

expect(units.length).toBe(3);

expect(units[0].start.getHours()).toBe(8);
expect(units[0].start.getMinutes()).toBe(30);
expect(units[0].end.getHours()).toBe(8);
expect(units[0].end.getMinutes()).toBe(30 + 23);

expect(units[1].start.getHours()).toBe(8);
expect(units[1].start.getMinutes()).toBe(30 + 23);
expect(units[1].end.getHours()).toBe(9);
expect(units[1].end.getMinutes()).toBe(16);

expect(units[2].start.getHours()).toBe(9);
expect(units[2].start.getMinutes()).toBe(16);
expect(units[2].end.getHours()).toBe(9);
expect(units[2].end.getMinutes()).toBe(16 + 23 - 1);
});

it('should return time units', () => {
const units = timeScale(currentDate, 1, 0, 24, 30);
expect(units).toHaveLength(48);
Expand Down
8 changes: 6 additions & 2 deletions packages/dx-scheduler-core/src/plugins/common/computeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ export const timeScale: TimeScaleFn = (
const startDateOfView = firstDayOfWeek !== undefined
? calculateFirstDateOfWeek(currentDate, firstDayOfWeek, excludedDays)
: currentDate;
const left = moment(startDateOfView as Date).startOf('hour').hour(startDayHour);
const right = moment(startDateOfView as Date).startOf('hour').hour(endDayHour);
const left = moment(startDateOfView as Date)
.startOf('day')
.add(startDayHour, 'hour');
const right = moment(startDateOfView as Date)
.startOf('day')
.add(endDayHour, 'hour');

while (left.isBefore(right)) {
const startDate = left.toDate();
Expand Down

0 comments on commit 153ce52

Please sign in to comment.