Browse Source

fix: `minimumDate`/`maximumDate` issue in `datetime` mode that might occur when min/max includes hours, minutes or seconds (#740)

master
Henning Hall 1 year ago
committed by GitHub
parent
commit
f748d9117e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions
  1. +18
    -0
      .maestro/maximum-date.yml
  2. +11
    -1
      android/src/main/java/com/henninghall/date_picker/wheels/DayWheel.java

+ 18
- 0
.maestro/maximum-date.yml View File

@ -111,3 +111,21 @@ tags:
- runFlow: utils/swipe-wheel-3.yml
- assertVisible: '2000-01-01 00:00:00'
######### describe: minimumDate/maximumDate combinations
- runFlow: utils/reset.yml
## test: correct number of days should be selectable even if min/max days are not set to full days
- runFlow:
file: utils/change-minimum-date.yml
env:
VALUE: '2000-01-01 00:00:01'
- runFlow:
file: utils/change-maximum-date.yml
env:
VALUE: '2000-01-02 00:00:00'
- runFlow: utils/swipe-wheel-1.yml
- assertVisible: '2000-01-02 00:00:00'

+ 11
- 1
android/src/main/java/com/henninghall/date_picker/wheels/DayWheel.java View File

@ -32,12 +32,14 @@ public class DayWheel extends Wheel {
Calendar cal = getStartCal();
Calendar endCal = getEndCal();
while (!cal.after(endCal)){
while (true){
String value = getValue(cal);
values.add(value);
displayValues.put(value, getDisplayValue(cal));
if(Utils.isToday(cal)) todayValue = value;
cal.add(Calendar.DATE, 1);
Calendar startOfCurrentDay = toStartOfDay((Calendar) cal.clone());
if(startOfCurrentDay.after(endCal)) break;
}
return values;
@ -75,6 +77,14 @@ public class DayWheel extends Wheel {
return cal;
}
private Calendar toStartOfDay(Calendar cal){
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal;
}
private String getValue(Calendar cal){
return format.format(cal.getTime());
}

Loading…
Cancel
Save