Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMonthView() behaves incorrectly when excludedDays is set. #1201

Closed
darrendlin opened this issue Mar 22, 2020 · 5 comments
Closed

getMonthView() behaves incorrectly when excludedDays is set. #1201

darrendlin opened this issue Mar 22, 2020 · 5 comments

Comments

@darrendlin
Copy link

Describe the bug

I'm trying to modify the MonthView to only display 2 weeks at a time. I'm attempting this with:

@Injectable()
export class HalfMonthCalendarUtils extends CalendarUtils {
  getMonthView(args: GetMonthViewArgs): MonthView {
    return super.getMonthView({
      ...args,
      viewStart: startOfWeek(args.viewDate),
      viewEnd: addWeeks(endOfWeek(args.viewDate), 1)
    });
  }
}

The above code, if I understand it correctly, should always display current and following week given a viewDate.

However, I noticed that if I have [excludeDays] set and I select a day in the last week of a month, then only the current week is displayed and the following week isn't displayed.

Minimal reproduction of the problem with instructions

  • Have a basic CalendarUtils extension and modify the viewStart and viewEnd
  • Have [excludeDays] set in the calendar MonthView
  • It seems like if viewStart and viewEnd attempts to include days not within the current month, then those days get completely excluded even if the days should not have been filtered by [excludeDays].

https://stackblitz.com/edit/angular-kgs6vy

Screenshots
Expected:
Screen Shot 2020-03-22 at 5 00 02 PM
Result:
Screen Shot 2020-03-22 at 5 03 36 PM

Versions

  • @angular/core: 8.2.14
  • angular-calendar: 0.28.5
  • Browser name and version: Chrome 80.0.3987.132
@matts-bot
Copy link

matts-bot bot commented Mar 22, 2020

Thanks so much for opening an issue! If you'd like me to give priority to answering your issue or would just like to support this project, then please consider sponsoring me

@darrendlin
Copy link
Author

After digging around in CalendarUtils, I think I found the source of the issue:
https://github.com/mattlewis92/calendar-utils/blob/master/src/calendar-utils.ts#L846

...
      const isRowInMonth: boolean = row.some(
        day => getMonth(day.date) === getMonth(viewDate)
      );
      if (isRowInMonth) {
        days = [...days, ...row];
...

In instances where there are excludeDays set, the function only adds in the days if the date is in the same month. I'm running on fumes at the moment so I can't think of why it needs to check month as opposed to checking if it's within the given viewStart and viewEnd?

@mattlewis92
Copy link
Owner

Hey there, thanks for taking the time to look into this, I had a quick look and this certainly seems like a bug, would you like to make a pull request with the fix you suggested? Thanks! 😄

@mattlewis92
Copy link
Owner

Should be fixed now in 0.28.8 😄

AlexGuz23 pushed a commit to AlexGuz23/calendar-utils that referenced this issue Nov 3, 2022
@chitgoks
Copy link

If the option [weekStartsOn]="1", this previous week is displayed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants