Skip to content

Commit

Permalink
fix(schedule): fix overflow from event workday
Browse files Browse the repository at this point in the history
  • Loading branch information
abalad committed Oct 21, 2020
1 parent 3cca87d commit 9ed11f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ export class WorkScaleService {
}


transformHourToMileseconds( fullHour: string ) {
transformHourToMileseconds( fullHour: string, currentDate = this.currentDate ) {
const hourSplited = fullHour.split(':');

const hours = Number(hourSplited[0]);
const minutes = Number(hourSplited[1]);
const year = this.currentDate.getFullYear();
const month = this.currentDate.getMonth();
const date = this.currentDate.getDate();
const year = currentDate.getFullYear();
const month = currentDate.getMonth();
const date = currentDate.getDate();

return new Date(year, month, date, hours, minutes).getTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,35 +138,35 @@ export class ViewDayComponent implements OnInit, AfterViewInit, OnChanges, OnDes
const scales = workScale.filter( work => work.expansed === undefined);
for (let i = 0; i <= events.length - 1; i++) {

for (let index = 0; index <= workScale.length - 1; index++) {
workScale.forEach( (value, workScaleIndex, array) => {
const eventStartDate = new Date(new Date(events[i].date.start).setSeconds(0)).getTime();
const eventEndDate = new Date(new Date(events[i].date.end).setSeconds(0)).getTime();
const workStartDate = this.workScaleService.transformHourToMileseconds(scales[index].start);
const workEndDate = this.workScaleService.transformHourToMileseconds(scales[index].end);
const workStartDate = this.workScaleService.transformHourToMileseconds(scales[workScaleIndex].start, new Date(eventStartDate));
const workEndDate = this.workScaleService.transformHourToMileseconds(scales[workScaleIndex].end, new Date(eventEndDate));

if (eventEndDate >= workEndDate && eventStartDate > workEndDate) {
if (workScale.length - 1 === index) {
if (eventEndDate >= workEndDate && eventStartDate >= workEndDate) {
if (workScale.length - 1 === workScaleIndex) {
scales.push({
start: this.workScaleService.transformMilesecondsToHour(workEndDate),
end: this.workScaleService.transformMilesecondsToHour(eventEndDate),
interval: (scales[index].interval),
interval: (scales[workScaleIndex].interval),
expansed: true,
});

}
}

if (eventEndDate <= workStartDate && eventStartDate <= workStartDate) {
if (index === 0) {
if (workScaleIndex === 0) {
scales.push({
start: this.workScaleService.transformMilesecondsToHour(eventStartDate),
end: this.workScaleService.transformMilesecondsToHour(workStartDate),
interval: (scales[index].interval),
interval: (scales[workScaleIndex].interval),
expansed: true,
});
}
}
}
});
}

this.workScaleService.reload( this.filterScaleStartRepeated( this.sortScaleByStart( scales) ));
Expand Down

0 comments on commit 9ed11f9

Please sign in to comment.