public int getStandardOffset(long millis) { if (iNextInfo == null || millis < iNextInfo.iPeriodStart) { if (iStandardOffset == Integer.MIN_VALUE) { iStandardOffset = iZoneRef.getStandardOffset(iPeriodStart); } return iStandardOffset; } return iNextInfo.getStandardOffset(millis); } }
public int getStandardOffset(long millis) { if (iNextInfo == null || millis < iNextInfo.iPeriodStart) { if (iStandardOffset == Integer.MIN_VALUE) { iStandardOffset = iZoneRef.getStandardOffset(iPeriodStart); } return iStandardOffset; } return iNextInfo.getStandardOffset(millis); } }
/** * Checks whether, at a particular instant, the offset is standard or not. * <p> * This method can be used to determine whether Summer Time (DST) applies. * As a general rule, if the offset at the specified instant is standard, * then either Winter time applies, or there is no Summer Time. If the * instant is not standard, then Summer Time applies. * <p> * The implementation of the method is simply whether {@link #getOffset(long)} * equals {@link #getStandardOffset(long)} at the specified instant. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the offset for * @return true if the offset at the given instant is the standard offset * @since 1.5 */ public boolean isStandardOffset(long instant) { return getOffset(instant) == getStandardOffset(instant); }
/** * Checks whether, at a particular instant, the offset is standard or not. * <p> * This method can be used to determine whether Summer Time (DST) applies. * As a general rule, if the offset at the specified instant is standard, * then either Winter time applies, or there is no Summer Time. If the * instant is not standard, then Summer Time applies. * <p> * The implementation of the method is simply whether {@link #getOffset(long)} * equals {@link #getStandardOffset(long)} at the specified instant. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the offset for * @return true if the offset at the given instant is the standard offset * @since 1.5 */ public boolean isStandardOffset(long instant) { return getOffset(instant) == getStandardOffset(instant); }
private static DateTimeZone getFixedOffsetTimeZone(final DateTimeZone referenceDateTimeZone, final DateTime referenceDateTime) { // Check if DST was in effect at the reference date time final boolean shouldUseDST = !referenceDateTimeZone.isStandardOffset(referenceDateTime.getMillis()); if (shouldUseDST) { return DateTimeZone.forOffsetMillis(referenceDateTimeZone.getOffset(referenceDateTime.getMillis())); } else { return DateTimeZone.forOffsetMillis(referenceDateTimeZone.getStandardOffset(referenceDateTime.getMillis())); } } }
public static String listTimezones() { DateTimeFormatter offsetFormatter = new DateTimeFormatterBuilder().appendTimeZoneOffset(null, true, 2, 4).toFormatter(); Set<String> idSet = DateTimeZone.getAvailableIDs(); Map<String, String> tzMap = new TreeMap(); Iterator<String> it = idSet.iterator(); String id, cid, offset, key, output; DateTimeZone tz; int i = 0; long millis = System.currentTimeMillis(); // collect canonical and alias IDs into a map while (it.hasNext()) { id = it.next(); tz = DateTimeZone.forID(id); cid = tz.getID(); offset = offsetFormatter.withZone(tz).print(tz.getStandardOffset(millis)); key = offset + " " + cid; if (id == cid) { // Canonical ID if (!tzMap.containsKey(key)) tzMap.put(key, ""); } else {// alias ID if (!tzMap.containsKey(key)) tzMap.put(key, id); else tzMap.put(key, tzMap.get(key) + ", " + id); } } // assemble result output = "StandardOffset CanonicalID, Aliases\n"; for (Map.Entry<String, String> e : tzMap.entrySet()) output += e.getKey() + e.getValue()+"\n"; return output; }
/** * Encodes a built DateTimeZone to the given stream. Call readFrom to * decode the data into a DateTimeZone object. * * @param out the output stream to receive the encoded DateTimeZone * @since 1.5 (parameter added) */ public void writeTo(String zoneID, DataOutput out) throws IOException { // pass false so zone id is not written out DateTimeZone zone = toDateTimeZone(zoneID, false); if (zone instanceof FixedDateTimeZone) { out.writeByte('F'); // 'F' for fixed out.writeUTF(zone.getNameKey(0)); writeMillis(out, zone.getOffset(0)); writeMillis(out, zone.getStandardOffset(0)); } else { if (zone instanceof CachedDateTimeZone) { out.writeByte('C'); // 'C' for cached, precalculated zone = ((CachedDateTimeZone)zone).getUncachedZone(); } else { out.writeByte('P'); // 'P' for precalculated, uncached } ((PrecalculatedZone)zone).writeTo(out); } }
static DateTimeZone nonDefaultTimeZone() { String defaultId = DateTimeZone.getDefault().getID(); for (String id : DateTimeZone.getAvailableIDs()) { if (!id.equals(defaultId)) { DateTimeZone zone = DateTimeZone.forID(id); if (zone.getStandardOffset(0) != 0) { return zone; } } } throw new IllegalStateException("no non-default timezone"); } }
/** * Encodes a built DateTimeZone to the given stream. Call readFrom to * decode the data into a DateTimeZone object. * * @param out the output stream to receive the encoded DateTimeZone * @since 1.5 (parameter added) */ public void writeTo(String zoneID, DataOutput out) throws IOException { // pass false so zone id is not written out DateTimeZone zone = toDateTimeZone(zoneID, false); if (zone instanceof FixedDateTimeZone) { out.writeByte('F'); // 'F' for fixed out.writeUTF(zone.getNameKey(0)); writeMillis(out, zone.getOffset(0)); writeMillis(out, zone.getStandardOffset(0)); } else { if (zone instanceof CachedDateTimeZone) { out.writeByte('C'); // 'C' for cached, precalculated zone = ((CachedDateTimeZone)zone).getUncachedZone(); } else { out.writeByte('P'); // 'P' for precalculated, uncached } ((PrecalculatedZone)zone).writeTo(out); } }
int stdOffset = tz.getStandardOffset(millis); String key = tz.getNameKey(millis); int nextStdOffset = tz.getStandardOffset(millis); String nextKey = tz.getNameKey(millis);
int stdOffset = tz.getStandardOffset(millis); String key = tz.getNameKey(millis); int nextStdOffset = tz.getStandardOffset(millis); String nextKey = tz.getNameKey(millis);
@Test public void testWindhoek() { DateTimeZone zone = DateTimeZone.forID("Africa/Windhoek"); DateTime dtDec1990 = new DateTime(1990, 12, 1, 0, 0, 0, 0, zone); assertEquals(3600000, zone.getStandardOffset(dtDec1990.getMillis())); assertEquals(7200000, zone.getOffset(dtDec1990.getMillis())); assertEquals(false, zone.isStandardOffset(dtDec1990.getMillis())); DateTime dtDec1994 = new DateTime(1994, 12, 1, 0, 0, 0, 0, zone); assertEquals(3600000, zone.getStandardOffset(dtDec1994.getMillis())); assertEquals(7200000, zone.getOffset(dtDec1994.getMillis())); assertEquals(false, zone.isStandardOffset(dtDec1994.getMillis())); DateTime dtJun1995 = new DateTime(1995, 6, 1, 0, 0, 0, 0, zone); assertEquals(3600000, zone.getStandardOffset(dtJun1995.getMillis())); assertEquals(3600000, zone.getOffset(dtJun1995.getMillis())); assertEquals(true, zone.isStandardOffset(dtJun1995.getMillis())); }
@Test public void testDublin() { DateTimeZone zone = DateTimeZone.forID("Europe/Dublin"); DateTime winter = new DateTime(2018, 1, 1, 0, 0, 0, 0, zone); assertEquals(0, zone.getStandardOffset(winter.getMillis())); assertEquals(0, zone.getOffset(winter.getMillis())); assertEquals(true, zone.isStandardOffset(winter.getMillis())); assertEquals("Greenwich Mean Time", zone.getName(winter.getMillis())); assertEquals("GMT", zone.getNameKey(winter.getMillis())); DateTime summer = winter.plusMonths(6); assertEquals(0, zone.getStandardOffset(summer.getMillis())); assertEquals(3600000, zone.getOffset(summer.getMillis())); assertEquals(false, zone.isStandardOffset(summer.getMillis())); assertEquals(true, zone.getName(summer.getMillis()).startsWith("Irish ")); assertEquals("IST", zone.getNameKey(summer.getMillis())); }
@Test public void testGetOffsetFixed() { DateTimeZone zone = DateTimeZone.forID("+01:00"); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(TEST_TIME_SUMMER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(TEST_TIME_WINTER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getStandardOffset(TEST_TIME_SUMMER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getStandardOffset(TEST_TIME_WINTER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffsetFromLocal(TEST_TIME_SUMMER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffsetFromLocal(TEST_TIME_WINTER)); assertEquals(true, zone.isStandardOffset(TEST_TIME_SUMMER)); assertEquals(true, zone.isStandardOffset(TEST_TIME_WINTER)); }
@Test public void testGetOffset_long() { DateTimeZone zone = DateTimeZone.forID("Europe/Paris"); assertEquals(2L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(TEST_TIME_SUMMER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(TEST_TIME_WINTER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getStandardOffset(TEST_TIME_SUMMER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getStandardOffset(TEST_TIME_WINTER)); assertEquals(2L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffsetFromLocal(TEST_TIME_SUMMER)); assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffsetFromLocal(TEST_TIME_WINTER)); assertEquals(false, zone.isStandardOffset(TEST_TIME_SUMMER)); assertEquals(true, zone.isStandardOffset(TEST_TIME_WINTER)); }
public int getStandardOffset(long millis) { if (iNextInfo == null || millis < iNextInfo.iPeriodStart) { if (iStandardOffset == Integer.MIN_VALUE) { iStandardOffset = iZoneRef.getStandardOffset(iPeriodStart); } return iStandardOffset; } return iNextInfo.getStandardOffset(millis); } }
/** * Checks whether, at a particular instant, the offset is standard or not. * <p> * This method can be used to determine whether Summer Time (DST) applies. * As a general rule, if the offset at the specified instant is standard, * then either Winter time applies, or there is no Summer Time. If the * instant is not standard, then Summer Time applies. * <p> * The implementation of the method is simply whether {@link #getOffset(long)} * equals {@link #getStandardOffset(long)} at the specified instant. * * @param instant milliseconds from 1970-01-01T00:00:00Z to get the offset for * @return true if the offset at the given instant is the standard offset * @since 1.5 */ public boolean isStandardOffset(long instant) { return getOffset(instant) == getStandardOffset(instant); }
/** * Encodes a built DateTimeZone to the given stream. Call readFrom to * decode the data into a DateTimeZone object. * * @param out the output stream to receive the encoded DateTimeZone * @since 1.5 (parameter added) */ public void writeTo(String zoneID, DataOutput out) throws IOException { // pass false so zone id is not written out DateTimeZone zone = toDateTimeZone(zoneID, false); if (zone instanceof FixedDateTimeZone) { out.writeByte('F'); // 'F' for fixed out.writeUTF(zone.getNameKey(0)); writeMillis(out, zone.getOffset(0)); writeMillis(out, zone.getStandardOffset(0)); } else { if (zone instanceof CachedDateTimeZone) { out.writeByte('C'); // 'C' for cached, precalculated zone = ((CachedDateTimeZone)zone).getUncachedZone(); } else { out.writeByte('P'); // 'P' for precalculated, uncached } ((PrecalculatedZone)zone).writeTo(out); } }
public int getStandardOffset(long millis) { if (iNextInfo == null || millis < iNextInfo.iPeriodStart) { if (iStandardOffset == Integer.MIN_VALUE) { iStandardOffset = iZoneRef.getStandardOffset(iPeriodStart); } return iStandardOffset; } return iNextInfo.getStandardOffset(millis); } }
public int getStandardOffset(long millis) { if (iNextInfo == null || millis < iNextInfo.iPeriodStart) { if (iStandardOffset == Integer.MIN_VALUE) { iStandardOffset = iZoneRef.getStandardOffset(iPeriodStart); } return iStandardOffset; } return iNextInfo.getStandardOffset(millis); } }