Skip to content

Commit

Permalink
workaround Android problem with Date
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Oct 27, 2020
1 parent 398c20f commit 760cc3b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void testOnlyOpen()
public void testByClosedAfter() throws ParseException
{
QueryChangesetsFilters filters = new QueryChangesetsFilters();
Date validDate = dateFormat.parse("2222-11-22T22:11:00+0700");
Date validDate = dateFormat.parse("2222-11-22T22:11:00Z");
filters.byClosedAfter(validDate);

assertEquals(validDate, dateFormat.parse(getParam(filters.toParamString(), "time")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/** Format used to represent dates within the OSM Api 0.6 (except notes)*/
public class OsmXmlDateFormat
{
private static final SimpleDateFormat DEFAULT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
private static final SimpleDateFormat DEFAULT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
static {
DEFAULT.setTimeZone(TimeZone.getTimeZone("UTC"));
}

public Date parse(String source) throws ParseException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testIllegalLimit()
public void testCreatedBefore() throws ParseException
{
QueryNotesFilters filters = new QueryNotesFilters();
Date validDate = dateFormat.parse("2222-11-22T22:11:00+0700");
Date validDate = dateFormat.parse("2222-11-22T22:11:00Z");
filters.createdBefore(validDate);

assertEquals(validDate, dateFormat.parse(getParam(filters.toParamString(), "to")));
Expand All @@ -95,7 +95,7 @@ public void testCreatedBefore() throws ParseException
public void testCreatedAfter() throws ParseException
{
QueryNotesFilters filters = new QueryNotesFilters();
Date validDate = dateFormat.parse("2222-11-22T22:11:00+0700");
Date validDate = dateFormat.parse("2222-11-22T22:11:00Z");
filters.createdAfter(validDate);

assertEquals(validDate, dateFormat.parse(getParam(filters.toParamString(), "from")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Pattern;

import de.westnordost.osmapi.common.Iso8601CompatibleDateFormat;
import de.westnordost.osmapi.common.OsmXmlDateFormat;

/** Gpx timestamps can optionally include milliseconds */
public class GpxDateFormat extends OsmXmlDateFormat
{
private static final SimpleDateFormat MILLIS = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");

private static final SimpleDateFormat MILLIS = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
static {
MILLIS.setTimeZone(TimeZone.getTimeZone("UTC"));
}

private static final Pattern MILLIS_PATTERN = Pattern.compile("\\.[0-9]{3}");
private static boolean hasMillis(String source)
{
Expand Down

0 comments on commit 760cc3b

Please sign in to comment.