use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRegressionTest method Test4151429.
@Test
public void Test4151429() {
try {
TimeZone tz = TimeZone.getTimeZone("GMT");
/*String name =*/
tz.getDisplayName(true, Integer.MAX_VALUE, Locale.getDefault());
errln("IllegalArgumentException not thrown by TimeZone.getDisplayName()");
} catch (IllegalArgumentException e) {
System.out.print("");
}
}
use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRegressionTest method Test4173604.
/**
* TimeZone broken in last hour of year
*/
@Test
public void Test4173604() {
TimeZone pst = TimeZone.getTimeZone("PST");
int o22 = pst.getOffset(1, 1998, 11, 31, Calendar.THURSDAY, 22 * 60 * 60 * 1000);
int o23 = pst.getOffset(1, 1998, 11, 31, Calendar.THURSDAY, 23 * 60 * 60 * 1000);
int o00 = pst.getOffset(1, 1999, 0, 1, Calendar.FRIDAY, 0);
if (o22 != o23 || o22 != o00) {
errln("Offsets should be the same (for PST), but got: " + "12/31 22:00 " + o22 + ", 12/31 23:00 " + o23 + ", 01/01 00:00 " + o00);
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeZone(pst);
cal.clear();
cal.set(1998, Calendar.JANUARY, 1);
int lastDST = cal.get(Calendar.DST_OFFSET);
int transitions = 0;
int delta = 5;
while (cal.get(Calendar.YEAR) < 2000) {
cal.add(Calendar.MINUTE, delta);
if (cal.get(Calendar.DST_OFFSET) != lastDST) {
++transitions;
Calendar t = (Calendar) cal.clone();
t.add(Calendar.MINUTE, -delta);
logln(t.getTime() + " " + t.get(Calendar.DST_OFFSET));
logln(cal.getTime() + " " + (lastDST = cal.get(Calendar.DST_OFFSET)));
}
}
if (transitions != 4) {
errln("Saw " + transitions + " transitions; should have seen 4");
}
}
use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRuleTest method TestBasicTimeZoneCoverage.
@Test
public void TestBasicTimeZoneCoverage() {
TimeZone tz = TimeZone.getTimeZone("PST");
if (tz instanceof BasicTimeZone) {
BasicTimeZone btz = (BasicTimeZone) tz;
int[] offsets = new int[2];
btz.getOffsetFromLocal(Calendar.getInstance().getTimeInMillis(), BasicTimeZone.LOCAL_STD, BasicTimeZone.LOCAL_STD, offsets);
if (offsets[0] > offsets[1]) {
errln("Error calling getOffsetFromLocal().");
}
} else {
logln("Skipping TestBasicTimeZoneCoverage: ICU4J is configured to use JDK TimeZone");
}
}
use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneRuleTest method TestHistoricalRuleBasedTimeZone.
/*
* Test equivalency between OlsonTimeZone and custom RBTZ representing the
* equivalent rules in a certain time range
*/
@Test
public void TestHistoricalRuleBasedTimeZone() {
// Compare to America/New_York with equivalent RBTZ
TimeZone ny = TimeZone.getTimeZone("America/New_York", TimeZone.TIMEZONE_ICU);
// RBTZ
InitialTimeZoneRule ir = new InitialTimeZoneRule("EST", -5 * HOUR, 0);
RuleBasedTimeZone rbtz = new RuleBasedTimeZone("EST5EDT", ir);
DateTimeRule dtr;
AnnualTimeZoneRule tzr;
// Standard time
dtr = new DateTimeRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * HOUR, // Last Sunday in October, at 2AM wall time
DateTimeRule.WALL_TIME);
tzr = new AnnualTimeZoneRule("EST", -5 * HOUR, /* rawOffset */
0, /* dstSavings */
dtr, 1967, 2006);
rbtz.addTransitionRule(tzr);
dtr = new DateTimeRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, true, 2 * HOUR, // SUN>=1 in November, at 2AM wall time
DateTimeRule.WALL_TIME);
tzr = new AnnualTimeZoneRule("EST", -5 * HOUR, 0, dtr, 2007, AnnualTimeZoneRule.MAX_YEAR);
rbtz.addTransitionRule(tzr);
// Daylight saving time
dtr = new DateTimeRule(Calendar.APRIL, -1, Calendar.SUNDAY, 2 * HOUR, // Last Sunday in April, at 2AM wall time
DateTimeRule.WALL_TIME);
tzr = new AnnualTimeZoneRule("EDT", -5 * HOUR, 1 * HOUR, dtr, 1967, 1973);
rbtz.addTransitionRule(tzr);
dtr = new DateTimeRule(Calendar.JANUARY, 6, 2 * HOUR, // January 6, at 2AM wall time
DateTimeRule.WALL_TIME);
tzr = new AnnualTimeZoneRule("EDT", -5 * HOUR, 1 * HOUR, dtr, 1974, 1974);
rbtz.addTransitionRule(tzr);
dtr = new DateTimeRule(Calendar.FEBRUARY, 23, 2 * HOUR, // February 23, at 2AM wall time
DateTimeRule.WALL_TIME);
tzr = new AnnualTimeZoneRule("EDT", -5 * HOUR, 1 * HOUR, dtr, 1975, 1975);
rbtz.addTransitionRule(tzr);
dtr = new DateTimeRule(Calendar.APRIL, -1, Calendar.SUNDAY, 2 * HOUR, // Last Sunday in April, at 2AM wall time
DateTimeRule.WALL_TIME);
tzr = new AnnualTimeZoneRule("EDT", -5 * HOUR, 1 * HOUR, dtr, 1976, 1986);
rbtz.addTransitionRule(tzr);
dtr = new DateTimeRule(Calendar.APRIL, 1, Calendar.SUNDAY, true, 2 * HOUR, // SUN>=1 in April, at 2AM wall time
DateTimeRule.WALL_TIME);
tzr = new AnnualTimeZoneRule("EDT", -5 * HOUR, 1 * HOUR, dtr, 1987, 2006);
rbtz.addTransitionRule(tzr);
dtr = new DateTimeRule(Calendar.MARCH, 8, Calendar.SUNDAY, true, 2 * HOUR, // SUN>=8 in March, at 2AM wall time
DateTimeRule.WALL_TIME);
tzr = new AnnualTimeZoneRule("EDT", -5 * HOUR, 1 * HOUR, dtr, 2007, AnnualTimeZoneRule.MAX_YEAR);
rbtz.addTransitionRule(tzr);
// hasEquivalentTransitions
long jan1_1950 = getUTCMillis(1950, Calendar.JANUARY, 1);
long jan1_1967 = getUTCMillis(1971, Calendar.JANUARY, 1);
long jan1_2010 = getUTCMillis(2010, Calendar.JANUARY, 1);
if (!(((BasicTimeZone) ny).hasEquivalentTransitions(rbtz, jan1_1967, jan1_2010))) {
errln("FAIL: The RBTZ must be equivalent to America/New_York between 1967 and 2010");
}
if (((BasicTimeZone) ny).hasEquivalentTransitions(rbtz, jan1_1950, jan1_2010)) {
errln("FAIL: The RBTZ must not be equivalent to America/New_York between 1950 and 2010");
}
// Same with above, but calling RBTZ#hasEquivalentTransitions against OlsonTimeZone
if (!rbtz.hasEquivalentTransitions(ny, jan1_1967, jan1_2010)) {
errln("FAIL: The RBTZ must be equivalent to America/New_York between 1967 and 2010");
}
if (rbtz.hasEquivalentTransitions(ny, jan1_1950, jan1_2010)) {
errln("FAIL: The RBTZ must not be equivalent to America/New_York between 1950 and 2010");
}
// TimeZone APIs
if (ny.hasSameRules(rbtz) || rbtz.hasSameRules(ny)) {
errln("FAIL: hasSameRules must return false");
}
RuleBasedTimeZone rbtzc = (RuleBasedTimeZone) rbtz.clone();
if (!rbtz.hasSameRules(rbtzc) || !rbtz.hasEquivalentTransitions(rbtzc, jan1_1950, jan1_2010)) {
errln("FAIL: hasSameRules/hasEquivalentTransitions must return true for cloned RBTZs");
}
long[] times = { getUTCMillis(2006, Calendar.MARCH, 15), getUTCMillis(2006, Calendar.NOVEMBER, 1), getUTCMillis(2007, Calendar.MARCH, 15), getUTCMillis(2007, Calendar.NOVEMBER, 1), getUTCMillis(2008, Calendar.MARCH, 15), getUTCMillis(2008, Calendar.NOVEMBER, 1) };
int[] offsets1 = new int[2];
int[] offsets2 = new int[2];
for (int i = 0; i < times.length; i++) {
// Check getOffset - must return the same results for these time data
rbtz.getOffset(times[i], false, offsets1);
ny.getOffset(times[i], false, offsets2);
if (offsets1[0] != offsets2[0] || offsets1[1] != offsets2[1]) {
errln("FAIL: Incompatible time zone offsets for ny and rbtz");
}
// Check inDaylightTime
Date d = new Date(times[i]);
if (rbtz.inDaylightTime(d) != ny.inDaylightTime(d)) {
errln("FAIL: Incompatible daylight saving time for ny and rbtz");
}
}
}
use of android.icu.util.TimeZone in project j2objc by google.
the class TimeZoneTest method TestMark.
@Test
public void TestMark() {
String tzid = "America/Argentina/ComodRivadavia";
TimeZone tz = TimeZone.getTimeZone(tzid);
int offset = tz.getOffset(new Date().getTime());
logln(tzid + ":\t" + offset);
List list = Arrays.asList(TimeZone.getAvailableIDs());
if (!list.contains(tzid)) {
errln("Could create the time zone but it is not in getAvailableIDs");
}
}
Aggregations