This commit is contained in:
Robert Vokac 2024-03-23 08:20:02 +01:00
parent 2f7482536e
commit 805ddd162f
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
2 changed files with 43 additions and 19 deletions

View File

@ -292,27 +292,27 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
break; break;
case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_MONTH:
if (oldMonth != newMonth) { if (oldMonth != newMonth) {
updateProperty(timeCalcConfiguration.testMinuteCustomProperty, increase, decrease, reset, Calendar.MONTH); updateProperty(timeCalcConfiguration.testMonthCustomProperty, increase, decrease, reset, Calendar.MONTH);
} }
break; break;
case Calendar.HOUR_OF_DAY: case Calendar.HOUR_OF_DAY:
if (oldDay != newDay) { if (oldDay != newDay) {
updateProperty(timeCalcConfiguration.testSecondCustomProperty, increase, decrease, reset, Calendar.DAY_OF_MONTH); updateProperty(timeCalcConfiguration.testDayCustomProperty, increase, decrease, reset, Calendar.DAY_OF_MONTH);
} }
break; break;
case Calendar.MINUTE: case Calendar.MINUTE:
if (oldHour != newHour) { if (oldHour != newHour) {
updateProperty(timeCalcConfiguration.testMillisecondCustomProperty, increase, decrease, reset, Calendar.HOUR_OF_DAY); updateProperty(timeCalcConfiguration.testHourCustomProperty, increase, decrease, reset, Calendar.HOUR_OF_DAY);
} }
break; break;
case Calendar.SECOND: case Calendar.SECOND:
if (oldMinute != newMinute) { if (oldMinute != newMinute) {
updateProperty(timeCalcConfiguration.testMillisecondCustomProperty, increase, decrease, reset, Calendar.MINUTE); updateProperty(timeCalcConfiguration.testMinuteCustomProperty, increase, decrease, reset, Calendar.MINUTE);
} }
break; break;
case Calendar.MILLISECOND: case Calendar.MILLISECOND:
if (oldSecond != newSecond) { if (oldSecond != newSecond) {
updateProperty(timeCalcConfiguration.testMillisecondCustomProperty, increase, decrease, reset, Calendar.SECOND); updateProperty(timeCalcConfiguration.testSecondCustomProperty, increase, decrease, reset, Calendar.SECOND);
} }
break; break;
default: default:

View File

@ -67,24 +67,40 @@ public class Time extends Thread {
public Calendar asCalendar() { public Calendar asCalendar() {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, returnValueAsNeeded(yearProperty, yearCustomProperty)); cal.set(Calendar.YEAR, returnValueAsNeeded(yearProperty, yearCustomProperty, Calendar.YEAR));
cal.set(Calendar.MONTH, returnValueAsNeeded(monthProperty, monthCustomProperty) - 1); cal.set(Calendar.MONTH, returnValueAsNeeded(monthProperty, monthCustomProperty, Calendar.MONTH) - 1);
cal.set(Calendar.DAY_OF_MONTH, returnValueAsNeeded(dayProperty, dayCustomProperty)); cal.set(Calendar.DAY_OF_MONTH, returnValueAsNeeded(dayProperty, dayCustomProperty, Calendar.DAY_OF_MONTH));
cal.set(Calendar.HOUR_OF_DAY, returnValueAsNeeded(hourProperty, hourCustomProperty)); cal.set(Calendar.HOUR_OF_DAY, returnValueAsNeeded(hourProperty, hourCustomProperty, Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, returnValueAsNeeded(minuteProperty, minuteCustomProperty)); cal.set(Calendar.MINUTE, returnValueAsNeeded(minuteProperty, minuteCustomProperty, Calendar.MINUTE));
cal.set(Calendar.SECOND, returnValueAsNeeded(secondProperty, secondCustomProperty)); cal.set(Calendar.SECOND, returnValueAsNeeded(secondProperty, secondCustomProperty, Calendar.SECOND));
cal.set(Calendar.MILLISECOND, returnValueAsNeeded(millisecondProperty, millisecondCustomProperty)); cal.set(Calendar.MILLISECOND, returnValueAsNeeded(millisecondProperty, millisecondCustomProperty, Calendar.MILLISECOND));
return cal; return cal;
} }
private int returnValueAsNeeded(ReadOnlyProperty<Integer> p1, IntegerProperty p2) { private int returnValueAsNeeded(ReadOnlyProperty<Integer> real, IntegerProperty custom, int timeUnit) {
return returnValueAsNeeded(p1.getValue(), p2.getValue()); return returnValueAsNeeded(real.getValue(), custom.getValue(), timeUnit);
} }
private int returnValueAsNeeded(int i1, int i2) { private int returnValueAsNeeded(int real, int custom, int timeUnit) {
if(this.allowCustomValuesProperty.isDisabled()) { if (this.allowCustomValuesProperty.isDisabled()) {
return i1; return real;
} }
return i2 == Integer.MAX_VALUE ? i1 : i2;
int month = monthProperty.getValue();
if (timeUnit == Calendar.DAY_OF_MONTH && (month == 2 || month == 4
|| month == 6 || month == 9
|| month == 11)) {
if (month == 2) {
if (custom > 28) {
custom = 28;
} else {
if (custom > 30) {
custom = 30;
}
}
}
}
return custom == Integer.MAX_VALUE ? real : custom;
} }
public void run() { public void run() {
@ -127,14 +143,22 @@ public class Time extends Thread {
+ dayOfWeekProperty.getValue() + " " + dayOfWeekProperty.getValue() + " "
); );
} }
// private int returnCustomValueIfNeeded(Calendar cal, int timeUnit,ReadOnlyProperty<Integer> real,IntegerProperty custom) {
// return returnCustomValueIfNeeded(cal, timeUnit, real, custom);
// }
private int returnCustomValueIfNeeded(Calendar cal, int timeUnit, private int returnCustomValueIfNeeded(Calendar cal, int timeUnit,
IntegerProperty custom, IntegerProperty custom,
ReadOnlyProperty<Integer> real) { ReadOnlyProperty<Integer> real) {
boolean allow = allowCustomValuesProperty.isEnabled(); boolean allow = allowCustomValuesProperty.isEnabled();
Integer customValue = custom.getValue(); Integer customValue = custom.getValue();
int month = monthProperty.getValue();
if (allow && customValue != Integer.MAX_VALUE) { if (allow && customValue != Integer.MAX_VALUE) {
if(timeUnit == Calendar.DAY_OF_MONTH && (month == 2 || month ==4 || month == 6 || month == 9 || month == 11)) {
if(cal.getActualMaximum(Calendar.DAY_OF_MONTH) < custom.getValue()) {
return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
}
}
return custom.getValue(); return custom.getValue();
} else { } else {
return timeUnit == Calendar.MONTH ? (cal.get(timeUnit) + 1) : cal.get(timeUnit); return timeUnit == Calendar.MONTH ? (cal.get(timeUnit) + 1) : cal.get(timeUnit);