In the user interface, there are dropdowns for selecting a year and a week. Once a year is selected, the list of weeks for that year is displayed in the week dropdown.
Now, the requirement is to disable the selection of future weeks.
For example, for the year 2022: The weeks dropdown displays values from 1 to 53. However, users should only be able to select weeks up to the current date in February.
Expected output: Users should not be able to select future weeks; only the numbers for the current weeks should be displayed.
Below is the code that calculates the weeks based on the selected year.
Could someone please assist in implementing the logic to disable future weeks?
week(y = 0) {
y = y ? y : new Date().getFullYear();
let d, isLeap;
d = new Date(y, 0, 1);
isLeap = new Date(y, 1, 29).getMonth() === 1;
let count = d.getDay() === 4 || isLeap && d.getDay() === 3 ? 53 : 52;
this.numbers = Array(count).fill(0).map((x, i) => i + 1);
}