@@ -657,124 +657,126 @@ export default class SchedulerData {
657
657
}
658
658
659
659
// Previous Code
660
- // _createHeaders() {
661
- // const headers = [];
662
- // let start = this.localeDayjs(new Date(this.startDate));
663
- // let end = this.localeDayjs(new Date(this.endDate));
664
- // let header = start;
665
-
666
- // if (this.showAgenda) {
667
- // headers.push({ time: header.format(DATETIME_FORMAT), nonWorkingTime: false });
668
- // } else if (this.cellUnit === CellUnit.Hour) {
669
- // if (start.hour() === 0) {
670
- // start = start.add(this.config.dayStartFrom, 'hours');
671
- // }
672
- // if (end.hour() === 0) {
673
- // end = end.add(this.config.dayStopTo, 'hours');
674
- // }
675
- // header = start;
676
-
677
- // let prevHour = -1;
678
- // while (header >= start && header <= end) {
679
- // // prevent doubled hours on time change
680
- // if (header.hour() === prevHour) {
681
- // header = header.add(1, 'hours');
682
- // continue;
683
- // }
684
- // prevHour = header.hour();
685
- // const minuteSteps = this.getMinuteStepsInHour();
686
- // for (let i = 0; i < minuteSteps; i++) {
687
- // const hour = header.hour();
688
- // if (hour >= this.config.dayStartFrom && hour <= this.config.dayStopTo) {
689
- // const time = header.format(DATETIME_FORMAT);
690
- // const nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
691
- // headers.push({ time, nonWorkingTime });
692
- // }
693
-
694
- // header = header.add(this.config.minuteStep, 'minutes');
695
- // }
696
- // }
697
- // } else if (this.cellUnit === CellUnit.Day) {
698
- // while (header >= start && header <= end) {
699
- // const time = header.format(DATETIME_FORMAT);
700
- // const dayOfWeek = header.weekday();
701
- // if (this.config.displayWeekend || (dayOfWeek !== 0 && dayOfWeek !== 6)) {
702
- // const nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
703
- // headers.push({ time, nonWorkingTime });
704
- // }
705
-
706
- // header = header.add(1, 'days');
707
- // }
708
- // } else if (this.cellUnit === CellUnit.Week) {
709
- // while (header >= start && header <= end) {
710
- // const time = header.format(DATE_FORMAT);
711
- // headers.push({ time });
712
- // header = header.add(1, 'weeks').startOf('week');
713
- // }
714
- // } else if (this.cellUnit === CellUnit.Month) {
715
- // while (header >= start && header <= end) {
716
- // const time = header.format(DATE_FORMAT);
717
- // headers.push({ time });
718
- // header = header.add(1, 'months').startOf('month');
719
- // }
720
- // } else if (this.cellUnit === CellUnit.Year) {
721
- // while (header >= start && header <= end) {
722
- // const time = header.format(DATE_FORMAT);
723
- // headers.push({ time });
724
- // header = header.add(1, 'years').startOf('year');
725
- // }
726
- // }
727
-
728
- // this.headers = headers;
729
- // }
730
-
731
660
_createHeaders ( ) {
732
661
const headers = [ ] ;
733
- const start = this . localeDayjs ( new Date ( this . startDate ) ) ;
734
- const end = this . localeDayjs ( new Date ( this . endDate ) ) ;
662
+ let start = this . localeDayjs ( new Date ( this . startDate ) ) ;
663
+ let end = this . localeDayjs ( new Date ( this . endDate ) ) ;
664
+ let header = start ;
735
665
736
- const processHeader = ( header , format , unit , incrementFn ) => {
737
- let head = header ;
738
- while ( head >= start && head <= end ) {
739
- const time = head . format ( format ) ;
740
- if ( unit === CellUnit . Day ) {
741
- const dayOfWeek = head . weekday ( ) ;
742
- if ( this . config . displayWeekend || ( dayOfWeek !== 0 && dayOfWeek !== 6 ) ) {
666
+ if ( this . showAgenda ) {
667
+ headers . push ( { time : header . format ( DATETIME_FORMAT ) , nonWorkingTime : false } ) ;
668
+ } else if ( this . cellUnit === CellUnit . Hour ) {
669
+ if ( start . hour ( ) === 0 ) {
670
+ start = start . add ( this . config . dayStartFrom , 'hours' ) ;
671
+ }
672
+ if ( end . hour ( ) === 0 ) {
673
+ end = end . add ( this . config . dayStopTo , 'hours' ) ;
674
+ }
675
+ header = start ;
676
+
677
+ let prevHour = - 1 ;
678
+ while ( header >= start && header <= end ) {
679
+ // prevent doubled hours on time change
680
+ if ( header . hour ( ) === prevHour ) {
681
+ header = header . add ( 1 , 'hours' ) ;
682
+ // eslint-disable-next-line no-continue
683
+ continue ;
684
+ }
685
+ prevHour = header . hour ( ) ;
686
+ const minuteSteps = this . getMinuteStepsInHour ( ) ;
687
+ for ( let i = 0 ; i < minuteSteps ; i += 1 ) {
688
+ const hour = header . hour ( ) ;
689
+ if ( hour >= this . config . dayStartFrom && hour <= this . config . dayStopTo ) {
690
+ const time = header . format ( DATETIME_FORMAT ) ;
743
691
const nonWorkingTime = this . behaviors . isNonWorkingTimeFunc ( this , time ) ;
744
692
headers . push ( { time, nonWorkingTime } ) ;
745
693
}
746
- } else {
747
- headers . push ( { time } ) ;
694
+
695
+ header = header . add ( this . config . minuteStep , 'minutes' ) ;
748
696
}
749
- head = head . add ( 1 , incrementFn ) ;
750
697
}
751
- } ;
752
-
753
- if ( this . showAgenda ) {
754
- headers . push ( { time : start . format ( DATETIME_FORMAT ) , nonWorkingTime : false } ) ;
755
- } else if ( this . cellUnit === CellUnit . Hour ) {
756
- const hourIncrement = this . config . minuteStep < 60 ? 'minutes' : 'hours' ;
757
- const minuteSteps = this . getMinuteStepsInHour ( ) ;
758
- let header = start . hour ( ) === 0 ? start . add ( this . config . dayStartFrom , 'hours' ) : start ;
759
- while ( header <= end ) {
760
- const hour = header . hour ( ) ;
761
- if ( hour >= this . config . dayStartFrom && hour <= this . config . dayStopTo ) {
762
- const time = header . format ( DATETIME_FORMAT ) ;
698
+ } else if ( this . cellUnit === CellUnit . Day ) {
699
+ while ( header >= start && header <= end ) {
700
+ const time = header . format ( DATETIME_FORMAT ) ;
701
+ const dayOfWeek = header . weekday ( ) ;
702
+ if ( this . config . displayWeekend || ( dayOfWeek !== 0 && dayOfWeek !== 6 ) ) {
763
703
const nonWorkingTime = this . behaviors . isNonWorkingTimeFunc ( this , time ) ;
764
704
headers . push ( { time, nonWorkingTime } ) ;
765
705
}
766
- header = header . add ( minuteSteps , hourIncrement ) ;
706
+
707
+ header = header . add ( 1 , 'days' ) ;
708
+ }
709
+ } else if ( this . cellUnit === CellUnit . Week ) {
710
+ while ( header >= start && header <= end ) {
711
+ const time = header . format ( DATE_FORMAT ) ;
712
+ headers . push ( { time } ) ;
713
+ header = header . add ( 1 , 'weeks' ) . startOf ( 'week' ) ;
714
+ }
715
+ } else if ( this . cellUnit === CellUnit . Month ) {
716
+ while ( header >= start && header <= end ) {
717
+ const time = header . format ( DATE_FORMAT ) ;
718
+ headers . push ( { time } ) ;
719
+ header = header . add ( 1 , 'months' ) . startOf ( 'month' ) ;
720
+ }
721
+ } else if ( this . cellUnit === CellUnit . Year ) {
722
+ while ( header >= start && header <= end ) {
723
+ const time = header . format ( DATE_FORMAT ) ;
724
+ headers . push ( { time } ) ;
725
+ header = header . add ( 1 , 'years' ) . startOf ( 'year' ) ;
767
726
}
768
- } else {
769
- const header = start ;
770
- const format = this . cellUnit === CellUnit . Day ? DATETIME_FORMAT : DATE_FORMAT ;
771
- const incrementFn = this . cellUnit === CellUnit . Day ? 'days' : `${ this . cellUnit } s` ;
772
- processHeader ( header , format , this . cellUnit , incrementFn ) ;
773
727
}
774
728
775
729
this . headers = headers ;
776
730
}
777
731
732
+ // Fix Optimited code
733
+ // _createHeaders() {
734
+ // const headers = [];
735
+ // const start = this.localeDayjs(new Date(this.startDate));
736
+ // const end = this.localeDayjs(new Date(this.endDate));
737
+
738
+ // const processHeader = (header, format, unit, incrementFn) => {
739
+ // let head = header;
740
+ // while (head >= start && head <= end) {
741
+ // const time = head.format(format);
742
+ // if (unit === CellUnit.Day) {
743
+ // const dayOfWeek = head.weekday();
744
+ // if (this.config.displayWeekend || (dayOfWeek !== 0 && dayOfWeek !== 6)) {
745
+ // const nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
746
+ // headers.push({ time, nonWorkingTime });
747
+ // }
748
+ // } else {
749
+ // headers.push({ time });
750
+ // }
751
+ // head = head.add(1, incrementFn);
752
+ // }
753
+ // };
754
+
755
+ // if (this.showAgenda) {
756
+ // headers.push({ time: start.format(DATETIME_FORMAT), nonWorkingTime: false });
757
+ // } else if (this.cellUnit === CellUnit.Hour) {
758
+ // const hourIncrement = this.config.minuteStep < 60 ? 'minutes' : 'hours';
759
+ // const minuteSteps = this.getMinuteStepsInHour();
760
+ // let header = start.hour() === 0 ? start.add(this.config.dayStartFrom, 'hours') : start;
761
+ // while (header <= end) {
762
+ // const hour = header.hour();
763
+ // if (hour >= this.config.dayStartFrom && hour <= this.config.dayStopTo) {
764
+ // const time = header.format(DATETIME_FORMAT);
765
+ // const nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
766
+ // headers.push({ time, nonWorkingTime });
767
+ // }
768
+ // header = header.add(minuteSteps, hourIncrement);
769
+ // }
770
+ // } else {
771
+ // const header = start;
772
+ // const format = this.cellUnit === CellUnit.Day ? DATETIME_FORMAT : DATE_FORMAT;
773
+ // const incrementFn = this.cellUnit === CellUnit.Day ? 'days' : `${this.cellUnit}s`;
774
+ // processHeader(header, format, this.cellUnit, incrementFn);
775
+ // }
776
+
777
+ // this.headers = headers;
778
+ // }
779
+
778
780
_createInitHeaderEvents ( header ) {
779
781
const start = this . localeDayjs ( new Date ( header . time ) ) ;
780
782
const startValue = start . format ( DATETIME_FORMAT ) ;
0 commit comments