/** * Obtains an instance of {@code OffsetDateTime} from a text string * such as {@code 2007-12-23T10:15:30+01:00}. * <p> * The string must represent a valid date-time and is parsed using * {@link org.threeten.bp.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME}. * * @param text the text to parse such as "2007-12-23T10:15:30+01:00", not null * @return the parsed offset date-time, not null * @throws DateTimeParseException if the text cannot be parsed */ public static OffsetDateTime parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME); }
/** * Obtains an instance of {@code OffsetDateTime} from a text string * such as {@code 2007-12-03T10:15:30+01:00}. * <p> * The string must represent a valid date-time and is parsed using * {@link org.threeten.bp.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME}. * * @param text the text to parse such as "2007-12-03T10:15:30+01:00", not null * @return the parsed offset date-time, not null * @throws DateTimeParseException if the text cannot be parsed */ public static OffsetDateTime parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME); }
default OffsetDateTime convert(long time) { return OffsetDateTime.parse(sdf.format(new Date(time))); } }
@Override protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException { try { return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME); } catch (DateTimeException e) { return _rethrowDateTimeException(ctxt, OffsetDateTime.class, e, key); } } }
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length()-5) + "Z"; } return OffsetDateTime.parse(date, formatter); } } }
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length()-5) + "Z"; } return OffsetDateTime.parse(date, formatter); } } }
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length()-5) + "Z"; } return OffsetDateTime.parse(date, formatter); } } }
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length()-5) + "Z"; } return OffsetDateTime.parse(date, formatter); } } }
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length()-5) + "Z"; } return OffsetDateTime.parse(date, formatter); } } }
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length()-5) + "Z"; } return OffsetDateTime.parse(date, formatter); } } }
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length()-5) + "Z"; } return OffsetDateTime.parse(date, formatter); } } }
@Override public OffsetDateTime read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); if (date.endsWith("+0000")) { date = date.substring(0, date.length()-5) + "Z"; } return OffsetDateTime.parse(date, formatter); } } }
public static GsonBuilder getGsonBuilder() { GsonBuilder builder = new GsonBuilder(); // trakt exclusively uses ISO 8601 date times with milliseconds and time zone offset // such as '2011-12-03T10:15:30.000+01:00' or '2011-12-03T10:15:30.000Z' builder.registerTypeAdapter(OffsetDateTime.class, (JsonDeserializer<OffsetDateTime>) (json, typeOfT, context) -> OffsetDateTime.parse(json.getAsString())); builder.registerTypeAdapter(OffsetDateTime.class, (JsonSerializer<OffsetDateTime>) (src, typeOfSrc, context) -> new JsonPrimitive(src.toString())); // dates are in ISO 8601 format as well builder.registerTypeAdapter(LocalDate.class, (JsonDeserializer<LocalDate>) (json, typeOfT, context) -> LocalDate.parse(json.getAsString())); // privacy builder.registerTypeAdapter(ListPrivacy.class, (JsonDeserializer<ListPrivacy>) (json, typeOfT, context) -> ListPrivacy.fromValue(json.getAsString())); // rating builder.registerTypeAdapter(Rating.class, (JsonDeserializer<Rating>) (json, typeOfT, context) -> Rating.fromValue(json.getAsInt())); builder.registerTypeAdapter(Rating.class, (JsonSerializer<Rating>) (src, typeOfSrc, context) -> new JsonPrimitive(src.value)); // sort by builder.registerTypeAdapter(SortBy.class, (JsonDeserializer<SortBy>) (json, typeOfT, context) -> SortBy.fromValue(json.getAsString())); // sort how builder.registerTypeAdapter(SortHow.class, (JsonDeserializer<SortHow>) (json, typeOfT, context) -> SortHow.fromValue(json.getAsString())); // status builder.registerTypeAdapter(Status.class, (JsonDeserializer<Status>) (json, typeOfT, context) -> Status.fromValue(json.getAsString())); return builder; }
@Override public LongPositionVector getLatestPosition() { Optional<Address> emptyAddress = Optional.empty(); if (lastSeenTPV == null) { Instant timestamp = Instant.now(); Position position = new Position(Double.NaN, Double.NaN); // NaN or 0? boolean isPositionConfident = false; double speedMetersPerSecond = 0; double headingDegreesFromNorth = 0; return new LongPositionVector(emptyAddress, timestamp, position, isPositionConfident, speedMetersPerSecond, headingDegreesFromNorth); } else { final TPV tpv = lastSeenTPV; // Is this enough to ensure that tpv will remain the same // through the rest of the method? Instant timestamp = OffsetDateTime.parse(tpv.time()).toInstant(); Position position = new Position(tpv.lat(), tpv.lon()); boolean isPositionConfident = false; // TODO: double-check conditions for PAI=true. double speedMetersPerSecond = tpv.speed(); double headingDegreesFromNorth = tpv.track(); return new LongPositionVector(emptyAddress, timestamp, position, isPositionConfident, speedMetersPerSecond, headingDegreesFromNorth); } }
return OffsetDateTime.parse(new String(tmp, 0, len));