bugfix: editing the day didn't work for not today dates
This commit is contained in:
@ -90,9 +90,18 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
return String.format("%02d:%02d", diff.toHours(), diff.toMinutes() % 60);
|
||||
}
|
||||
|
||||
public LocalDateTime getLocalDateTimeFromHHmm(String s) {
|
||||
/**
|
||||
* get local date time from s
|
||||
*
|
||||
* @param s the HH:mm formatted values
|
||||
* @param ldt the date as basic for that datetime, for today one can use LocalDateTime.now(); in fact this is set if ldt is null internally
|
||||
* @return the generated datetime
|
||||
*/
|
||||
public LocalDateTime getLocalDateTimeFromHHmm(String s, LocalDateTime ldt) {
|
||||
if (s == null || s.trim().isEmpty()) {
|
||||
return null;
|
||||
} else if (ldt == null) {
|
||||
ldt = LocalDateTime.now();
|
||||
}
|
||||
String[] hm = s.split(":");
|
||||
Integer hours = 0;
|
||||
@ -103,7 +112,6 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
if (hm.length > 1) {
|
||||
minutes = Integer.valueOf(hm[1]);
|
||||
}
|
||||
LocalDateTime ldt = LocalDateTime.now();
|
||||
ldt = ldt.withHour(hours);
|
||||
ldt = ldt.withMinute(minutes);
|
||||
ldt = ldt.withSecond(0);
|
||||
@ -128,7 +136,7 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
}
|
||||
|
||||
public void setTimeFromString(String s) {
|
||||
LocalDateTime ldt = getLocalDateTimeFromHHmm(s);
|
||||
LocalDateTime ldt = getLocalDateTimeFromHHmm(s, null); // use setDay instead
|
||||
this.timeFrom = ldt == null ? null : Timestamp.valueOf(ldt);
|
||||
}
|
||||
|
||||
@ -137,7 +145,7 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
}
|
||||
|
||||
public void setTimeUntilString(String s) {
|
||||
LocalDateTime ldt = getLocalDateTimeFromHHmm(s);
|
||||
LocalDateTime ldt = getLocalDateTimeFromHHmm(s, null); // use setDay instead
|
||||
this.timeUntil = ldt == null ? null : Timestamp.valueOf(ldt);
|
||||
}
|
||||
|
||||
|
@ -167,6 +167,8 @@ public class DoneModel implements Model, Serializable {
|
||||
|
||||
public boolean update(JooqFacesContext facesContext) {
|
||||
try {
|
||||
// day contains the correct date; with that, refresh the current date after possibly changing the day
|
||||
bean.setDay(day);
|
||||
new DoneGateway(facesContext).update(bean);
|
||||
return true;
|
||||
} catch (DataAccessException | ClassNotFoundException | SQLException e) {
|
||||
@ -254,6 +256,10 @@ public class DoneModel implements Model, Serializable {
|
||||
return times;
|
||||
}
|
||||
|
||||
public String getGermanFormattedDay() {
|
||||
return day == null ? "null" : new SimpleDateFormat("EEEE, dd.MMMM yyyy").format(day);
|
||||
}
|
||||
|
||||
public Date getDay() {
|
||||
return day;
|
||||
}
|
||||
|
Reference in New Issue
Block a user