List of usage examples for java.util Calendar isSet
boolean isSet
To view the source code for java.util Calendar isSet.
Click Source Link
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); boolean b = cal.isSet(Calendar.DAY_OF_MONTH); System.out.println("Day of month is set: " + b); // clear day of month cal.clear(Calendar.DAY_OF_MONTH); // determine if the given calendar field has a value set b = cal.isSet(Calendar.DAY_OF_MONTH); System.out.println("Day of month is set: " + b); }
From source file:org.apache.jena.atlas.lib.DateTimeUtils.java
private static boolean hasZeroMilliSeconds(Calendar cal) { return !cal.isSet(Calendar.MILLISECOND) || cal.get(Calendar.MILLISECOND) == 0; }
From source file:org.ow2.aspirerfid.queryandcapture.ui.MasterDataQueryAndCaptureGui.java
/** * Formats a <code>Calendar</code> value into an ISO8601-compliant date/time * string.//from w w w . ja v a 2 s. c o m * * @param cal * The time value to be formatted into a date/time string. * @return The formatted date/time string. */ private static String format(final Calendar cal) { if (cal == null) { throw new IllegalArgumentException("argument can not be null"); } // determine era and adjust year if necessary int year = cal.get(Calendar.YEAR); if (cal.isSet(Calendar.ERA) && cal.get(Calendar.ERA) == GregorianCalendar.BC) { /** * calculate year using astronomical system: year n BCE => * astronomical year -n + 1 */ year = 0 - year + 1; } /** * the format of the date/time string is: YYYY-MM-DDThh:mm:ss.SSSTZD * note that we cannot use java.text.SimpleDateFormat for formatting * because it can't handle years <= 0 and TZD's */ StringBuilder buf = new StringBuilder(); // year ([-]YYYY) buf.append(XXXX_FORMAT.format(year)); buf.append('-'); // month (MM) buf.append(XX_FORMAT.format(cal.get(Calendar.MONTH) + 1)); buf.append('-'); // day (DD) buf.append(XX_FORMAT.format(cal.get(Calendar.DAY_OF_MONTH))); buf.append('T'); // hour (hh) buf.append(XX_FORMAT.format(cal.get(Calendar.HOUR_OF_DAY))); buf.append(':'); // minute (mm) buf.append(XX_FORMAT.format(cal.get(Calendar.MINUTE))); buf.append(':'); // second (ss) buf.append(XX_FORMAT.format(cal.get(Calendar.SECOND))); buf.append('.'); // millisecond (SSS) buf.append(XXX_FORMAT.format(cal.get(Calendar.MILLISECOND))); // time zone designator (+/-hh:mm) buf.append(getTimeZone(cal)); return buf.toString(); }
From source file:edu.wisc.my.stats.query.support.UWDataWareHouseInformationProvider.java
public long getTimeStamp(ResultSet rs, TimeResolution resolution) throws SQLException { final Calendar timeStampCal = Calendar.getInstance(); timeStampCal.clear();// w w w . j ava 2 s .com switch (resolution) { case MINUTE: final int minutes = rs.getInt("MINUTE"); timeStampCal.set(Calendar.MINUTE, minutes); case FIVE_MINUTE: if (!timeStampCal.isSet(Calendar.MINUTE)) { final int fiveMinutes = rs.getInt("FIVE_MINUTE_INCREMENT"); timeStampCal.set(Calendar.MINUTE, (fiveMinutes - 1) * 5); } case HOUR: final int hours = rs.getInt("HOUR"); timeStampCal.set(Calendar.HOUR, hours); case DAY: final int days = rs.getInt("CALENDAR_DAY_NUMBER"); timeStampCal.set(Calendar.DAY_OF_MONTH, days); case WEEK: final int week = rs.getInt("CALENDAR_WEEK_NUMBER"); timeStampCal.set(Calendar.WEEK_OF_YEAR, week); case MONTH: final int months = rs.getInt("CALENDAR_MONTH_NUMBER"); timeStampCal.set(Calendar.MONTH, months - 1); //Dang 0 based months case YEAR: final int years = rs.getInt("CALENDAR_YEAR_NUMBER"); timeStampCal.set(Calendar.YEAR, years); } return timeStampCal.getTimeInMillis(); }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static String convertToString(Date value) { if (isCustomClassPresent) { // this means user has define a seperate converter util class return invokeToStringMethod(value, Date.class); } else {/*from ww w . ja v a2 s.c o m*/ // lexical form of the date is '-'? yyyy '-' mm '-' dd zzzzzz? Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(value); if (!calendar.isSet(Calendar.ZONE_OFFSET)) { calendar.setTimeZone(TimeZone.getDefault()); } StringBuffer dateString = new StringBuffer(16); appendDate(dateString, calendar); appendTimeZone(calendar, dateString); return dateString.toString(); } }
From source file:org.apache.jackrabbit.core.persistence.util.BundleWriter.java
/** * Serializes a JCR date value using the {@link #writeVarLong(long)} * serialization on a special 64-bit date encoding. This encoding maps * the <code>sYYYY-MM-DDThh:mm:ss.sssTZD</code> date format used by * JCR to an as small 64 bit integer (positive or negative) as possible, * while preserving full accuracy (including time zone offsets) and * favouring common levels of accuracy (per minute, hour and day) over * full millisecond level detail./*from w ww . j a v a 2 s . com*/ * <p> * Each date value is mapped to separate timestamp and timezone fields, * both of whose lenghts are variable: * <pre> * +----- ... ------- ... --+ * | timestamp | timezone | * +----- ... ------- ... --+ * </pre> * <p> * The type and length of the timezone field can be determined by looking * at the two least significant bits of the value: * <dl> * <dt><code>?0</code></dt> * <dd> * UTC time. The length of the timezone field is just one bit, * i.e. the second bit is already a part of the timestamp field. * </dd> * <dt><code>01</code></dt> * <dd> * The offset is counted as hours from UTC, and stored as the number * of hours (positive or negative) in the next 5 bits (range from * -16 to +15 hours), making the timezone field 7 bits long in total. * </dd> * <dt><code>11</code></dt> * <dd> * The offset is counted as hours and minutes from UTC, and stored * as the total minute offset (positive or negative) in the next * 11 bits (range from -17 to +17 hours), making the timezone field * 13 bits long in total. * </dd> * </dl> * <p> * The remaining 51-63 bits of the encoded value make up the timestamp * field that also uses the two least significant bits to indicate the * type and length of the field: * <dl> * <dt><code>00</code></dt> * <dd> * <code>sYYYY-MM-DDT00:00:00.000</code>, i.e. midnight of the * specified date. The next 9 bits encode the day within the year * (starting from 1, maximum value 366) and the remaining bits are * used for the year, stored as an offset from year 2010. * </dd> * <dt><code>01</code></dt> * <dd> * <code>sYYYY-MM-DDThh:00:00.000</code>, i.e. at the hour. The * next 5 bits encode the hour within the day (starting from 0, * maximum value 23) and the remaining bits are used as described * above for the date. * </dd> * <dt><code>10</code></dt> * <dd> * <code>sYYYY-MM-DDThh:mm:00.000</code>, i.e. at the minute. The * next 11 bits encode the minute within the day (starting from 0, * maximum value 1439) and the remaining bits are used as described * above for the date. * </dd> * <dt><code>11</code></dt> * <dd> * <code>sYYYY-MM-DDThh:mm:ss.sss</code>, i.e. full millisecond * accuracy. The next 30 bits encode the millisecond within the * day (starting from 0, maximum value 87839999) and the remaining * bits are used as described above for the date. * </dd> * </dl> * <p> * With full timezone and millisecond accuracies, this encoding leaves * 10 bits (64 - 9 - 30 - 2 - 11 - 2) for the date offset, which allows * for representation of all timestamps between years 1498 and 2521. * Timestamps outside this range and with a minute-level timezone offset * are automatically truncated to minute-level accuracy to support the * full range of years -9999 to 9999 specified in JCR. * <p> * Note that the year, day of year, and time of day values are stored * as separate bit sequences to avoid problems with changing leap second * or leap year definitions. Bit fields are used for better encoding and * decoding performance than what would be possible with the slightly more * space efficient mechanism of using multiplication and modulo divisions * to separate the different timestamp fields. * * @param value date value * @throws IOException if an I/O error occurs */ private void writeDate(Calendar value) throws IOException { int y = value.get(Calendar.YEAR); if (value.isSet(Calendar.ERA) && value.get(Calendar.ERA) == GregorianCalendar.BC) { y = 1 - y; // convert to an astronomical year } y -= 2010; // use a recent offset NOTE: do not change this! int d = value.get(Calendar.DAY_OF_YEAR); int h = value.get(Calendar.HOUR_OF_DAY); int m = value.get(Calendar.MINUTE); int s = value.get(Calendar.SECOND); int u = value.get(Calendar.MILLISECOND); int z = value.getTimeZone().getOffset(value.getTimeInMillis()) / (60 * 1000); int zh = z / 60; int zm = z - zh * 60; long ts = y << 9 | d & 0x01ff; if ((u != 0 || s != 0) && ((-512 <= y && y < 512) || zm == 0)) { ts <<= 30; ts |= (((h * 60 + m) * 60 + s) * 1000 + u) & 0x3fffffff; // 30 bits ts <<= 2; ts |= 3; } else if (m != 0) { ts <<= 11; ts |= (h * 60 + m) & 0x07ff; // 11 bits ts <<= 2; ts |= 2; } else if (h != 0) { ts <<= 5; ts |= h & 0x1f; // 5 bits ts <<= 2; ts |= 1; } else { ts <<= 2; } if (zm != 0) { ts <<= 11; ts |= z & 0x07ff; // 11 bits writeVarLong(ts << 2 | 3); } else if (zh != 0) { ts <<= 5; ts |= zh & 0x1f; // 5 bits writeVarLong(ts << 2 | 1); } else { writeVarLong(ts << 1); } }
From source file:DateTime.java
/** Formats the value as an RFC 3339 date/time string. */ public String toStringRfc3339() { StringBuilder sb = new StringBuilder(); Calendar dateTime = new GregorianCalendar(GMT); long localTime = value; Integer tzShift = this.tzShift; if (tzShift != null) { localTime += tzShift.longValue() * 60000; }/* w w w . j av a 2s. c o m*/ dateTime.setTimeInMillis(localTime); appendInt(sb, dateTime.get(Calendar.YEAR), 4); sb.append('-'); appendInt(sb, dateTime.get(Calendar.MONTH) + 1, 2); sb.append('-'); appendInt(sb, dateTime.get(Calendar.DAY_OF_MONTH), 2); if (!dateOnly) { sb.append('T'); appendInt(sb, dateTime.get(Calendar.HOUR_OF_DAY), 2); sb.append(':'); appendInt(sb, dateTime.get(Calendar.MINUTE), 2); sb.append(':'); appendInt(sb, dateTime.get(Calendar.SECOND), 2); if (dateTime.isSet(Calendar.MILLISECOND)) { sb.append('.'); appendInt(sb, dateTime.get(Calendar.MILLISECOND), 3); } } if (tzShift != null) { if (tzShift.intValue() == 0) { sb.append('Z'); } else { int absTzShift = tzShift.intValue(); if (tzShift > 0) { sb.append('+'); } else { sb.append('-'); absTzShift = -absTzShift; } int tzHours = absTzShift / 60; int tzMinutes = absTzShift % 60; appendInt(sb, tzHours, 2); sb.append(':'); appendInt(sb, tzMinutes, 2); } } return sb.toString(); }
From source file:de.schildbach.pte.AbstractEfaProvider.java
protected QueryDeparturesResult queryDeparturesMobile(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs) throws IOException { final HttpUrl.Builder url = departureMonitorEndpoint.newBuilder(); appendXsltDepartureMonitorRequestParameters(url, stationId, time, maxDepartures, equivs); final AtomicReference<QueryDeparturesResult> result = new AtomicReference<>(); final HttpClient.Callback callback = new HttpClient.Callback() { @Override/*from w w w . j a v a 2 s. com*/ public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(body.byteStream(), null); // Read encoding from XML declaration final ResultHeader header = enterEfa(pp); final QueryDeparturesResult r = new QueryDeparturesResult(header); XmlPullUtil.require(pp, "dps"); if (XmlPullUtil.optEnter(pp, "dps")) { final Calendar plannedDepartureTime = new GregorianCalendar(timeZone); final Calendar predictedDepartureTime = new GregorianCalendar(timeZone); while (XmlPullUtil.optEnter(pp, "dp")) { // misc /* final String stationName = */normalizeLocationName(XmlPullUtil.valueTag(pp, "n")); /* final boolean isRealtime = */XmlPullUtil.valueTag(pp, "realtime").equals("1"); XmlPullUtil.optSkip(pp, "dt"); // time parseMobileSt(pp, plannedDepartureTime, predictedDepartureTime); final LineDestination lineDestination = parseMobileM(pp, true); XmlPullUtil.enter(pp, "r"); final String assignedId = XmlPullUtil.valueTag(pp, "id"); XmlPullUtil.valueTag(pp, "a"); final Position position = parsePosition(XmlPullUtil.optValueTag(pp, "pl", null)); XmlPullUtil.skipExit(pp, "r"); /* final Point positionCoordinate = */parseCoord( XmlPullUtil.optValueTag(pp, "c", null)); // TODO messages StationDepartures stationDepartures = findStationDepartures(r.stationDepartures, assignedId); if (stationDepartures == null) { stationDepartures = new StationDepartures( new Location(LocationType.STATION, assignedId), new ArrayList<Departure>(maxDepartures), null); r.stationDepartures.add(stationDepartures); } stationDepartures.departures.add(new Departure(plannedDepartureTime.getTime(), predictedDepartureTime.isSet(Calendar.HOUR_OF_DAY) ? predictedDepartureTime.getTime() : null, lineDestination.line, position, lineDestination.destination, null, null)); XmlPullUtil.skipExit(pp, "dp"); } XmlPullUtil.skipExit(pp, "dps"); result.set(r); } else { result.set(new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION)); } } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } } }; if (httpPost) httpClient.getInputStream(callback, url.build(), url.build().encodedQuery(), "application/x-www-form-urlencoded", httpReferer); else httpClient.getInputStream(callback, url.build(), httpReferer); return result.get(); }
From source file:de.schildbach.pte.AbstractEfaProvider.java
private QueryDeparturesResult xsltDepartureMonitorRequest(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs) throws IOException { final HttpUrl.Builder url = departureMonitorEndpoint.newBuilder(); appendXsltDepartureMonitorRequestParameters(url, stationId, time, maxDepartures, equivs); final AtomicReference<QueryDeparturesResult> result = new AtomicReference<>(); final HttpClient.Callback callback = new HttpClient.Callback() { @Override// ww w . j a v a 2 s. c o m public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(body.byteStream(), null); // Read encoding from XML declaration final ResultHeader header = enterItdRequest(pp); final QueryDeparturesResult r = new QueryDeparturesResult(header); XmlPullUtil.enter(pp, "itdDepartureMonitorRequest"); XmlPullUtil.optSkipMultiple(pp, "itdMessage"); final String nameState = processItdOdv(pp, "dm", new ProcessItdOdvCallback() { @Override public void location(final String nameState, final Location location, final int matchQuality) { if (location.type == LocationType.STATION) if (findStationDepartures(r.stationDepartures, location.id) == null) r.stationDepartures.add(new StationDepartures(location, new LinkedList<Departure>(), new LinkedList<LineDestination>())); } }); if ("notidentified".equals(nameState) || "list".equals(nameState)) { result.set(new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION)); return; } XmlPullUtil.optSkip(pp, "itdDateTime"); XmlPullUtil.optSkip(pp, "itdDMDateTime"); XmlPullUtil.optSkip(pp, "itdDateRange"); XmlPullUtil.optSkip(pp, "itdTripOptions"); XmlPullUtil.optSkip(pp, "itdMessage"); if (XmlPullUtil.test(pp, "itdServingLines")) { if (!pp.isEmptyElementTag()) { XmlPullUtil.enter(pp, "itdServingLines"); while (XmlPullUtil.test(pp, "itdServingLine")) { final String assignedStopId = XmlPullUtil.optAttr(pp, "assignedStopID", null); final LineDestinationAndCancelled lineDestinationAndCancelled = processItdServingLine( pp); final LineDestination lineDestination = new LineDestination( lineDestinationAndCancelled.line, lineDestinationAndCancelled.destination); StationDepartures assignedStationDepartures; if (assignedStopId == null) assignedStationDepartures = r.stationDepartures.get(0); else assignedStationDepartures = findStationDepartures(r.stationDepartures, assignedStopId); if (assignedStationDepartures == null) assignedStationDepartures = new StationDepartures( new Location(LocationType.STATION, assignedStopId), new LinkedList<Departure>(), new LinkedList<LineDestination>()); final List<LineDestination> assignedStationDeparturesLines = checkNotNull( assignedStationDepartures.lines); if (!assignedStationDeparturesLines.contains(lineDestination)) assignedStationDeparturesLines.add(lineDestination); } XmlPullUtil.skipExit(pp, "itdServingLines"); } else { XmlPullUtil.next(pp); } } else { result.set(new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION)); return; } XmlPullUtil.require(pp, "itdDepartureList"); if (XmlPullUtil.optEnter(pp, "itdDepartureList")) { final Calendar plannedDepartureTime = new GregorianCalendar(timeZone); final Calendar predictedDepartureTime = new GregorianCalendar(timeZone); while (XmlPullUtil.test(pp, "itdDeparture")) { final String assignedStopId = XmlPullUtil.attr(pp, "stopID"); StationDepartures assignedStationDepartures = findStationDepartures(r.stationDepartures, assignedStopId); if (assignedStationDepartures == null) { final Point coord = processCoordAttr(pp); // final String name = normalizeLocationName(XmlPullUtil.attr(pp, "nameWO")); assignedStationDepartures = new StationDepartures( new Location(LocationType.STATION, assignedStopId, coord), new LinkedList<Departure>(), new LinkedList<LineDestination>()); } final Position position = parsePosition(XmlPullUtil.optAttr(pp, "platformName", null)); XmlPullUtil.enter(pp, "itdDeparture"); XmlPullUtil.require(pp, "itdDateTime"); plannedDepartureTime.clear(); processItdDateTime(pp, plannedDepartureTime); predictedDepartureTime.clear(); if (XmlPullUtil.test(pp, "itdRTDateTime")) processItdDateTime(pp, predictedDepartureTime); XmlPullUtil.optSkip(pp, "itdFrequencyInfo"); XmlPullUtil.require(pp, "itdServingLine"); final boolean isRealtime = XmlPullUtil.attr(pp, "realtime").equals("1"); final LineDestinationAndCancelled lineDestinationAndCancelled = processItdServingLine( pp); if (isRealtime && !predictedDepartureTime.isSet(Calendar.HOUR_OF_DAY)) predictedDepartureTime.setTimeInMillis(plannedDepartureTime.getTimeInMillis()); XmlPullUtil.skipExit(pp, "itdDeparture"); if (!lineDestinationAndCancelled.cancelled) { final Departure departure = new Departure(plannedDepartureTime.getTime(), predictedDepartureTime.isSet(Calendar.HOUR_OF_DAY) ? predictedDepartureTime.getTime() : null, lineDestinationAndCancelled.line, position, lineDestinationAndCancelled.destination, null, null); assignedStationDepartures.departures.add(departure); } } XmlPullUtil.skipExit(pp, "itdDepartureList"); } result.set(r); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } } }; if (httpPost) httpClient.getInputStream(callback, url.build(), url.build().encodedQuery(), "application/x-www-form-urlencoded", httpReferer); else httpClient.getInputStream(callback, url.build(), httpReferer); return result.get(); }
From source file:de.schildbach.pte.AbstractEfaProvider.java
private QueryTripsResult queryTripsMobile(final HttpUrl url, final Location from, final @Nullable Location via, final Location to, final InputStream is) throws XmlPullParserException, IOException { final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(is, null); // Read encoding from XML declaration final ResultHeader header = enterEfa(pp); final Calendar plannedTimeCal = new GregorianCalendar(timeZone); final Calendar predictedTimeCal = new GregorianCalendar(timeZone); final List<Trip> trips = new ArrayList<>(); if (XmlPullUtil.optEnter(pp, "ts")) { while (XmlPullUtil.optEnter(pp, "tp")) { XmlPullUtil.optSkip(pp, "attrs"); XmlPullUtil.valueTag(pp, "d"); // duration final int numChanges = Integer.parseInt(XmlPullUtil.valueTag(pp, "ic")); final String tripId = XmlPullUtil.valueTag(pp, "de"); XmlPullUtil.optValueTag(pp, "optval", null); XmlPullUtil.optValueTag(pp, "alt", null); XmlPullUtil.optValueTag(pp, "gix", null); XmlPullUtil.enter(pp, "ls"); final List<Trip.Leg> legs = new LinkedList<>(); Location firstDepartureLocation = null; Location lastArrivalLocation = null; while (XmlPullUtil.test(pp, "l")) { XmlPullUtil.enter(pp, "l"); XmlPullUtil.enter(pp, "ps"); Stop departure = null;//ww w . j av a 2s . com Stop arrival = null; while (XmlPullUtil.optEnter(pp, "p")) { final String name = XmlPullUtil.valueTag(pp, "n"); final String usage = XmlPullUtil.valueTag(pp, "u"); XmlPullUtil.optValueTag(pp, "de", null); XmlPullUtil.requireSkip(pp, "dt"); parseMobileSt(pp, plannedTimeCal, predictedTimeCal); XmlPullUtil.requireSkip(pp, "lis"); XmlPullUtil.enter(pp, "r"); final String id = XmlPullUtil.valueTag(pp, "id"); XmlPullUtil.optValueTag(pp, "a", null); final Position position = parsePosition(XmlPullUtil.optValueTag(pp, "pl", null)); final String place = normalizeLocationName(XmlPullUtil.optValueTag(pp, "pc", null)); final Point coord = parseCoord(XmlPullUtil.optValueTag(pp, "c", null)); XmlPullUtil.skipExit(pp, "r"); final Location location; if (id.equals("99999997") || id.equals("99999998")) location = new Location(LocationType.ADDRESS, null, coord, place, name); else location = new Location(LocationType.STATION, id, coord, place, name); XmlPullUtil.skipExit(pp, "p"); final Date plannedTime = plannedTimeCal.isSet(Calendar.HOUR_OF_DAY) ? plannedTimeCal.getTime() : null; final Date predictedTime = predictedTimeCal.isSet(Calendar.HOUR_OF_DAY) ? predictedTimeCal.getTime() : null; if ("departure".equals(usage)) { departure = new Stop(location, true, plannedTime, predictedTime, position, null); if (firstDepartureLocation == null) firstDepartureLocation = location; } else if ("arrival".equals(usage)) { arrival = new Stop(location, false, plannedTime, predictedTime, position, null); lastArrivalLocation = location; } else { throw new IllegalStateException("unknown usage: " + usage); } } checkState(departure != null); checkState(arrival != null); XmlPullUtil.skipExit(pp, "ps"); final boolean isRealtime = XmlPullUtil.valueTag(pp, "realtime").equals("1"); final LineDestination lineDestination = parseMobileM(pp, false); final List<Point> path; if (XmlPullUtil.test(pp, "pt")) path = processCoordinateStrings(pp, "pt"); else path = null; final List<Stop> intermediateStops; XmlPullUtil.require(pp, "pss"); if (XmlPullUtil.optEnter(pp, "pss")) { intermediateStops = new LinkedList<>(); while (XmlPullUtil.test(pp, "s")) { plannedTimeCal.clear(); predictedTimeCal.clear(); final String s = XmlPullUtil.valueTag(pp, "s"); final String[] intermediateParts = s.split(";"); final String id = intermediateParts[0]; if (!id.equals(departure.location.id) && !id.equals(arrival.location.id)) { final String name = normalizeLocationName(intermediateParts[1]); if (!("0000-1".equals(intermediateParts[2]) && "000-1".equals(intermediateParts[3]))) { ParserUtils.parseIsoDate(plannedTimeCal, intermediateParts[2]); ParserUtils.parseIsoTime(plannedTimeCal, intermediateParts[3]); if (isRealtime) { ParserUtils.parseIsoDate(predictedTimeCal, intermediateParts[2]); ParserUtils.parseIsoTime(predictedTimeCal, intermediateParts[3]); if (intermediateParts.length > 5 && intermediateParts[5].length() > 0) { final int delay = Integer.parseInt(intermediateParts[5]); predictedTimeCal.add(Calendar.MINUTE, delay); } } } final String coordPart = intermediateParts[4]; final Point coords; if (!"::".equals(coordPart)) { final String[] coordParts = coordPart.split(":"); if ("WGS84".equals(coordParts[2])) { final int lat = (int) Math.round(Double.parseDouble(coordParts[1])); final int lon = (int) Math.round(Double.parseDouble(coordParts[0])); coords = new Point(lat, lon); } else { coords = null; } } else { coords = null; } final Location location = new Location(LocationType.STATION, id, coords, null, name); final Date plannedTime = plannedTimeCal.isSet(Calendar.HOUR_OF_DAY) ? plannedTimeCal.getTime() : null; final Date predictedTime = predictedTimeCal.isSet(Calendar.HOUR_OF_DAY) ? predictedTimeCal.getTime() : null; final Stop stop = new Stop(location, false, plannedTime, predictedTime, null, null); intermediateStops.add(stop); } } XmlPullUtil.skipExit(pp, "pss"); } else { intermediateStops = null; } XmlPullUtil.optSkip(pp, "interchange"); XmlPullUtil.requireSkip(pp, "ns"); // TODO messages XmlPullUtil.skipExit(pp, "l"); if (lineDestination.line == Line.FOOTWAY) { legs.add(new Trip.Individual(Trip.Individual.Type.WALK, departure.location, departure.getDepartureTime(), arrival.location, arrival.getArrivalTime(), path, 0)); } else if (lineDestination.line == Line.TRANSFER) { legs.add(new Trip.Individual(Trip.Individual.Type.TRANSFER, departure.location, departure.getDepartureTime(), arrival.location, arrival.getArrivalTime(), path, 0)); } else if (lineDestination.line == Line.SECURE_CONNECTION || lineDestination.line == Line.DO_NOT_CHANGE) { // ignore } else { legs.add(new Trip.Public(lineDestination.line, lineDestination.destination, departure, arrival, intermediateStops, path, null)); } } XmlPullUtil.skipExit(pp, "ls"); XmlPullUtil.optSkip(pp, "seqroutes"); final List<Fare> fares; if (XmlPullUtil.optEnter(pp, "tcs")) { fares = new ArrayList<>(2); XmlPullUtil.optSkipMultiple(pp, "tc"); // TODO fares XmlPullUtil.skipExit(pp, "tcs"); } else { fares = null; } final Trip trip = new Trip(tripId, firstDepartureLocation, lastArrivalLocation, legs, fares, null, numChanges); trips.add(trip); XmlPullUtil.skipExit(pp, "tp"); } XmlPullUtil.skipExit(pp, "ts"); } if (trips.size() > 0) { final String[] context = (String[]) header.context; return new QueryTripsResult(header, url.toString(), from, via, to, new Context(commandLink(context[0], context[1]).toString()), trips); } else { return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); } }