Reputation: 3215
I am trying to change the last day allowed in my calendar Widget based on the current date or fix date.
The code below is using a date as a default start date and I need to allow the user to select between this date and date + 3 months later.
val maxDay = Calendar.getInstance()
setSelectedDate(currentShipDate.toDate())
maxDay.add(Calendar.MONTH, 3)
state().edit()
.setMinimumDate(minDay.time)
.setMaximumDate(maxDay.time)
.commit()
The maxDay
is now set to 3 months later using the currentShipDate
. However, I am looking to allow the user to also select a date until the end of the 3rd months.
For example, if the ship happened in 21st July, you can change the shipping date til 31st October (instead of 21st October)
For example, if the ship happened in 10th July, you can change the shipping date til 31st October (instead of 10st October)
Any idea ?
Thanks for your help
Upvotes: 0
Views: 767
Reputation: 2931
Do it like this:
maxDay.add(Calendar.MONTH, 4)
maxDay.set(Calendar.DAY_OF_MONTH, 1)
maxDay.add(Calendar.DAY_OF_MONTH, -1)
This will give you the last day of the third month.
Upvotes: 2