Browse Source

Merge pull request #46 from henninghall/multiple-centruries

Support picking dates in different centuries
master
Henning Hall 6 years ago
committed by GitHub
parent
commit
f6fadcf04d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions
  1. +14
    -3
      android/src/main/java/com/henninghall/date_picker/PickerView.java

+ 14
- 3
android/src/main/java/com/henninghall/date_picker/PickerView.java View File

@ -77,7 +77,7 @@ public class PickerView extends RelativeLayout {
ampmWheel = new AmPmWheel(this, R.id.ampm); ampmWheel = new AmPmWheel(this, R.id.ampm);
hourWheel = new HourWheel(this, R.id.hour); hourWheel = new HourWheel(this, R.id.hour);
dateFormat = new SimpleDateFormat(getDateFormatTemplate(), Locale.US);
setDateFormat();
changeAmPmWhenPassingMidnightOrNoon(); changeAmPmWhenPassingMidnightOrNoon();
} }
@ -89,6 +89,7 @@ public class PickerView extends RelativeLayout {
dateFormat.setTimeZone(timeZone); dateFormat.setTimeZone(timeZone);
Calendar date = Calendar.getInstance(timeZone); Calendar date = Calendar.getInstance(timeZone);
date.setTime(dateFormat.parse(getDateString())); date.setTime(dateFormat.parse(getDateString()));
update2DigitYearStart(date);
if (minDate != null && date.before(minDate)) applyOnVisibleWheels(new AnimateToDate(minDate)); if (minDate != null && date.before(minDate)) applyOnVisibleWheels(new AnimateToDate(minDate));
else if (maxDate != null && date.after(maxDate)) applyOnVisibleWheels(new AnimateToDate(maxDate)); else if (maxDate != null && date.after(maxDate)) applyOnVisibleWheels(new AnimateToDate(maxDate));
@ -139,11 +140,12 @@ public class PickerView extends RelativeLayout {
public void setDate(Calendar cal) { public void setDate(Calendar cal) {
applyOnAllWheels(new SetDate(cal)); applyOnAllWheels(new SetDate(cal));
update2DigitYearStart(cal);
} }
public void setLocale(Locale locale) { public void setLocale(Locale locale) {
this.locale = locale; this.locale = locale;
dateFormat = new SimpleDateFormat(getDateFormatTemplate(), Locale.US);
setDateFormat();
wheelOrderUpdater.update(locale, mode); wheelOrderUpdater.update(locale, mode);
requireDisplayValueUpdate = true; requireDisplayValueUpdate = true;
} }
@ -193,7 +195,7 @@ public class PickerView extends RelativeLayout {
public void setMode(Mode mode) { public void setMode(Mode mode) {
this.mode = mode; this.mode = mode;
dateFormat = new SimpleDateFormat(getDateFormatTemplate(), Locale.US);
setDateFormat();
applyOnAllWheels(new UpdateVisibility()); applyOnAllWheels(new UpdateVisibility());
wheelOrderUpdater.update(locale, mode); wheelOrderUpdater.update(locale, mode);
} }
@ -240,4 +242,13 @@ public class PickerView extends RelativeLayout {
public TimeZone getTimeZone() { public TimeZone getTimeZone() {
return timeZone; return timeZone;
} }
public void setDateFormat(){
dateFormat = new SimpleDateFormat(getDateFormatTemplate(), Locale.US);
}
public void update2DigitYearStart(Calendar selectedDate){
Calendar cal = (Calendar) selectedDate.clone();
cal.add(Calendar.YEAR, -50); // subtract 50 years to hit the middle of the century
dateFormat.set2DigitYearStart(cal.getTime());
}
} }

Loading…
Cancel
Save