Java Code Examples for android.icu.util.TimeZone#useDaylightTime()
The following examples show how to use
android.icu.util.TimeZone#useDaylightTime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeZoneTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestVariousAPI518() { TimeZone time_zone = TimeZone.getTimeZone("PST"); Calendar cal = Calendar.getInstance(); cal.set(1997, Calendar.APRIL, 30); Date d = cal.getTime(); logln("The timezone is " + time_zone.getID()); if (time_zone.inDaylightTime(d) != true) errln("FAIL: inDaylightTime returned false"); if (time_zone.useDaylightTime() != true) errln("FAIL: useDaylightTime returned false"); if (time_zone.getRawOffset() != -8*millisPerHour) errln( "FAIL: getRawOffset returned wrong value"); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(d); if (time_zone.getOffset(GregorianCalendar.AD, gc.get(GregorianCalendar.YEAR), gc.get(GregorianCalendar.MONTH), gc.get(GregorianCalendar.DAY_OF_MONTH), gc.get(GregorianCalendar.DAY_OF_WEEK), 0) != -7*millisPerHour) errln("FAIL: getOffset returned wrong value"); }
Example 2
Source File: TimeZoneTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestOddTimeZoneNames() { for (int i = 0; i < timeZoneTestNames.length; i += 2) { String funkyName = timeZoneTestNames[i]; String correctName = timeZoneTestNames[i+1]; TimeZone ftz = TimeZone.getTimeZone(funkyName); TimeZone ctz = TimeZone.getTimeZone(correctName); String fdn = ftz.getDisplayName(); long fro = ftz.getRawOffset(); long fds = ftz.getDSTSavings(); boolean fdy = ftz.useDaylightTime(); String cdn = ctz.getDisplayName(); long cro = ctz.getRawOffset(); long cds = ctz.getDSTSavings(); boolean cdy = ctz.useDaylightTime(); if (!fdn.equals(cdn)) { logln("display name (" + funkyName + ", " + correctName + ") expected: " + cdn + " but got: " + fdn); } else if (fro != cro) { logln("offset (" + funkyName + ", " + correctName + ") expected: " + cro + " but got: " + fro); } else if (fds != cds) { logln("daylight (" + funkyName + ", " + correctName + ") expected: " + cds + " but got: " + fds); } else if (fdy != cdy) { logln("uses daylight (" + funkyName + ", " + correctName + ") expected: " + cdy + " but got: " + fdy); } else { // no error, assume we're referencing the same internal java object } } }
Example 3
Source File: TimeZoneTest.java From j2objc with Apache License 2.0 | 4 votes |
ZoneDescriptor(TimeZone zone) { this.id = zone.getID(); this.offset = zone.getRawOffset() / 60000; this.daylight = zone.useDaylightTime(); }
Example 4
Source File: TimeZoneRegressionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * Test setRawOffset works OK with system timezone */ @Test public void TestT5280() { boolean isJdkZone = (TimeZone.getDefaultTimeZoneType() == TimeZone.TIMEZONE_JDK); String[] tzids = TimeZone.getAvailableIDs(); for (int i = 0; i < tzids.length; i++) { TimeZone tz = TimeZone.getTimeZone(tzids[i]); boolean useDst = tz.useDaylightTime(); // Increase offset for 30 minutes int newRawOffset = tz.getRawOffset() + 30*60*1000; try { tz.setRawOffset(newRawOffset); } catch (Exception e) { errln("FAIL: setRawOffset throws an exception"); } int offset = tz.getRawOffset(); if (offset != newRawOffset) { if (isJdkZone) { // JDK TimeZone#setRawOffset() only update the last rule, and getRawOffset() returns // the current raw offset. Therefore, they might be different. logln("Modified zone(" + tz.getID() + ") - getRawOffset returns " + offset + "/ Expected: " + newRawOffset); } else { errln("FAIL: Modified zone(" + tz.getID() + ") - getRawOffset returns " + offset + "/ Expected: " + newRawOffset); } } // Ticket#5917 // Check if DST observation status is not unexpectedly changed. boolean newDst = tz.useDaylightTime(); if (useDst != newDst) { errln("FAIL: Modified zone(" + tz.getID() + ") - useDaylightTime has changed from " + useDst + " to " + newDst); } // Make sure the offset is preserved in a clone TimeZone tzClone = (TimeZone)tz.clone(); int offsetC = tzClone.getRawOffset(); if (offsetC != newRawOffset) { if (isJdkZone) { logln("Cloned modified zone(" + tz.getID() + ") - getRawOffset returns " + offsetC + "/ Expected: " + newRawOffset); } else { errln("FAIL: Cloned modified zone(" + tz.getID() + ") - getRawOffset returns " + offsetC + "/ Expected: " + newRawOffset); } } if (offset != offsetC) { errln("FAIL: Different raw offset - Original:" + offset + ", Cloned:" + offsetC); } } }
Example 5
Source File: TimeZoneBoundaryTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * Given a date, a TimeZone, and expected values for inDaylightTime, * useDaylightTime, zone and DST offset, verify that this is the case. */ void verifyDST(String tag, Calendar cal, TimeZone time_zone, boolean expUseDaylightTime, boolean expInDaylightTime, int expRawOffset, int expOffset) { Date d = cal.getTime(); logln("-- " + tag + ": " + d + " in zone " + time_zone.getID() + " (" + d.getTime()/3600000.0 + ")"); if (time_zone.inDaylightTime(d) == expInDaylightTime) logln("PASS: inDaylightTime = " + time_zone.inDaylightTime(d)); else errln("FAIL: inDaylightTime = " + time_zone.inDaylightTime(d)); if (time_zone.useDaylightTime() == expUseDaylightTime) logln("PASS: useDaylightTime = " + time_zone.useDaylightTime()); else errln("FAIL: useDaylightTime = " + time_zone.useDaylightTime()); if (time_zone.getRawOffset() == expRawOffset) logln("PASS: getRawOffset() = " + expRawOffset/(double)ONE_HOUR); else errln("FAIL: getRawOffset() = " + time_zone.getRawOffset()/(double)ONE_HOUR + "; expected " + expRawOffset/(double)ONE_HOUR); //GregorianCalendar gc = new GregorianCalendar(time_zone); //gc.setTime(d); int offset = time_zone.getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_WEEK), ((cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE)) * 60 + cal.get(Calendar.SECOND)) * 1000 + cal.get(Calendar.MILLISECOND)); if (offset == expOffset) logln("PASS: getOffset() = " + offset/(double)ONE_HOUR); else { logln("era=" + cal.get(Calendar.ERA) + ", year=" + cal.get(Calendar.YEAR) + ", month=" + cal.get(Calendar.MONTH) + ", dom=" + cal.get(Calendar.DAY_OF_MONTH) + ", dow=" + cal.get(Calendar.DAY_OF_WEEK) + ", time-of-day=" + (((cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE)) * 60 + cal.get(Calendar.SECOND)) * 1000 + cal.get(Calendar.MILLISECOND)) / 3600000.0 + " hours"); errln("FAIL: getOffset() = " + offset/(double)ONE_HOUR + "; expected " + expOffset/(double)ONE_HOUR); } }
Example 6
Source File: TimeZoneBoundaryTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * Find boundaries by stepping. */ void findBoundariesStepwise(int year, long interval, TimeZone z, int expectedChanges) { java.util.Calendar tempcal = java.util.Calendar.getInstance(); tempcal.clear(); tempcal.set(year, Calendar.JANUARY, 1); Date d = tempcal.getTime(); long time = d.getTime(); // ms long limit = time + ONE_YEAR + ONE_DAY; boolean lastState = z.inDaylightTime(d); int changes = 0; logln("-- Zone " + z.getID() + " starts in " + year + " with DST = " + lastState); logln("useDaylightTime = " + z.useDaylightTime()); while (time < limit) { d.setTime(time); boolean state = z.inDaylightTime(d); if (state != lastState) { logln((state ? "Entry " : "Exit ") + "at " + d); lastState = state; ++changes; } time += interval; } if (changes == 0) { if (!lastState && !z.useDaylightTime()) logln("No DST"); else errln("FAIL: DST all year, or no DST with true useDaylightTime"); } else if (changes != 2) { errln("FAIL: " + changes + " changes seen; should see 0 or 2"); } else if (!z.useDaylightTime()) { errln("FAIL: useDaylightTime false but 2 changes seen"); } if (changes != expectedChanges) { errln("FAIL: " + changes + " changes seen; expected " + expectedChanges); } }