mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-17 18:39:50 +00:00
fix date rollovers
more lines git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@306 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
641bd33749
commit
f5210b4dcf
1 changed files with 73 additions and 32 deletions
|
@ -24,7 +24,9 @@ import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -247,7 +249,8 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
XmlPullUtil.require(pp, "Overview");
|
XmlPullUtil.require(pp, "Overview");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
XmlPullUtil.require(pp, "Date");
|
XmlPullUtil.require(pp, "Date");
|
||||||
final Date currentDate = DATE_FORMAT.parse(XmlPullUtil.text(pp));
|
final Calendar currentDate = new GregorianCalendar();
|
||||||
|
currentDate.setTime(DATE_FORMAT.parse(XmlPullUtil.text(pp)));
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
XmlPullUtil.require(pp, "ConSectionList");
|
XmlPullUtil.require(pp, "ConSectionList");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
|
@ -278,7 +281,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
XmlPullUtil.require(pp, "Dep");
|
XmlPullUtil.require(pp, "Dep");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
XmlPullUtil.require(pp, "Time");
|
XmlPullUtil.require(pp, "Time");
|
||||||
final Date departureTime = ParserUtils.joinDateTime(currentDate, TIME_FORMAT.parse(XmlPullUtil.text(pp).substring(3, 8)));
|
final Date departureTime = parseTime(currentDate, XmlPullUtil.text(pp));
|
||||||
XmlPullUtil.require(pp, "Platform");
|
XmlPullUtil.require(pp, "Platform");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
XmlPullUtil.require(pp, "Text");
|
XmlPullUtil.require(pp, "Text");
|
||||||
|
@ -307,27 +310,35 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
String name = null;
|
String name = null;
|
||||||
String category = null;
|
String category = null;
|
||||||
|
String longCategory = null;
|
||||||
while (XmlPullUtil.test(pp, "JourneyAttribute"))
|
while (XmlPullUtil.test(pp, "JourneyAttribute"))
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
XmlPullUtil.require(pp, "Attribute");
|
XmlPullUtil.require(pp, "Attribute");
|
||||||
final String attrName = XmlPullUtil.attr(pp, "type");
|
final String attrName = XmlPullUtil.attr(pp, "type");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
final String attrValue = parseAttributeVariant(pp, "NORMAL");
|
final Map<String, String> attributeVariants = parseAttributeVariants(pp);
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
|
|
||||||
if ("NAME".equals(attrName))
|
if ("NAME".equals(attrName))
|
||||||
name = attrValue;
|
{
|
||||||
|
name = attributeVariants.get("NORMAL");
|
||||||
|
}
|
||||||
else if ("CATEGORY".equals(attrName))
|
else if ("CATEGORY".equals(attrName))
|
||||||
category = attrValue;
|
{
|
||||||
|
category = attributeVariants.get("NORMAL");
|
||||||
|
longCategory = attributeVariants.get("LONG");
|
||||||
|
}
|
||||||
else if ("DIRECTION".equals(attrName))
|
else if ("DIRECTION".equals(attrName))
|
||||||
direction = attrValue;
|
{
|
||||||
|
direction = attributeVariants.get("NORMAL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
|
|
||||||
line = _normalizeLine(category, name);
|
line = _normalizeLine(category, name, longCategory);
|
||||||
}
|
}
|
||||||
else if (tag.equals("Walk") || tag.equals("Transfer"))
|
else if (tag.equals("Walk") || tag.equals("Transfer"))
|
||||||
{
|
{
|
||||||
|
@ -362,7 +373,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
XmlPullUtil.require(pp, "Arr");
|
XmlPullUtil.require(pp, "Arr");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
XmlPullUtil.require(pp, "Time");
|
XmlPullUtil.require(pp, "Time");
|
||||||
final Date arrivalTime = ParserUtils.joinDateTime(currentDate, TIME_FORMAT.parse(XmlPullUtil.text(pp).substring(3, 8)));
|
final Date arrivalTime = parseTime(currentDate, XmlPullUtil.text(pp));
|
||||||
XmlPullUtil.require(pp, "Platform");
|
XmlPullUtil.require(pp, "Platform");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
XmlPullUtil.require(pp, "Text");
|
XmlPullUtil.require(pp, "Text");
|
||||||
|
@ -432,26 +443,46 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String parseAttributeVariant(final XmlPullParser pp, final String type) throws XmlPullParserException, IOException
|
private final Map<String, String> parseAttributeVariants(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
String value = null;
|
final Map<String, String> attributeVariants = new HashMap<String, String>();
|
||||||
|
|
||||||
while (XmlPullUtil.test(pp, "AttributeVariant"))
|
while (XmlPullUtil.test(pp, "AttributeVariant"))
|
||||||
{
|
{
|
||||||
if (type.equals(XmlPullUtil.attr(pp, "type")))
|
final String type = XmlPullUtil.attr(pp, "type");
|
||||||
{
|
XmlPullUtil.enter(pp);
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.require(pp, "Text");
|
||||||
XmlPullUtil.require(pp, "Text");
|
final String value = XmlPullUtil.text(pp).trim();
|
||||||
value = XmlPullUtil.text(pp).trim();
|
XmlPullUtil.exit(pp);
|
||||||
XmlPullUtil.exit(pp);
|
|
||||||
}
|
attributeVariants.put(type, value);
|
||||||
else
|
|
||||||
{
|
|
||||||
XmlPullUtil.next(pp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return attributeVariants;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Pattern P_TIME = Pattern.compile("(\\d+)d(\\d+):(\\d{2}):(\\d{2})");
|
||||||
|
|
||||||
|
private Date parseTime(final Calendar currentDate, final String str)
|
||||||
|
{
|
||||||
|
final Matcher m = P_TIME.matcher(str);
|
||||||
|
if (m.matches())
|
||||||
|
{
|
||||||
|
final Calendar c = new GregorianCalendar();
|
||||||
|
c.set(Calendar.YEAR, currentDate.get(Calendar.YEAR));
|
||||||
|
c.set(Calendar.MONTH, currentDate.get(Calendar.MONTH));
|
||||||
|
c.set(Calendar.DAY_OF_MONTH, currentDate.get(Calendar.DAY_OF_MONTH));
|
||||||
|
c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(2)));
|
||||||
|
c.set(Calendar.MINUTE, Integer.parseInt(m.group(3)));
|
||||||
|
c.set(Calendar.SECOND, Integer.parseInt(m.group(4)));
|
||||||
|
c.set(Calendar.MILLISECOND, 0);
|
||||||
|
c.add(Calendar.DAY_OF_MONTH, Integer.parseInt(m.group(1)));
|
||||||
|
return c.getTime();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("cannot parse duration: " + str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern P_DURATION = Pattern.compile("(\\d+):(\\d{2})");
|
private static final Pattern P_DURATION = Pattern.compile("(\\d+):(\\d{2})");
|
||||||
|
@ -475,39 +506,49 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
throw new IllegalArgumentException("cannot handle: " + location.toDebugString());
|
throw new IllegalArgumentException("cannot handle: " + location.toDebugString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String _normalizeLine(final String type, final String name)
|
private final String _normalizeLine(final String type, final String name, final String longCategory)
|
||||||
{
|
{
|
||||||
final String normalizedType = type.split(" ", 2)[0];
|
final String normalizedType = type.split(" ", 2)[0];
|
||||||
final String normalizedName = normalizeWhitespace(name);
|
final String normalizedName = normalizeWhitespace(name);
|
||||||
|
|
||||||
if ("THALYS".equals(normalizedType))
|
if ("EN".equals(normalizedType))
|
||||||
|
return "I" + normalizedName;
|
||||||
|
if ("ICE".equals(normalizedType)) // InterCityExpress
|
||||||
return "I" + normalizedName;
|
return "I" + normalizedName;
|
||||||
if ("IC".equals(normalizedType))
|
if ("IC".equals(normalizedType))
|
||||||
return "I" + normalizedName;
|
return "I" + normalizedName;
|
||||||
if ("EN".equals(normalizedType))
|
if ("CNL".equals(normalizedType)) // CityNightLine
|
||||||
return "I" + normalizedName;
|
return "I" + normalizedName;
|
||||||
if ("OEC".equals(normalizedType))
|
if ("OEC".equals(normalizedType))
|
||||||
return "I" + normalizedName;
|
return "I" + normalizedName;
|
||||||
|
if ("OIC".equals(normalizedType))
|
||||||
|
return "I" + normalizedName;
|
||||||
|
if ("THALYS".equals(normalizedType))
|
||||||
|
return "I" + normalizedName;
|
||||||
|
|
||||||
if ("R".equals(normalizedType))
|
if ("R".equals(normalizedType)) // Regio
|
||||||
return "R" + normalizedName;
|
return "R" + normalizedName;
|
||||||
if ("RE".equals(normalizedType))
|
if ("RE".equals(normalizedType))
|
||||||
return "R" + normalizedName;
|
return "R" + normalizedName;
|
||||||
if ("IR".equals(normalizedType))
|
if ("IR".equals(normalizedType))
|
||||||
return "R" + normalizedName;
|
return "R" + normalizedName;
|
||||||
|
|
||||||
if ("Tramway".equals(normalizedType))
|
if ("S".equals(normalizedType)) // S-Bahn
|
||||||
return "T" + normalizedName;
|
return "S" + normalizedName;
|
||||||
|
|
||||||
if ("BUS".equals(normalizedType))
|
if ("Tramway".equals(normalizedType))
|
||||||
return "B" + normalizedName;
|
return "T" + normalizedName;
|
||||||
|
|
||||||
|
if ("BUS".equals(normalizedType))
|
||||||
|
return "B" + normalizedName;
|
||||||
|
|
||||||
if ("L".equals(normalizedType))
|
if ("L".equals(normalizedType))
|
||||||
return "?" + normalizedName;
|
return "?" + normalizedName;
|
||||||
if ("NZ".equals(normalizedType))
|
if ("NZ".equals(normalizedType)) // Nacht-Zug
|
||||||
return "?" + normalizedName;
|
return "?" + normalizedName;
|
||||||
|
|
||||||
throw new IllegalStateException("cannot normalize type '" + normalizedType + "' (" + type + ") name '" + normalizedName + "'");
|
throw new IllegalStateException("cannot normalize type '" + normalizedType + "' (" + type + ") name '" + normalizedName + "' longCategory '"
|
||||||
|
+ longCategory + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Pattern P_WHITESPACE = Pattern.compile("\\s+");
|
private final static Pattern P_WHITESPACE = Pattern.compile("\\s+");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue