This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 883b60e269979a5ea1ad509d0332c3da16646d89 Author: Eric Chatellier <chatellier@codelutin.com> Date: Wed Aug 3 10:05:02 2016 +0200 Fix tests --- .../jtimer/plugin/timebundle/TimeBundleHelper.java | 29 +++++++++++----------- .../plugin/timebundle/TimeBundleHelperTest.java | 29 +++++++++------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java index 8082470..00d0e54 100644 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java +++ b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java @@ -23,7 +23,9 @@ package org.chorem.jtimer.plugin.timebundle; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; +import org.apache.commons.lang3.time.DurationFormatUtils; import org.chorem.jtimer.entities.TimerSync; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; @@ -41,6 +43,8 @@ import java.util.SortedMap; */ public class TimeBundleHelper { + protected static final String DATE_MIDNIGHT_PATTERN = "yyyy-MM-dd'T'00:00:00XXX"; + /** * Returns all the subtasks of a task (including the subtaks of subtasks). * @@ -70,19 +74,16 @@ public class TimeBundleHelper { JsonArray periodArray = new JsonArray(); Date startDate = sync.getLastSync(); Date endDate = DateUtils.ceiling(new Date(), Calendar.DAY_OF_MONTH); - String timestamp = "T00:00:00+00:00"; // why +1 ? - SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); - LocalDate startPeriodDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - String startPeriodString = startPeriodDate.toString() + timestamp; - LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - String endPeriodString = endPeriodDate.toString() + timestamp; + String startPeriodString = DateFormatUtils.format(startDate, DATE_MIDNIGHT_PATTERN); + String endPeriodString = DateFormatUtils.format(endDate, DATE_MIDNIGHT_PATTERN); + //get the times of the task - periodArray.addAll(getTimesAsJsonArray(task, startDate, endDate, sync.isWithAnnotations(), timestamp)); + periodArray.addAll(getTimesAsJsonArray(task, startDate, endDate, sync.isWithAnnotations())); //if there are subtasks, get the times of the subtasks that have no syncInfo if (!task.getSubTasks().isEmpty()) { for (TimerTask subtask : getAllSubTasks(task)) { if (subtask.getSyncs().isEmpty()) { - periodArray.addAll(getTimesAsJsonArray(subtask, startDate, endDate, sync.isWithAnnotations(), timestamp)); + periodArray.addAll(getTimesAsJsonArray(subtask, startDate, endDate, sync.isWithAnnotations())); } } } @@ -105,21 +106,19 @@ public class TimeBundleHelper { * @param startDate * @param endDate * @param withAnnotations - * @param timestamp * @return a JsonArray of the periods */ - public static JsonArray getTimesAsJsonArray(TimerTask task, Date startDate, Date endDate, boolean withAnnotations, String timestamp) { + public static JsonArray getTimesAsJsonArray(TimerTask task, Date startDate, Date endDate, boolean withAnnotations) { JsonArray periodArray = new JsonArray(); SortedMap<Date, Long> dates = task.getAllDaysAndTimes().subMap(startDate, endDate); for (SortedMap.Entry<Date, Long> entry : dates.entrySet()) { //adding id, startDate and duration - //converting Date to LocalDate (to ease the .toString()) - LocalDate date = entry.getKey().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - String dateString = date.toString(); + String dateString = DateFormatUtils.format(entry.getKey(), DATE_MIDNIGHT_PATTERN); //as jtimer has time entries only for a day, the id of the times will be the date in yyyy-mm-dd format + String idString = DateFormatUtils.format(entry.getKey(), "yyyy-MM-dd"); JsonObject periodElement = new JsonObject(); - periodElement.addProperty("id", dateString + "_" + task.getNumber()); - periodElement.addProperty("startDate", dateString + timestamp); + periodElement.addProperty("id", idString + "_" + task.getNumber()); + periodElement.addProperty("startDate", dateString); //TimerTaskHelper.getTotalTime(task, entry.getKey()) to get the total time of the task and all the subtasks //entry.getValue() to get only the time of the task divided by 1000 (jtimer stores milliseconds) periodElement.addProperty("duration", entry.getValue() / 1000); diff --git a/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java b/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java index 3bdb517..fc0d91a 100644 --- a/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java +++ b/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java @@ -23,6 +23,7 @@ package org.chorem.jtimer.plugin.timebundle; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.chorem.jtimer.AbstractJTimerTest; import org.chorem.jtimer.entities.TimerSync; @@ -46,14 +47,15 @@ public class TimeBundleHelperTest extends AbstractJTimerTest { @Test public void taskToJSONFormatTest() { TimerTask task = new TimerTask(); + task.setNumber(42); task.setName("JsonBuilder Test"); TimerSync sync = new TimerSync("http://localhost:3000"); task.addSync(sync); //set the creation date at same date as first timing date (to fit test object) - task.setCreationDate(new Date(1462831200000L)); - sync.setLastSync(new Date(1462831200000L)); - //date : 2016-05-10 - task.setTime(new Date(1462831200000L), 452000L); + task.setCreationDate(new Date(1451602800000L)); + sync.setLastSync(new Date(1451602800000L)); + //date : 2016-01-18 + task.setTime(new Date(1453071600000L), 452000L); //date : 2016-05-12 task.setTime(new Date(1463004000000L), 4533000L); @@ -62,33 +64,26 @@ public class TimeBundleHelperTest extends AbstractJTimerTest { JsonObject objectToHave = new JsonObject(); JsonArray periodArray = new JsonArray(); JsonObject periodElement1 = new JsonObject(); - //id is date+_+task.number, here -1 - periodElement1.addProperty("id", "2016-05-10_-1"); - periodElement1.addProperty("startDate", "2016-05-10T00:00:00+01:00"); + periodElement1.addProperty("id", "2016-01-18_42"); + periodElement1.addProperty("startDate", "2016-01-18T00:00:00+01:00"); periodElement1.addProperty("duration", 452); periodArray.add(periodElement1); JsonObject periodElement2 = new JsonObject(); - periodElement2.addProperty("id", "2016-05-12_-1"); - periodElement2.addProperty("startDate", "2016-05-12T00:00:00+01:00"); + periodElement2.addProperty("id", "2016-05-12_42"); + periodElement2.addProperty("startDate", "2016-05-12T00:00:00+02:00"); periodElement2.addProperty("duration", 4533); periodArray.add(periodElement2); objectToHave.addProperty("URL", "http://localhost:3000"); - //startDate corresponds to lastSync in taksToJsonObject - objectToHave.addProperty("startDate", "2016-05-10T00:00:00+01:00"); - //endDate is nextday (from currenttime) + objectToHave.addProperty("startDate", "2016-01-01T00:00:00+01:00"); Date endDate = DateUtils.ceiling(new Date(), Calendar.DAY_OF_MONTH); - String timestamp = "T00:00:00+01:00"; - LocalDate endPeriodDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - String endPeriodString = endPeriodDate.toString() + timestamp; + String endPeriodString = DateFormatUtils.format(endDate, TimeBundleHelper.DATE_MIDNIGHT_PATTERN); objectToHave.addProperty("endDate", endPeriodString); objectToHave.add("periods", periodArray); - //make a list of json objects from the task JsonObject jsonObject = TimeBundleHelper.taskToJsonObject(task, sync); - //compare it Assert.assertEquals(jsonObject, objectToHave); } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.