/** * 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); }
@Override public OffsetDateTime queryFrom(TemporalAccessor temporal) { return OffsetDateTime.from(temporal); } };
/** * Combines this time with a date to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this time and the specified date. * All possible combinations of date and time are valid. * * @param date the date to combine with, not null * @return the offset date-time formed from this time and the specified date, not null */ public OffsetDateTime atDate(LocalDate date) { return OffsetDateTime.of(date, time, offset); }
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; }
if (tmp[19] == '.') { final int nanos = readNanos(tmp, len - 1); return OffsetDateTime.of(year, month, day, hour, min, sec, nanos, ZoneOffset.UTC); return OffsetDateTime.of(year, month, day, hour, min, sec, 0, ZoneOffset.UTC); } else if (len > 22 && len < 36 && tmp[len - 3] == ':' && (tmp[len - 6] == '+' || tmp[len - 6] == '-') if (tmp[19] == '.') { final int nanos = readNanos(tmp, len - 6); return OffsetDateTime.of(year, month, day, hour, min, sec, nanos, offset); return OffsetDateTime.of(year, month, day, hour, min, sec, 0, offset); } else { return OffsetDateTime.parse(new String(tmp, 0, len));
@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); } }
@Override public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); } },
/** * Combines this instant with an offset to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this instant at the * specified offset from UTC/Greenwich. An exception will be thrown if the * instant is too large to fit into an offset date-time. * <p> * This method is equivalent to * {@link OffsetDateTime#ofInstant(Instant, ZoneId) OffsetDateTime.ofInstant(this, offset)}. * * @param offset the offset to combine with, not null * @return the offset date-time formed from this instant and the specified offset, not null * @throws DateTimeException if the result exceeds the supported range */ public OffsetDateTime atOffset(ZoneOffset offset) { return OffsetDateTime.ofInstant(this, offset); }
if (getOffset().equals(other.getOffset())) { return toLocalDateTime().compareTo(other.toLocalDateTime()); int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond()); if (cmp == 0) { cmp = toLocalTime().getNano() - other.toLocalTime().getNano(); if (cmp == 0) { cmp = toLocalDateTime().compareTo(other.toLocalDateTime());
OffsetDateTime end = OffsetDateTime.from(endExclusive); if (unit instanceof ChronoUnit) { end = end.withOffsetSameInstant(offset); return dateTime.until(end.dateTime, unit);
/** Returns TAI milliseconds mod 2^32 for the given date. * * Since java int is signed 32 bit integer, return long instead. * It is the same on byte level, but just to avoid confusing people with negative values here. * * * From http://stjarnhimlen.se/comp/time.html: * * TAI (Temps Atomique International or International Atomic Time) is * defined as the weighted average of the time kept by about 200 * atomic clocks in over 50 national laboratories worldwide. * TAI-UT1 was approximately 0 on 1958 Jan 1. * (TAI is ahead of UTC by 35 seconds as of 2014.) * * GPS time = TAI - 19 seconds. GPS time matched UTC from 1980-01-01 * to 1981-07-01. No leap seconds are inserted into GPS time, thus * GPS time is 13 seconds ahead of UTC on 2000-01-01. The GPS epoch * is 00:00 (midnight) UTC on 1980-01-06. * The difference between GPS Time and UTC changes in increments of * seconds each time a leap second is added to UTC time scale. */ public static long instantToTaiMillisSince2004Mod32(Instant instantX) { OffsetDateTime gnEpochStart = OffsetDateTime.of(LocalDateTime.of(2004, Month.JANUARY, 1, 0, 0), ZoneOffset.UTC); long millis2004 = gnEpochStart.toInstant().toEpochMilli(); long millisAtX = instantX.toEpochMilli(); long taiMillis = (millisAtX + LEAP_SECONDS_SINCE_2004*1000) - millis2004; return taiMillis % (1L << 32); }
return with(dateTime.with(adjuster), offset); } else if (adjuster instanceof Instant) { return ofInstant((Instant) adjuster, offset); } else if (adjuster instanceof ZoneOffset) { return with(dateTime, (ZoneOffset) adjuster); } else if (adjuster instanceof OffsetDateTime) { return (OffsetDateTime) adjuster;
@Override public long applyAsLong(OffsetDateTime dt) { return dt.toInstant().toEpochMilli(); } },
@Override public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); } }
/** * Combines this instant with an offset to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this instant at the * specified offset from UTC/Greenwich. An exception will be thrown if the * instant is too large to fit into an offset date-time. * <p> * This method is equivalent to * {@link OffsetDateTime#ofInstant(Instant, ZoneId) OffsetDateTime.ofInstant(this, offset)}. * * @param offset the offset to combine with, not null * @return the offset date-time formed from this instant and the specified offset, not null * @throws DateTimeException if the result exceeds the supported range */ public OffsetDateTime atOffset(ZoneOffset offset) { return OffsetDateTime.ofInstant(this, offset); }
if (getOffset().equals(other.getOffset())) { return toLocalDateTime().compareTo(other.toLocalDateTime()); int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond()); if (cmp == 0) { cmp = toLocalTime().getNano() - other.toLocalTime().getNano(); if (cmp == 0) { cmp = toLocalDateTime().compareTo(other.toLocalDateTime());