This is an automated email from the git hooks/post-receive script. New commit to branch feature/1169-Saisie_du_jour_uniquement in repository lima. See http://git.chorem.org/lima.git commit f1dc44658b4f4fd587c35f48fdabda6d34f304e3 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Feb 27 12:00:44 2015 +0100 improve validation of day of month + remove try catch block --- .../lima/ui/financialtransaction/DayColumn.java | 41 ++++++++++------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DayColumn.java b/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DayColumn.java index 17b328c..340e9f6 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DayColumn.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DayColumn.java @@ -50,7 +50,7 @@ public class DayColumn extends AbstractColumn<FinancialTransactionTableModel> { // valid that the day is into month range (date not > to 1rst day of next month) Date newDate = validAndGetNewDay(transaction, value); if (newDate != null) { - Integer newDay = (Integer) value; +// Integer newDay = (Integer) value; update = (transaction.getTransactionDate().compareTo(newDate) != 0); if (update) { transaction.setTransactionDate(newDate); @@ -68,30 +68,25 @@ public class DayColumn extends AbstractColumn<FinancialTransactionTableModel> { protected Date validAndGetNewDay(FinancialTransaction transaction, Object newDayValue) { Date result = null; - if (newDayValue != null) { - try { - Integer newDay = (Integer) newDayValue; - // valid that the day is into month range (date not > to 1rst day of next month) - if (newDay > 0) { - - Date previousDate = transaction.getTransactionDate(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(previousDate); - calendar.add(Calendar.MONTH, +1); - calendar.set(Calendar.DAY_OF_MONTH, 1); - Date maxDate = calendar.getTime(); - - calendar = Calendar.getInstance(); - calendar.setTime(previousDate); - calendar.set(Calendar.DAY_OF_MONTH, (Integer) newDayValue); - Date newDate = calendar.getTime(); + if (newDayValue != null && newDayValue instanceof Integer) { - if (newDate.before(maxDate)) { - result = newDate; - } + Integer newDay = (Integer) newDayValue; + + // valid that the day is into the month range + if (newDay > 0) { + + Date previousDate = transaction.getTransactionDate(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(previousDate); + int maximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); + if (newDay <= maximum) { + + calendar.set(Calendar.DAY_OF_MONTH, newDay); + Date newDate = calendar.getTime(); + result = newDate; + } else { + result = previousDate; } - } catch (Exception e) { - // nothing to do } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.