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

Fix #3064: Calendar not inc/dec for decades #3066

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,16 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
if (currentView === 'date') {
if (newViewDate.getMonth() === 0) {
newViewDate.setMonth(11);
newViewDate.setFullYear(newViewDate.getFullYear() - 1);
setCurrentMonth(11)
decrementYear();

newViewDate.setFullYear(decrementYear());
setCurrentMonth(11);
}
else {
newViewDate.setMonth(newViewDate.getMonth() - 1);
setCurrentMonth(prevState => prevState - 1)
}
}
else if (currentView === 'month') {
let currentYear = newViewDate.getFullYear();
let newYear = currentYear - 1;
let newYear = newViewDate.getFullYear() - 1;

if (props.yearNavigator) {
const minYear = parseInt(props.yearRange.split(':')[0], 10);
Expand All @@ -295,10 +292,10 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
}

if (currentView === 'month') {
decrementYear();
newViewDate.setFullYear(decrementYear());
}
else if (currentView === 'year') {
decrementDecade();
newViewDate.setFullYear(decrementDecade());
}

updateViewDate(event, newViewDate);
Expand All @@ -318,18 +315,16 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
if (currentView === 'date') {
if (newViewDate.getMonth() === 11) {
newViewDate.setMonth(0);
newViewDate.setFullYear(newViewDate.getFullYear() + 1);
newViewDate.setFullYear(incrementYear());
setCurrentMonth(0);
incrementYear();
}
else {
newViewDate.setMonth(newViewDate.getMonth() + 1);
setCurrentMonth(prevState => prevState + 1)
}
}
else if (currentView === 'month') {
let currentYear = newViewDate.getFullYear();
let newYear = currentYear + 1;
let newYear = newViewDate.getFullYear() + 1;

if (props.yearNavigator) {
const maxYear = parseInt(props.yearRange.split(':')[1], 10);
Expand All @@ -343,10 +338,10 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
}

if (currentView === 'month') {
incrementYear();
newViewDate.setFullYear(incrementYear());
}
else if (currentView === 'year') {
incrementDecade();
newViewDate.setFullYear(incrementDecade());
}

updateViewDate(event, newViewDate);
Expand All @@ -372,6 +367,7 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
let difference = yearOptions[yearOptions.length - 1] - yearOptions[0];
populateYearOptions(yearOptions[0] - difference, yearOptions[yearOptions.length - 1] - difference);
}
return _currentYear;
}

const incrementYear = () => {
Expand All @@ -382,6 +378,7 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
let difference = yearOptions[yearOptions.length - 1] - yearOptions[0];
populateYearOptions(yearOptions[0] + difference, yearOptions[yearOptions.length - 1] + difference);
}
return _currentYear;
}

const onMonthDropdownChange = (event, value) => {
Expand Down Expand Up @@ -1343,11 +1340,15 @@ export const Calendar = React.memo(React.forwardRef((props, ref) => {
}

const decrementDecade = () => {
setCurrentYear(prevState => prevState - 10);
const _currentYear = currentYear - 10;
setCurrentYear(_currentYear);
return _currentYear;
}

const incrementDecade = () => {
setCurrentYear(prevState => prevState + 10);
const _currentYear = currentYear + 10;
setCurrentYear(_currentYear);
return _currentYear;
}

const switchToMonthView = (event) => {
Expand Down