StephenChou1017 / react-big-scheduler

A scheduler and resource planning component built for React and made for modern browsers (IE10+)
https://stephenchou1017.github.io/scheduler/#/
MIT License
746 stars 415 forks source link

dayStopTo doesn't allow you to crossover into the next day #193

Open jeremygottfried opened 4 years ago

jeremygottfried commented 4 years ago

Pretty self explanatory. If I do this, it breaks the schedule.

dayStartFrom: 17,
dayStopTo: 5,
harshmendapara commented 2 years ago

SchedulerData.js

Replace Functions

_createHeaders() {
        let headers = [],
            start = this.localeMoment(this.startDate),
            end = this.localeMoment(this.endDate),
            header = start;

        if(this.showAgenda){
            headers.push({time: header.format(DATETIME_FORMAT), nonWorkingTime: false});
        }
        else {
            if (this.cellUnit === CellUnits.Hour) {
                start = start.add(this.config.dayStartFrom, "hours");
                end = end.add(this.config.dayStopTo, "hours");
                header = start;
                while (header >= start && header <= end) {
                    let minuteSteps = this.getMinuteStepsInHour();
                    for (let i = 0; i < minuteSteps; i++) {
                        let hour = header.hour();
                        // Eg when time is set from 00 t0 23  or 07 to 23
                        if (this.config.dayStartFrom <= this.config.dayStopTo) {
                            if (
                                hour >= this.config.dayStartFrom &&
                                hour <= this.config.dayStopTo
                            ) {
                                let time = header.format(DATETIME_FORMAT);
                                let nonWorkingTime =
                                    this.behaviors.isNonWorkingTimeFunc(
                                        this,
                                        time
                                    );
                                headers.push({
                                    time: time,
                                    nonWorkingTime: nonWorkingTime,
                                });
                            }
                        } else {
                            // Eg when time is set from 19 to 07 or 00 to 12
                            var dayStartFrom = this.config.dayStartFrom;
                            var dayStopTo = this.config.dayStopTo;

                            if (hour >= this.config.dayStopTo) dayStopTo = 23;
                            else if (hour <= this.config.dayStartFrom)
                                dayStartFrom = 0;

                            if (hour >= dayStartFrom && hour <= dayStopTo) {
                                let time = header.format(DATETIME_FORMAT);
                                var nonWorkingTime =
                                    this.behaviors.isNonWorkingTimeFunc(
                                        this,
                                        time
                                    );
                                headers.push({
                                    time: time,
                                    nonWorkingTime: nonWorkingTime,
                                });
                            }
                        }

                        header = header.add(this.config.minuteStep, "minutes");
                    }
                }
            }
            else {
                while (header >= start && header <= end) {
                    let time = header.format(DATETIME_FORMAT);
                    let dayOfWeek = header.weekday();
                    if( this.config.displayWeekend || (dayOfWeek !== 0 && dayOfWeek !== 6))
                    {
                        let nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
                        headers.push({ time: time, nonWorkingTime: nonWorkingTime });
                    }

                    header = header.add(1, 'days');
                }
            }
        }

        this.headers = headers;
    }