From f0c6031c68e1cd6ab9b851fba3d860655d2431eb Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Mon, 9 Apr 2018 15:10:04 +0200 Subject: [PATCH] simplify code, improve architecture, remove bug DateUtil function getOffsetDateStringFromDate was modyfying passed object now it is fixed --- .../MarkCompletedBuildingConstructionOldData.java | 10 ++++------ .../MarkCompletedHighwayConstructionOldData.java | 10 ++++------ .../westnordost/streetcomplete/quests/DateUtil.java | 12 +++++++----- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/construction/MarkCompletedBuildingConstructionOldData.java b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/construction/MarkCompletedBuildingConstructionOldData.java index 876dab35b9..956d70ff82 100644 --- a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/construction/MarkCompletedBuildingConstructionOldData.java +++ b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/construction/MarkCompletedBuildingConstructionOldData.java @@ -9,21 +9,19 @@ import de.westnordost.streetcomplete.quests.DateUtil; public class MarkCompletedBuildingConstructionOldData extends MarkCompletedBuildingConstruction { - private Calendar dateCalendar; + private Date date; MarkCompletedBuildingConstructionOldData(OverpassMapDataDao overpassServer, String dateString) throws ParseException { super(overpassServer); - Date date = DateUtil.basicISO8601().parse(dateString); - dateCalendar = Calendar.getInstance(); - dateCalendar.setTime(date); + date = DateUtil.basicISO8601().parse(dateString); } @Override protected String getCurrentDateString(){ - return DateUtil.getOffsetDateStringFromDate(0, dateCalendar) + "T00:00:00Z"; + return DateUtil.getOffsetDateStringFromDate(0, date) + "T00:00:00Z"; } @Override protected String getOffsetDateString(int offset){ - return DateUtil.getOffsetDateStringFromDate(offset, dateCalendar) + "T00:00:00Z"; + return DateUtil.getOffsetDateStringFromDate(offset, date) + "T00:00:00Z"; } } diff --git a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/construction/MarkCompletedHighwayConstructionOldData.java b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/construction/MarkCompletedHighwayConstructionOldData.java index 780ceefbed..8f63893ca9 100644 --- a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/construction/MarkCompletedHighwayConstructionOldData.java +++ b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/construction/MarkCompletedHighwayConstructionOldData.java @@ -9,21 +9,19 @@ import de.westnordost.streetcomplete.quests.DateUtil; public class MarkCompletedHighwayConstructionOldData extends MarkCompletedHighwayConstruction { - private Calendar dateCalendar; + private Date date; MarkCompletedHighwayConstructionOldData(OverpassMapDataDao overpassServer, String dateString) throws ParseException { super(overpassServer); - Date date = DateUtil.basicISO8601().parse(dateString); - dateCalendar = Calendar.getInstance(); - dateCalendar.setTime(date); + date = DateUtil.basicISO8601().parse(dateString); } @Override protected String getCurrentDateString(){ - return DateUtil.getOffsetDateStringFromDate(0, dateCalendar) + "T00:00:00Z"; + return DateUtil.getOffsetDateStringFromDate(0, date) + "T00:00:00Z"; } @Override protected String getOffsetDateString(int offset){ - return DateUtil.getOffsetDateStringFromDate(offset, dateCalendar) + "T00:00:00Z"; + return DateUtil.getOffsetDateStringFromDate(offset, date) + "T00:00:00Z"; } } diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/DateUtil.java b/app/src/main/java/de/westnordost/streetcomplete/quests/DateUtil.java index 38a5fbabea..c44f74124e 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/DateUtil.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/DateUtil.java @@ -2,20 +2,22 @@ import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Date; public class DateUtil { public static SimpleDateFormat basicISO8601(){ return new SimpleDateFormat("yyyy-MM-dd"); } - - public static String getOffsetDateStringFromDate(int offsetInDays, Calendar cal){ - cal.add(Calendar.DAY_OF_MONTH, offsetInDays); - return basicISO8601().format(cal.getTime()); + public static String getOffsetDateStringFromDate(final int offsetInDays, final Date date){ + Calendar modifiedCalendar = Calendar.getInstance(); + modifiedCalendar.setTime(date); + modifiedCalendar.add(Calendar.DAY_OF_MONTH, offsetInDays); + return basicISO8601().format(modifiedCalendar.getTime()); } public static String getOffsetDateString(int offsetInDays){ - return getOffsetDateStringFromDate(offsetInDays, Calendar.getInstance()); + return getOffsetDateStringFromDate(offsetInDays, Calendar.getInstance().getTime()); } public static String getCurrentDateString() {