private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
/** * @param localInstant the instant from 1970-01-01T00:00:00 local time * @return the instant from 1970-01-01T00:00:00Z */ private long localToUTC(long localInstant) { if (localInstant == Long.MAX_VALUE) { return Long.MAX_VALUE; } else if (localInstant == Long.MIN_VALUE) { return Long.MIN_VALUE; } DateTimeZone zone = getZone(); int offset = zone.getOffsetFromLocal(localInstant); long utcInstant = localInstant - offset; if (localInstant > NEAR_ZERO && utcInstant < 0) { return Long.MAX_VALUE; } else if (localInstant < -NEAR_ZERO && utcInstant > 0) { return Long.MIN_VALUE; } int offsetBasedOnUtc = zone.getOffset(utcInstant); if (offset != offsetBasedOnUtc) { throw new IllegalInstantException(localInstant, zone.getID()); } return utcInstant; }
/** * @param localInstant the instant from 1970-01-01T00:00:00 local time * @return the instant from 1970-01-01T00:00:00Z */ private long localToUTC(long localInstant) { if (localInstant == Long.MAX_VALUE) { return Long.MAX_VALUE; } else if (localInstant == Long.MIN_VALUE) { return Long.MIN_VALUE; } DateTimeZone zone = getZone(); int offset = zone.getOffsetFromLocal(localInstant); long utcInstant = localInstant - offset; if (localInstant > NEAR_ZERO && utcInstant < 0) { return Long.MAX_VALUE; } else if (localInstant < -NEAR_ZERO && utcInstant > 0) { return Long.MIN_VALUE; } int offsetBasedOnUtc = zone.getOffset(utcInstant); if (offset != offsetBasedOnUtc) { throw new IllegalInstantException(localInstant, zone.getID()); } return utcInstant; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
@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)); }
millis -= iOffset; } else if (iZone != null) { int offset = iZone.getOffsetFromLocal(millis); millis -= offset; if (offset != iZone.getOffset(millis)) {
millis -= iOffset; } else if (iZone != null) { int offset = iZone.getOffsetFromLocal(millis); millis -= offset; if (offset != iZone.getOffset(millis)) {
/** * @param instant instant from 1970-01-01T00:00:00 local time * @return instant from 1970-01-01T00:00:00Z */ private long localToUTC(long instant) { DateTimeZone zone = getZone(); int offset = zone.getOffsetFromLocal(instant); instant -= offset; if (offset != zone.getOffset(instant)) { throw new IllegalArgumentException ("Illegal instant due to time zone offset transition: " + DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").print(new Instant(instant))); } return instant; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
private int getOffsetFromLocalToSubtract(long instant) { int offset = this.iZone.getOffsetFromLocal(instant); long diff = instant - offset; // If there is a sign change, but the two values have different signs... if ((instant ^ diff) < 0 && (instant ^ offset) < 0) { throw new ArithmeticException("Subtracting time zone offset caused overflow"); } return offset; }
millis -= iOffset; } else if (iZone != null) { int offset = iZone.getOffsetFromLocal(millis); millis -= offset; if (offset != iZone.getOffset(millis)) {
@JRubyMethod(name = {"gmt_offset", "gmtoff", "utc_offset"}) public RubyInteger gmt_offset() { int offset = dt.getZone().getOffsetFromLocal(dt.getMillis()); return getRuntime().newFixnum((int)(offset/1000)); }