Java Code Examples for android.icu.util.Calendar#clone()
The following examples show how to use
android.icu.util.Calendar#clone() .
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: CompatibilityTest.java From j2objc with Apache License 2.0 | 6 votes |
void marchByDelta(Calendar cal, int delta) { Calendar cur = (Calendar)cal.clone(); int initialDOW = cur.get(Calendar.DAY_OF_WEEK); int DOW, newDOW = initialDOW; do { DOW = newDOW; logln("DOW = " + DOW + " " + cur.getTime()); cur.add(Calendar.DAY_OF_WEEK, delta); newDOW = cur.get(Calendar.DAY_OF_WEEK); int expectedDOW = 1 + (DOW + delta - 1) % 7; if (newDOW != expectedDOW) { errln("Day of week should be " + expectedDOW + " instead of " + newDOW + " on " + cur.getTime()); return; } } while (newDOW != initialDOW); }
Example 2
Source File: RelativeDateFormat.java From j2objc with Apache License 2.0 | 5 votes |
/** * @return the number of days in "until-now" */ private static int dayDifference(Calendar until) { Calendar nowCal = (Calendar)until.clone(); Date nowDate = new Date(System.currentTimeMillis()); nowCal.clear(); nowCal.setTime(nowDate); int dayDiff = until.get(Calendar.JULIAN_DAY) - nowCal.get(Calendar.JULIAN_DAY); return dayDiff; }
Example 3
Source File: CompatibilityTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestClonesUnique908() { Calendar c = Calendar.getInstance(); Calendar d = (Calendar)c.clone(); c.set(Calendar.MILLISECOND, 123); d.set(Calendar.MILLISECOND, 456); if (c.get(Calendar.MILLISECOND) != 123 || d.get(Calendar.MILLISECOND) != 456) { errln("FAIL: Clones share fields"); } }
Example 4
Source File: IBMCalendarTest.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void TestAmbiguousWallTimeAPIs() { Calendar cal = Calendar.getInstance(); assertEquals("Default repeated wall time option", cal.getRepeatedWallTimeOption(), Calendar.WALLTIME_LAST); assertEquals("Default skipped wall time option", cal.getSkippedWallTimeOption(), Calendar.WALLTIME_LAST); Calendar cal2 = (Calendar)cal.clone(); assertTrue("Equality", cal2.equals(cal)); assertTrue("Hash code", cal.hashCode() == cal2.hashCode()); cal2.setRepeatedWallTimeOption(Calendar.WALLTIME_FIRST); cal2.setSkippedWallTimeOption(Calendar.WALLTIME_FIRST); assertFalse("Equality after mod", cal2.equals(cal)); assertFalse("Hash code after mod", cal.hashCode() == cal2.hashCode()); assertEquals("getRepeatedWallTimeOption after mod", cal2.getRepeatedWallTimeOption(), Calendar.WALLTIME_FIRST); assertEquals("getSkippedWallTimeOption after mod", cal2.getSkippedWallTimeOption(), Calendar.WALLTIME_FIRST); try { cal.setRepeatedWallTimeOption(Calendar.WALLTIME_NEXT_VALID); errln("IAE expected on setRepeatedWallTimeOption(WALLTIME_NEXT_VALID"); } catch (IllegalArgumentException e) { // expected } }
Example 5
Source File: CalendarRegressionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * Calendar and GregorianCalendar hashCode() methods need improvement. * Calendar needs a good implementation that subclasses can override, and * GregorianCalendar should use that implementation. */ @Test public void Test4136399() { /* * Note: This test is actually more strict than it has to be. * Technically, there is no requirement that unequal objects have * unequal hashes. We only require equal objects to have equal hashes. * It is desirable for unequal objects to have distributed hashes, but * there is no hard requirement here. * * In this test we make assumptions about certain attributes of calendar * objects getting represented in the hash, which need not always be the * case (although it does work currently with the given test). */ Calendar a = Calendar.getInstance(); Calendar b = (Calendar)a.clone(); if (a.hashCode() != b.hashCode()) { errln("Calendar hash code unequal for cloned objects"); } TimeZone atz1 = a.getTimeZone(); TimeZone atz2 = (TimeZone)atz1.clone(); if(!atz1.equals(atz2)){ errln("The clone timezones are not equal"); } if(atz1.hashCode()!=atz2.hashCode()){ errln("TimeZone hash code unequal for cloned objects"); } b.setMinimalDaysInFirstWeek(7 - a.getMinimalDaysInFirstWeek()); if (a.hashCode() == b.hashCode()) { errln("Calendar hash code ignores minimal days in first week"); } b.setMinimalDaysInFirstWeek(a.getMinimalDaysInFirstWeek()); b.setFirstDayOfWeek((a.getFirstDayOfWeek() % 7) + 1); // Next day if (a.hashCode() == b.hashCode()) { errln("Calendar hash code ignores first day of week"); } b.setFirstDayOfWeek(a.getFirstDayOfWeek()); b.setLenient(!a.isLenient()); if (a.hashCode() == b.hashCode()) { errln("Calendar hash code ignores lenient setting"); } b.setLenient(a.isLenient()); // Assume getTimeZone() returns a reference, not a clone // of a reference -- this is true as of this writing TimeZone atz = a.getTimeZone(); TimeZone btz = b.getTimeZone(); btz.setRawOffset(atz.getRawOffset() + 60*60*1000); if(atz.hashCode()== btz.hashCode()){ errln(atz.hashCode()+"=="+btz.hashCode()); } if (a.getTimeZone()!= b.getTimeZone() && a.hashCode() == b.hashCode()) { errln("Calendar hash code ignores zone"); } b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset()); GregorianCalendar c = new GregorianCalendar(); GregorianCalendar d = (GregorianCalendar)c.clone(); if (c.hashCode() != d.hashCode()) { errln("GregorianCalendar hash code unequal for clones objects"); } Date cutover = c.getGregorianChange(); d.setGregorianChange(new Date(cutover.getTime() + 24*60*60*1000)); if (c.hashCode() == d.hashCode()) { errln("GregorianCalendar hash code ignores cutover"); } }
Example 6
Source File: SimpleDateFormat.java From j2objc with Apache License 2.0 | 2 votes |
/** * Package-private constructor that allows a subclass to specify * whether it supports fast formatting. * * TODO make this API public. */ SimpleDateFormat(String pattern, DateFormatSymbols formatData, Calendar calendar, ULocale locale, boolean useFastFormat, String override) { this(pattern, (DateFormatSymbols)formatData.clone(), (Calendar)calendar.clone(), null, locale, useFastFormat,override); }