use of java.util.SimpleTimeZone in project robovm by robovm.
the class SimpleTimeZoneTest method test_getOffsetJ.
public void test_getOffsetJ() {
Calendar cal = Calendar.getInstance();
cal.set(1998, Calendar.NOVEMBER, 11, 0, 0);
st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
assertTrue("Incorrect offset returned", st1.getOffset(cal.getTimeInMillis()) == -(5 * 60 * 60 * 1000));
st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
cal.set(1998, Calendar.JUNE, 11, 0, 0);
assertEquals("Incorrect offset returned", -(5 * 60 * 60 * 1000), st1.getOffset(cal.getTimeInMillis()));
// Regression for HARMONY-5459
st1 = new SimpleTimeZone(TimeZone.getDefault().getRawOffset(), TimeZone.getDefault().getID());
int fourHours = 4 * 60 * 60 * 1000;
st1.setRawOffset(fourHours);
cal.set(2099, 01, 1, 0, 0);
assertEquals(fourHours, st1.getOffset(cal.getTimeInMillis()));
}
use of java.util.SimpleTimeZone in project robovm by robovm.
the class SimpleTimeZoneTest method test_setStartRuleIII.
/**
* java.util.SimpleTimeZone#setStartRule(int, int, int)
*/
public void test_setStartRuleIII() {
// Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
// int)
SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
// Spec indicates that both end and start must be set or result is
// undefined
st.setStartRule(Calendar.NOVEMBER, 1, 1);
st.setEndRule(Calendar.DECEMBER, 1, 1);
assertTrue("StartRule improperly set", st.useDaylightTime());
assertTrue("StartRule improperly set", st.inDaylightTime((new GregorianCalendar(1998, Calendar.NOVEMBER, 13).getTime())));
assertTrue("StartRule improperly set", !(st.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 13).getTime())));
try {
st.setStartRule(13, 20, 0);
fail("IllegalArgumentException is not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
try {
st.setStartRule(1, 32, 0);
fail("IllegalArgumentException is not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
try {
st.setStartRule(1, 30, 10);
fail("IllegalArgumentException is not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
}
use of java.util.SimpleTimeZone in project XobotOS by xamarin.
the class DERGeneralizedTime method getDate.
public Date getDate() throws ParseException {
SimpleDateFormat dateF;
String d = time;
if (time.endsWith("Z")) {
if (hasFractionalSeconds()) {
dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'");
} else {
dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
}
dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
} else if (time.indexOf('-') > 0 || time.indexOf('+') > 0) {
d = this.getTime();
if (hasFractionalSeconds()) {
dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSSz");
} else {
dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
}
dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
} else {
if (hasFractionalSeconds()) {
dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
} else {
dateF = new SimpleDateFormat("yyyyMMddHHmmss");
}
dateF.setTimeZone(new SimpleTimeZone(0, TimeZone.getDefault().getID()));
}
if (hasFractionalSeconds()) {
// java misinterprets extra digits as being milliseconds...
String frac = d.substring(14);
int index;
for (index = 1; index < frac.length(); index++) {
char ch = frac.charAt(index);
if (!('0' <= ch && ch <= '9')) {
break;
}
}
if (index - 1 > 3) {
frac = frac.substring(0, 4) + frac.substring(index);
d = d.substring(0, 14) + frac;
} else if (index - 1 == 1) {
frac = frac.substring(0, index) + "00" + frac.substring(index);
d = d.substring(0, 14) + frac;
} else if (index - 1 == 2) {
frac = frac.substring(0, index) + "0" + frac.substring(index);
d = d.substring(0, 14) + frac;
}
}
return dateF.parse(d);
}
use of java.util.SimpleTimeZone in project robovm by robovm.
the class TimeZoneTest method testCustomTimeZoneDisplayNames.
// http://b/3049014
public void testCustomTimeZoneDisplayNames() {
TimeZone tz0001 = new SimpleTimeZone(60000, "ONE MINUTE");
TimeZone tz0130 = new SimpleTimeZone(5400000, "ONE HOUR, THIRTY");
TimeZone tzMinus0130 = new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY");
assertEquals("GMT+00:01", tz0001.getDisplayName(false, TimeZone.SHORT, Locale.US));
assertEquals("GMT+01:30", tz0130.getDisplayName(false, TimeZone.SHORT, Locale.US));
assertEquals("GMT-01:30", tzMinus0130.getDisplayName(false, TimeZone.SHORT, Locale.US));
}
use of java.util.SimpleTimeZone in project jdk8u_jdk by JetBrains.
the class ZoneInfo method getOffsets.
private int getOffsets(long date, int[] offsets, int type) {
// if dst is never observed, there is no transition.
if (transitions == null) {
int offset = getLastRawOffset();
if (offsets != null) {
offsets[0] = offset;
offsets[1] = 0;
}
return offset;
}
date -= rawOffsetDiff;
int index = getTransitionIndex(date, type);
// FIXME: should support LMT.
if (index < 0) {
int offset = getLastRawOffset();
if (offsets != null) {
offsets[0] = offset;
offsets[1] = 0;
}
return offset;
}
if (index < transitions.length) {
long val = transitions[index];
int offset = this.offsets[(int) (val & OFFSET_MASK)] + rawOffsetDiff;
if (offsets != null) {
int dst = (int) ((val >>> DST_NSHIFT) & 0xfL);
int save = (dst == 0) ? 0 : this.offsets[dst];
offsets[0] = offset - save;
offsets[1] = save;
}
return offset;
}
// beyond the transitions, delegate to SimpleTimeZone if there
// is a rule; otherwise, return rawOffset.
SimpleTimeZone tz = getLastRule();
if (tz != null) {
int rawoffset = tz.getRawOffset();
long msec = date;
if (type != UTC_TIME) {
msec -= rawOffset;
}
int dstoffset = tz.getOffset(msec) - rawOffset;
// Check if it's in a standard-to-daylight transition.
if (dstoffset > 0 && tz.getOffset(msec - dstoffset) == rawoffset) {
dstoffset = 0;
}
if (offsets != null) {
offsets[0] = rawoffset;
offsets[1] = dstoffset;
}
return rawoffset + dstoffset;
}
int offset = getLastRawOffset();
if (offsets != null) {
offsets[0] = offset;
offsets[1] = 0;
}
return offset;
}
Aggregations