-
Notifications
You must be signed in to change notification settings - Fork 83
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
Fix KDateRange failing tests on prs opened on last day of the month #718
Fix KDateRange failing tests on prs opened on last day of the month #718
Conversation
@@ -157,8 +157,9 @@ | |||
}, | |||
numOfDays: 7, | |||
isFirstChoice: this.selectedStartDate == null ? true : false, | |||
activeMonth: new Date().getMonth() - 1 == -1 ? 11 : new Date().getMonth() - 1, | |||
activeYearStart: new Date().getFullYear(), | |||
activeMonth: |
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.
I'm curious to know why 1 is subtracted from the active month. It means that the activeMonth will always be the month before the lastAllowedDate right? But if we are in January, the previous month would cause the year to also have to be reduced, but I see that activeYearStart is taken only from getFullYear.
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.
This is because of how the Date() constructor in JavaScript sets the months. It uses an integer value to represent the month, beginning with 0 for January to 11 for December.
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.
Oh no, I meant what if the lastAllowedDate
was for example new Date(2024, 0, 1)
, then activeMonth would be 11, but activeYearStart would be 2024, so the active date would be December 2024 instead of December 2023. But I looked at the code and I see that this activeYearStart
value is updated in the created hook if this happens, so there is no problem.
Anyways I think we could avoid the ternary here, and the check in the created hook if we do something similar to get the previous month:
data() {
const previousMonth = new Date(this.lastAllowedDate);
previousMonth.setMonth(lastAllowedDate.getMonth() - 1);
return {
...,
activeMonth: previousMonth.getMonth(),
activeYearStart: previousMonth.getFullYear(),
};
},
But it is totally optional, although I think it would clarify the intention that activeMonth and activeYearStart refer to the previous month of the lastAllowedDate.
Update how KDatecalendar test case prop previousMonth is set Co-authored-by: Alex Velez <[email protected]>
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.
lgtm! And code seems to be working even if lastAllowedDate
is the last day of the month.
Description
This pull request fixes the failing
KDateCalendar
component tests that would occur on open pull requests on the last day of the month. This was fixed by setting dates manually in the tests. TheKDateCalendar
has also been updated to display the month of the propertylastAllowedDate
.Issue addressed
Addresses #713
Changelog
KDateCalendar
component tests that occurred on the last day of the month in open pull requests by setting dates manually in the tests. Additionally, theKDateCalendar
is updated to show the month of thelastAllowedDate
property.Testing checklist
Reviewer guidance
After review
CHANGELOG.md
Comments