@Override protected void initializeProviders() { TzdbZoneRulesProvider provider; InputStream is = null; try { is = context.getAssets().open("org/threeten/bp/TZDB.dat"); provider = new TzdbZoneRulesProvider(is); } catch (IOException e) { throw new IllegalStateException("TZDB.dat missing from assets.", e); } finally { if (is != null) { try { is.close(); } catch (IOException ignored) { } } } ZoneRulesProvider.registerProvider(provider); } }
public static void init(Context context) { if (!initialized.getAndSet(true)) { ZoneRulesInitializer.setInitializer(new AssetsZoneRulesInitializer(context)); } }
@Test public void litmus() { AndroidThreeTen.init(context); assertThat(ZoneRulesProvider.getAvailableZoneIds()).isNotEmpty(); } }
private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException { switch (type) { case SZR: return StandardZoneRules.readExternal(in); case ZOT: return ZoneOffsetTransition.readExternal(in); case ZOTRULE: return ZoneOffsetTransitionRule.readExternal(in); default: throw new StreamCorruptedException("Unknown serialized type"); } }
@Override public ZoneOffset getOffset(LocalDateTime localDateTime) { Object info = getOffsetInfo(localDateTime); if (info instanceof ZoneOffsetTransition) { return ((ZoneOffsetTransition) info).getOffsetBefore(); } return (ZoneOffset) info; }
/** * Writes the state to the stream. * * @param out the output stream, not null * @throws IOException if an error occurs */ void writeExternal(DataOutput out) throws IOException { Ser.writeEpochSec(toEpochSecond(), out); Ser.writeOffset(offsetBefore, out); Ser.writeOffset(offsetAfter, out); }
@Override public ZoneRules getRules() { // additional query for group provider when null allows for possibility // that the provider was added after the ZoneId was created return (rules != null ? rules : ZoneRulesProvider.getRules(id, false)); }
void addToBuilder(ZoneRulesBuilder bld) { adjustToFowards(2004); // irrelevant, treat as leap year bld.addRuleToWindow(startYear, endYear, month, dayOfMonth, dayOfWeek, time, adjustDays, timeDefinition, savingsAmount); } }
ZoneId zoneId = ZoneId.of("Australia/Sydney"); ZoneRules rules = zoneId.getRules(); ZoneOffsetTransition nextTransition = rules.nextTransition(Instant.now()); System.out.println("Next transition at: " + nextTransition.getInstant().atZone(zoneId)); ZoneOffsetTransition nextNextTransition = rules.nextTransition(nextTransition.getInstant()); System.out.println("Next transition after that at: " + nextNextTransition.getInstant().atZone(zoneId));
/** * Parses the source files. * * @throws Exception if an error occurs */ private void parseFiles() throws Exception { for (File file : sourceFiles) { printVerbose("Parsing file: " + file); parseFile(file); } }
/** * Uses a serialization delegate. * * @return the replacing object, not null */ private Object writeReplace() { return new Ser(Ser.ZOT, this); }
@Override public ZoneOffsetTransition getTransition(LocalDateTime localDateTime) { Object info = getOffsetInfo(localDateTime); return (info instanceof ZoneOffsetTransition ? (ZoneOffsetTransition) info : null); }
/** * Gets the associated time-zone rules. * <p> * The rules will always return this offset when queried. * The implementation class is immutable, thread-safe and serializable. * * @return the rules, not null */ @Override public ZoneRules getRules() { return ZoneRules.of(this); }
/** * Implements the {@code Externalizable} interface to write the object. * * @param out the data stream to write to, not null */ public void writeExternal(ObjectOutput out) throws IOException { writeInternal(type, object, out); }
private static Object readInternal(byte type, DataInput in) throws IOException, ClassNotFoundException { switch (type) { case SZR: return StandardZoneRules.readExternal(in); case ZOT: return ZoneOffsetTransition.readExternal(in); case ZOTRULE: return ZoneOffsetTransitionRule.readExternal(in); default: throw new StreamCorruptedException("Unknown serialized type"); } }
@Override public ZoneOffset getOffset(LocalDateTime localDateTime) { Object info = getOffsetInfo(localDateTime); if (info instanceof ZoneOffsetTransition) { return ((ZoneOffsetTransition) info).getOffsetBefore(); } return (ZoneOffset) info; }
/** * Writes the state to the stream. * * @param out the output stream, not null * @throws IOException if an error occurs */ void writeExternal(DataOutput out) throws IOException { Ser.writeEpochSec(toEpochSecond(), out); Ser.writeOffset(offsetBefore, out); Ser.writeOffset(offsetAfter, out); }
void addToBuilder(ZoneRulesBuilder bld) { adjustToFowards(2004); // irrelevant, treat as leap year bld.addRuleToWindow(startYear, endYear, month, dayOfMonth, dayOfWeek, time, adjustDays, timeDefinition, savingsAmount); } }
/** * Uses a serialization delegate. * * @return the replacing object, not null */ private Object writeReplace() { return new Ser(Ser.ZOT, this); }
/** * Uses a serialization delegate. * * @return the replacing object, not null */ private Object writeReplace() { return new Ser(Ser.ZOTRULE, this); }