bugfix: editing the day didn't work for not today dates

This commit is contained in:
2020-01-17 15:04:12 +01:00
parent 7548ba6986
commit bb558531df
5 changed files with 38 additions and 19 deletions

View File

@ -20,11 +20,16 @@
</classpathentry> </classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/java"> <classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes> <attributes>
<attribute name="test" value="true"/>
<attribute name="gradle_scope" value="test"/> <attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/> <attribute name="gradle_used_by_scope" value="test"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"> <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
<attributes> <attributes>

View File

@ -22,7 +22,7 @@ apply plugin: 'eclipse'
apply plugin: 'nu.studer.jooq' apply plugin: 'nu.studer.jooq'
group = 'jottyfan' group = 'jottyfan'
version = '1.0.9' version = '1.1.0'
description = """timetrack""" description = """timetrack"""

View File

@ -90,9 +90,18 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
return String.format("%02d:%02d", diff.toHours(), diff.toMinutes() % 60); 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()) { if (s == null || s.trim().isEmpty()) {
return null; return null;
} else if (ldt == null) {
ldt = LocalDateTime.now();
} }
String[] hm = s.split(":"); String[] hm = s.split(":");
Integer hours = 0; Integer hours = 0;
@ -103,7 +112,6 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
if (hm.length > 1) { if (hm.length > 1) {
minutes = Integer.valueOf(hm[1]); minutes = Integer.valueOf(hm[1]);
} }
LocalDateTime ldt = LocalDateTime.now();
ldt = ldt.withHour(hours); ldt = ldt.withHour(hours);
ldt = ldt.withMinute(minutes); ldt = ldt.withMinute(minutes);
ldt = ldt.withSecond(0); ldt = ldt.withSecond(0);
@ -128,7 +136,7 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
} }
public void setTimeFromString(String s) { 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); 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) { 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); this.timeUntil = ldt == null ? null : Timestamp.valueOf(ldt);
} }

View File

@ -167,6 +167,8 @@ public class DoneModel implements Model, Serializable {
public boolean update(JooqFacesContext facesContext) { public boolean update(JooqFacesContext facesContext) {
try { 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); new DoneGateway(facesContext).update(bean);
return true; return true;
} catch (DataAccessException | ClassNotFoundException | SQLException e) { } catch (DataAccessException | ClassNotFoundException | SQLException e) {
@ -254,6 +256,10 @@ public class DoneModel implements Model, Serializable {
return times; return times;
} }
public String getGermanFormattedDay() {
return day == null ? "null" : new SimpleDateFormat("EEEE, dd.MMMM yyyy").format(day);
}
public Date getDay() { public Date getDay() {
return day; return day;
} }

View File

@ -24,19 +24,19 @@ public class TestDoneBean {
public void testGetLocalDateTimeFromHHmm() { public void testGetLocalDateTimeFromHHmm() {
LocalDateTime ldt = LocalDateTime.now(); LocalDateTime ldt = LocalDateTime.now();
ldt = ldt.withSecond(0).withNano(0); ldt = ldt.withSecond(0).withNano(0);
assertEquals(ldt.withHour(0).withMinute(0), new DoneBean().getLocalDateTimeFromHHmm("0:0")); assertEquals(ldt.withHour(0).withMinute(0), new DoneBean().getLocalDateTimeFromHHmm("0:0", LocalDateTime.now()));
assertEquals(ldt.withHour(0).withMinute(5), new DoneBean().getLocalDateTimeFromHHmm("0:5")); assertEquals(ldt.withHour(0).withMinute(5), new DoneBean().getLocalDateTimeFromHHmm("0:5", LocalDateTime.now()));
assertEquals(ldt.withHour(3).withMinute(2), new DoneBean().getLocalDateTimeFromHHmm("3:2")); assertEquals(ldt.withHour(3).withMinute(2), new DoneBean().getLocalDateTimeFromHHmm("3:2", LocalDateTime.now()));
assertEquals(ldt.withHour(3).withMinute(2), new DoneBean().getLocalDateTimeFromHHmm("03:2")); assertEquals(ldt.withHour(3).withMinute(2), new DoneBean().getLocalDateTimeFromHHmm("03:2", LocalDateTime.now()));
assertEquals(ldt.withHour(10).withMinute(2), new DoneBean().getLocalDateTimeFromHHmm("10:2")); assertEquals(ldt.withHour(10).withMinute(2), new DoneBean().getLocalDateTimeFromHHmm("10:2", LocalDateTime.now()));
assertEquals(ldt.withHour(12).withMinute(2), new DoneBean().getLocalDateTimeFromHHmm("12:02")); assertEquals(ldt.withHour(12).withMinute(2), new DoneBean().getLocalDateTimeFromHHmm("12:02", LocalDateTime.now()));
assertEquals(ldt.withHour(12).withMinute(20), new DoneBean().getLocalDateTimeFromHHmm("12:20")); assertEquals(ldt.withHour(12).withMinute(20), new DoneBean().getLocalDateTimeFromHHmm("12:20", LocalDateTime.now()));
assertEquals(null, new DoneBean().getLocalDateTimeFromHHmm(null)); assertEquals(null, new DoneBean().getLocalDateTimeFromHHmm(null, LocalDateTime.now()));
assertEquals(null, new DoneBean().getLocalDateTimeFromHHmm("")); assertEquals(null, new DoneBean().getLocalDateTimeFromHHmm("", LocalDateTime.now()));
assertEquals(null, new DoneBean().getLocalDateTimeFromHHmm(" ")); assertEquals(null, new DoneBean().getLocalDateTimeFromHHmm(" ", LocalDateTime.now()));
assertEquals(ldt.withHour(0).withMinute(0), new DoneBean().getLocalDateTimeFromHHmm("0")); assertEquals(ldt.withHour(0).withMinute(0), new DoneBean().getLocalDateTimeFromHHmm("0", LocalDateTime.now()));
assertEquals(ldt.withHour(1).withMinute(0), new DoneBean().getLocalDateTimeFromHHmm("1")); assertEquals(ldt.withHour(1).withMinute(0), new DoneBean().getLocalDateTimeFromHHmm("1", LocalDateTime.now()));
assertEquals(ldt.withHour(5).withMinute(0), new DoneBean().getLocalDateTimeFromHHmm("5")); assertEquals(ldt.withHour(5).withMinute(0), new DoneBean().getLocalDateTimeFromHHmm("5", LocalDateTime.now()));
} }
@Test @Test