-
Notifications
You must be signed in to change notification settings - Fork 3k
fix: updated calcualtions for showSixWeeks #2562
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,18 +125,26 @@ export function weekDayNames(firstDayOfWeek = 0) { | |
return weekDaysNames; | ||
} | ||
|
||
export function page(date: XDate, firstDayOfWeek = 0, showSixWeeks = false) { | ||
const days = month(date); | ||
const calculateDays = (dates: XDate[], from: XDate, to: XDate) => { | ||
let before: XDate[] = []; | ||
let after: XDate[] = []; | ||
const days = dates.map(day => day.clone()); | ||
if (isLTE(from, days[0])) { | ||
before = fromTo(from, days[0]); | ||
} | ||
if (isGTE(to, days[days.length - 1])) { | ||
after = fromTo(days[days.length - 1], to); | ||
} | ||
return before.concat(days.slice(1, days.length - 1), after); | ||
}; | ||
|
||
export function page(date: XDate, firstDayOfWeek = 0, showSixWeeks = false) { | ||
const days = month(date); | ||
|
||
const fdow = (7 + firstDayOfWeek) % 7 || 7; | ||
const ldow = (fdow + 6) % 7; | ||
|
||
firstDayOfWeek = firstDayOfWeek || 0; | ||
|
||
const from = days[0].clone(); | ||
const daysBefore = from.getDay(); | ||
|
||
if (from.getDay() !== fdow) { | ||
from.addDays(-(from.getDay() + 7 - fdow) % 7); | ||
|
@@ -148,21 +156,17 @@ export function page(date: XDate, firstDayOfWeek = 0, showSixWeeks = false) { | |
to.addDays((ldow + 7 - day) % 7); | ||
} | ||
|
||
const daysForSixWeeks = (daysBefore + days.length) / 6 >= 6; | ||
const daysOnPage = calculateDays(days, from, to).length; | ||
const daysForSixWeeks = daysOnPage / 7 >= 6; | ||
|
||
if (showSixWeeks && !daysForSixWeeks) { | ||
if (42 - daysOnPage > 7) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for months with 28 days (5 weeks) (Feb 2026) => add 7 days before If it bothers you we can just do to.addDays(42 - daysOnPage) but it's uglier in my opinion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 42 = 6weeks * 7days |
||
from.addDays(-7); | ||
} | ||
to.addDays(7); | ||
} | ||
|
||
if (isLTE(from, days[0])) { | ||
before = fromTo(from, days[0]); | ||
} | ||
|
||
if (isGTE(to, days[days.length - 1])) { | ||
after = fromTo(days[days.length - 1], to); | ||
} | ||
|
||
return before.concat(days.slice(1, days.length - 1), after); | ||
return calculateDays(days, from, to); | ||
} | ||
|
||
export function isDateNotInRange(date: XDate, minDate: string, maxDate: string) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to insure immutability, I'm not sure if this is indeed needed tho