Browse Source

fix: incorrect initial date when date in past (#644)

master
Henning Hall 2 years ago
committed by GitHub
parent
commit
a84d570ade
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 19 deletions
  1. +29
    -2
      .maestro/display-text.yml
  2. +1
    -1
      .maestro/utils/swipe-wheel-1.yml
  3. +0
    -4
      android/src/main/java/com/henninghall/date_picker/props/Prop.java
  4. +4
    -12
      android/src/main/java/com/henninghall/date_picker/wheels/DayWheel.java

+ 29
- 2
.maestro/display-text.yml View File

@ -1,8 +1,35 @@
appId: com.rn069
---
- runFlow:
file: utils/set-timezone.yml
env:
REGION: Sweden
GMT: GMT+01:00
STATE: ''
# test: can have initial date in past
- runFlow: utils/launch.yml
- tapOn: androidVariant
- tapOn: nativeAndroid
- runFlow:
file: utils/change-prop.yml
env:
PROP: maximumDate
VALUE: undefined
- runFlow:
file: utils/change-prop.yml
env:
PROP: minimumDate
VALUE: undefined
- runFlow:
file: utils/change-prop.yml
env:
PROP: date
VALUE: '1999-01-01'
- runFlow: utils/swipe-wheel-1.yml
- assertVisible: '1999-01-02 01:00:00'
- runFlow: utils/reset.yml
# test: display text
- runFlow:
file: utils/change-prop.yml
env:

+ 1
- 1
.maestro/utils/swipe-wheel-1.yml View File

@ -2,4 +2,4 @@ appId: com.rn069
---
- swipe:
start: 25%, 40%
end: 25%, 30%
end: 25%, 35%

+ 0
- 4
android/src/main/java/com/henninghall/date_picker/props/Prop.java View File

@ -17,10 +17,6 @@ public abstract class Prop {
this.value = toValue(value);
}
public void setValue(T value){
this.value = value;
}
public T getValue(){
return value;
}

+ 4
- 12
android/src/main/java/com/henninghall/date_picker/wheels/DayWheel.java View File

@ -18,7 +18,7 @@ import java.util.HashMap;
public class DayWheel extends Wheel {
private String todayValue;
private static int defaultNumberOfDays = Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_YEAR);
private static int defaultNumberOfDays = 150;
private HashMap<String, String> displayValues;
public DayWheel(Picker picker, State state) {
@ -54,7 +54,7 @@ public class DayWheel extends Wheel {
cal = (Calendar) max.clone();
cal.add(Calendar.DATE, -cal.getActualMaximum(Calendar.DAY_OF_YEAR) / 2);
} else {
cal = (Calendar) getInitialDate().clone();
cal = getInitialDate();
cal.add(Calendar.DATE, -defaultNumberOfDays / 2);
}
return cal;
@ -70,20 +70,12 @@ public class DayWheel extends Wheel {
cal = (Calendar) min.clone();
cal.add(Calendar.DATE, cal.getActualMaximum(Calendar.DAY_OF_YEAR) / 2);
} else {
cal = (Calendar) getInitialDate().clone();
cal.setTime(new Date());
cal = getInitialDate();
cal.add(Calendar.DATE, defaultNumberOfDays / 2);
}
return cal;
}
private void resetToMidnight(Calendar cal){
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
}
private String getValue(Calendar cal){
return format.format(cal.getTime());
}
@ -141,7 +133,7 @@ public class DayWheel extends Wheel {
// Rounding cal to closest minute interval
private Calendar getInitialDate() {
Calendar cal = Calendar.getInstance();
Calendar cal = state.getDate();
int minuteInterval = state.getMinuteInterval();
if(minuteInterval <= 1) return cal;
SimpleDateFormat minuteFormat = new SimpleDateFormat("mm", state.getLocale());

Loading…
Cancel
Save