Skip to content

Commit

Permalink
simplify code, improve architecture, remove bug
Browse files Browse the repository at this point in the history
DateUtil function getOffsetDateStringFromDate was modyfying passed object
now it is fixed
  • Loading branch information
matkoniecz committed Apr 9, 2018
1 parent 242124b commit f0c6031
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f0c6031

Please sign in to comment.