@Test public void testSingle() { ZoneId zone = ZoneId.of("GMT"); TimeZoneRulesImpl rules = new TimeZoneRulesImpl(zone.getRules()); int y = 2017; int m = 3; int d = 29; LocalDateTime dt = LocalDateTime.of(y, m, d, 0, 0); long millis = Timestamps.toMicros(y, m, d, 0, 0); ZonedDateTime zdt = dt.atZone(zone); long expected = zdt.getOffset().getTotalSeconds(); long changed = Timestamps.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * 1000; expected += (changed - millis) / 1000; long offset = rules.getOffset(millis, y, Timestamps.isLeapYear(y)); try { Assert.assertEquals(expected, offset / 1000); } catch (Throwable e) { System.out.println(zone.getId() + "; " + zdt + "; " + Timestamps.toString(millis + offset)); throw e; } }
@Override public long getOffset(long micros, int year, boolean leap) { if (standardOffset != Long.MIN_VALUE) { return standardOffset; } if (ruleCount > 0 && micros > cutoffTransition) { return fromRules(micros, year, leap); } if (micros > cutoffTransition) { return lastWall; } return fromHistory(micros); }
TimeZoneRulesImpl implements TimeZoneRules { @Override public long getOffset(long micros, int year, boolean leap) { if (standardOffset != Long.MIN_VALUE) { return standardOffset; } if (ruleCount > 0 && micros > cutoffTransition) { return fromRules(micros, year, leap); } if (micros > cutoffTransition) { return lastWall; } return fromHistory(micros); } }
TimeZoneRulesImpl implements TimeZoneRules { @Override public long getOffset(long micros, int year, boolean leap) { if (standardOffset != Long.MIN_VALUE) { return standardOffset; } if (ruleCount > 0 && micros > cutoffTransition) { return fromRules(micros, year, leap); } if (micros > cutoffTransition) { return lastWall; } return fromHistory(micros); } TimeZoneRulesImpl(ZoneRules rules); }
TimeZoneRulesImpl implements TimeZoneRules { @Override public long getOffset(long micros, int year, boolean leap) { if (standardOffset != Long.MIN_VALUE) { return standardOffset; } if (ruleCount > 0 && micros > cutoffTransition) { return fromRules(micros, year, leap); } if (micros > cutoffTransition) { return lastWall; } return fromHistory(micros); } TimeZoneRulesImpl(ZoneRules rules); @Override long getOffset(long micros, int year, boolean leap); @Override long getOffset(long micros); }
TimeZoneRulesImpl implements TimeZoneRules { @Override public long getOffset(long micros, int year, boolean leap) { if (standardOffset != Long.MIN_VALUE) { return standardOffset; } if (ruleCount > 0 && micros > cutoffTransition) { return fromRules(micros, year, leap); } if (micros > cutoffTransition) { return lastWall; } return fromHistory(micros); } TimeZoneRulesImpl(ZoneRules rules); @Override long getOffset(long micros, int year, boolean leap); @Override long getOffset(long micros); static final long SAVING_INSTANT_TRANSITION; static final long STANDARD_OFFSETS; static final long LAST_RULES; static final long SAVINGS_LOCAL_TRANSITION; static final long WALL_OFFSETS; }