/** * Gets the chronology, which is the GJChronology if a GregorianCalendar is used, * BuddhistChronology if a BuddhistCalendar is used or ISOChronology otherwise. * The time zone specified is used in preference to that on the calendar. * * @param object the Calendar to convert, must not be null * @param zone the specified zone to use, null means default zone * @return the chronology, never null * @throws NullPointerException if the object is null * @throws ClassCastException if the object is an invalid type */ public Chronology getChronology(Object object, DateTimeZone zone) { if (object.getClass().getName().endsWith(".BuddhistCalendar")) { return BuddhistChronology.getInstance(zone); } else if (object instanceof GregorianCalendar) { GregorianCalendar gc = (GregorianCalendar) object; long cutover = gc.getGregorianChange().getTime(); if (cutover == Long.MIN_VALUE) { return GregorianChronology.getInstance(zone); } else if (cutover == Long.MAX_VALUE) { return JulianChronology.getInstance(zone); } else { return GJChronology.getInstance(zone, cutover, 4); } } else { return ISOChronology.getInstance(zone); } }
public void testToString() { DateTimeZone paris = DateTimeZone.forID("Europe/Paris"); ISOChronology isoParis = ISOChronology.getInstance(paris); assertEquals("ISOChronology[Europe/Paris]", isoParis.toString()); assertEquals("GJChronology[Europe/Paris]", GJChronology.getInstance(paris).toString()); assertEquals("GregorianChronology[Europe/Paris]", GregorianChronology.getInstance(paris).toString()); assertEquals("JulianChronology[Europe/Paris]", JulianChronology.getInstance(paris).toString()); assertEquals("BuddhistChronology[Europe/Paris]", BuddhistChronology.getInstance(paris).toString()); assertEquals("CopticChronology[Europe/Paris]", CopticChronology.getInstance(paris).toString()); assertEquals("EthiopicChronology[Europe/Paris]", EthiopicChronology.getInstance(paris).toString()); assertEquals("IslamicChronology[Europe/Paris]", IslamicChronology.getInstance(paris).toString()); assertEquals("LenientChronology[ISOChronology[Europe/Paris]]", LenientChronology.getInstance(isoParis).toString()); assertEquals("StrictChronology[ISOChronology[Europe/Paris]]", StrictChronology.getInstance(isoParis).toString()); assertEquals("LimitChronology[ISOChronology[Europe/Paris], NoLimit, NoLimit]", LimitChronology.getInstance(isoParis, null, null).toString()); assertEquals("ZonedChronology[ISOChronology[UTC], Europe/Paris]", ZonedChronology.getInstance(isoParis, paris).toString()); }
public void testGetInstantChronology_RI() { DateTime dt = new DateTime(123L, BuddhistChronology.getInstance()); assertEquals(BuddhistChronology.getInstance(), DateTimeUtils.getInstantChronology(dt)); Instant i = new Instant(123L); assertEquals(ISOChronology.getInstanceUTC(), DateTimeUtils.getInstantChronology(i)); AbstractInstant ai = new AbstractInstant() { public long getMillis() { return 0L; } public Chronology getChronology() { return null; // testing for this } }; assertEquals(ISOChronology.getInstance(), DateTimeUtils.getInstantChronology(ai)); assertEquals(ISOChronology.getInstance(), DateTimeUtils.getInstantChronology(null)); }
public void testMinusYears_int() { YearMonthDay test = new YearMonthDay(2002, 5, 3, BuddhistChronology.getInstance()); YearMonthDay result = test.minusYears(1); YearMonthDay expected = new YearMonthDay(2001, 5, 3, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minusYears(0); assertSame(test, result); }
public void testConstructor_Object_Chronology1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Interval base = new Interval(dt1, dt2); Interval test = new Interval(base, BuddhistChronology.getInstance()); assertEquals(dt1.getMillis(), test.getStartMillis()); assertEquals(dt2.getMillis(), test.getEndMillis()); assertEquals(BuddhistChronology.getInstance(), test.getChronology()); }
public void testPlusDays_int() { YearMonthDay test = new YearMonthDay(2002, 5, 3, BuddhistChronology.getInstance()); YearMonthDay result = test.plusDays(1); YearMonthDay expected = new YearMonthDay(2002, 5, 4, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusDays(0); assertSame(test, result); }
public void testPlus_RP() { MonthDay test = new MonthDay(6, 5, BuddhistChronology.getInstance()); MonthDay result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8)); MonthDay expected = new MonthDay(8, 9, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plus((ReadablePeriod) null); assertSame(test, result); }
public void testMinus_RP() { YearMonthDay test = new YearMonthDay(2002, 5, 3, BuddhistChronology.getInstance()); YearMonthDay result = test.minus(new Period(1, 1, 1, 1, 1, 1, 1, 1)); YearMonthDay expected = new YearMonthDay(2001, 4, 2, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minus((ReadablePeriod) null); assertSame(test, result); }
public void testGetChronology_Object_Zone() throws Exception { GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris")); assertEquals(GJChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(cal, MOSCOW)); cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow")); assertEquals(GJChronology.getInstance(), CalendarConverter.INSTANCE.getChronology(cal, (DateTimeZone) null)); cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow")); cal.setGregorianChange(new Date(0L)); assertEquals(GJChronology.getInstance(MOSCOW, 0L, 4), CalendarConverter.INSTANCE.getChronology(cal, MOSCOW)); cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow")); cal.setGregorianChange(new Date(Long.MAX_VALUE)); assertEquals(JulianChronology.getInstance(PARIS), CalendarConverter.INSTANCE.getChronology(cal, PARIS)); cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow")); cal.setGregorianChange(new Date(Long.MIN_VALUE)); assertEquals(GregorianChronology.getInstance(PARIS), CalendarConverter.INSTANCE.getChronology(cal, PARIS)); Calendar uc = new MockUnknownCalendar(TimeZone.getTimeZone("Europe/Moscow")); assertEquals(ISOChronology.getInstance(PARIS), CalendarConverter.INSTANCE.getChronology(uc, PARIS)); try { Calendar bc = (Calendar) Class.forName("sun.util.BuddhistCalendar").newInstance(); bc.setTimeZone(TimeZone.getTimeZone("Europe/Moscow")); assertEquals(BuddhistChronology.getInstance(PARIS), CalendarConverter.INSTANCE.getChronology(bc, PARIS)); } catch (ClassNotFoundException ex) { // ignore } }
public void testGetChronology_Object_nullChronology() throws Exception { GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris")); assertEquals(GJChronology.getInstance(PARIS), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null)); cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow")); cal.setGregorianChange(new Date(0L)); assertEquals(GJChronology.getInstance(MOSCOW, 0L, 4), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null)); cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow")); cal.setGregorianChange(new Date(Long.MAX_VALUE)); assertEquals(JulianChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null)); cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow")); cal.setGregorianChange(new Date(Long.MIN_VALUE)); assertEquals(GregorianChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null)); cal = new GregorianCalendar(new MockUnknownTimeZone()); assertEquals(GJChronology.getInstance(), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null)); Calendar uc = new MockUnknownCalendar(TimeZone.getTimeZone("Europe/Moscow")); assertEquals(ISOChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(uc, (Chronology) null)); try { Calendar bc = (Calendar) Class.forName("sun.util.BuddhistCalendar").newInstance(); bc.setTimeZone(TimeZone.getTimeZone("Europe/Moscow")); assertEquals(BuddhistChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(bc, (Chronology) null)); } catch (ClassNotFoundException ex) { // ignore } }
public void testSetIntoInterval_Object_Chronology7() throws Exception { MutableInterval m = new MutableInterval(-1000L, 1000L); StringConverter.INSTANCE.setInto(m, "2003-08-09/2004-06-09", BuddhistChronology.getInstance()); assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, BuddhistChronology.getInstance()), m.getStart()); assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, BuddhistChronology.getInstance()), m.getEnd()); assertEquals(BuddhistChronology.getInstance(), m.getChronology()); }
public void testSetIntoInterval_Object_Chronology8() throws Exception { MutableInterval m = new MutableInterval(-1000L, 1000L); StringConverter.INSTANCE.setInto(m, "2003-08-09T+06:00/2004-06-09T+07:00", BuddhistChronology.getInstance(EIGHT)); assertEquals(new DateTime(2003, 8, 9, 0, 0, 0, 0, BuddhistChronology.getInstance(SIX)).withZone(EIGHT), m.getStart()); assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0, BuddhistChronology.getInstance(SEVEN)).withZone(EIGHT), m.getEnd()); assertEquals(BuddhistChronology.getInstance(EIGHT), m.getChronology()); }
public void testSetIntoInterval_Object1() throws Exception { Interval i = new Interval(0L, 123L, CopticChronology.getInstance()); MutableInterval m = new MutableInterval(-1000L, 1000L, BuddhistChronology.getInstance()); ReadableIntervalConverter.INSTANCE.setInto(m, i, null); assertEquals(0L, m.getStartMillis()); assertEquals(123L, m.getEndMillis()); assertEquals(CopticChronology.getInstance(), m.getChronology()); }
public void testSetIntoInterval_Object2() throws Exception { Interval i = new Interval(0L, 123L, CopticChronology.getInstance()); MutableInterval m = new MutableInterval(-1000L, 1000L, BuddhistChronology.getInstance()); ReadableIntervalConverter.INSTANCE.setInto(m, i, GJChronology.getInstance()); assertEquals(0L, m.getStartMillis()); assertEquals(123L, m.getEndMillis()); assertEquals(GJChronology.getInstance(), m.getChronology()); }
public void testSetIntoInterval_Object3() throws Exception { MutableInterval i = new MutableInterval(0L, 123L) { public Chronology getChronology() { return null; // bad } }; MutableInterval m = new MutableInterval(-1000L, 1000L, BuddhistChronology.getInstance()); ReadableIntervalConverter.INSTANCE.setInto(m, i, GJChronology.getInstance()); assertEquals(0L, m.getStartMillis()); assertEquals(123L, m.getEndMillis()); assertEquals(GJChronology.getInstance(), m.getChronology()); }
public void testSetIntoInterval_Object4() throws Exception { MutableInterval i = new MutableInterval(0L, 123L) { public Chronology getChronology() { return null; // bad } }; MutableInterval m = new MutableInterval(-1000L, 1000L, BuddhistChronology.getInstance()); ReadableIntervalConverter.INSTANCE.setInto(m, i, null); assertEquals(0L, m.getStartMillis()); assertEquals(123L, m.getEndMillis()); assertEquals(ISOChronology.getInstance(), m.getChronology()); }
public void testPlus_RP() { YearMonthDay test = new YearMonthDay(2002, 5, 3, BuddhistChronology.getInstance()); YearMonthDay result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8)); YearMonthDay expected = new YearMonthDay(2003, 7, 7, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plus((ReadablePeriod) null); assertSame(test, result); }
public void testGetIntervalChronology_RI_RI() { DateTime dt1 = new DateTime(123L, BuddhistChronology.getInstance()); DateTime dt2 = new DateTime(123L, CopticChronology.getInstance()); assertEquals(BuddhistChronology.getInstance(), DateTimeUtils.getIntervalChronology(dt1, dt2)); assertEquals(BuddhistChronology.getInstance(), DateTimeUtils.getIntervalChronology(dt1, null)); assertEquals(CopticChronology.getInstance(), DateTimeUtils.getIntervalChronology(null, dt2)); assertEquals(ISOChronology.getInstance(), DateTimeUtils.getIntervalChronology(null, null)); }
public void testPlus_RP() { YearMonth test = new YearMonth(2002, 5, BuddhistChronology.getInstance()); YearMonth result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8)); YearMonth expected = new YearMonth(2003, 7, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plus((ReadablePeriod) null); assertSame(test, result); }
public void testPlusYears_int() { YearMonth test = new YearMonth(2002, 5, BuddhistChronology.getInstance()); YearMonth result = test.plusYears(1); YearMonth expected = new YearMonth(2003, 5, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusYears(0); assertSame(test, result); }
public void testPlusMonths_int() { YearMonth test = new YearMonth(2002, 5, BuddhistChronology.getInstance()); YearMonth result = test.plusMonths(1); YearMonth expected = new YearMonth(2002, 6, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusMonths(0); assertSame(test, result); }
public void testMinus_RP() { YearMonth test = new YearMonth(2002, 5, BuddhistChronology.getInstance()); YearMonth result = test.minus(new Period(1, 1, 1, 1, 1, 1, 1, 1)); YearMonth expected = new YearMonth(2001, 4, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minus((ReadablePeriod) null); assertSame(test, result); }
public void testMinusYears_int() { YearMonth test = new YearMonth(2002, 5, BuddhistChronology.getInstance()); YearMonth result = test.minusYears(1); YearMonth expected = new YearMonth(2001, 5, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minusYears(0); assertSame(test, result); }
public void testPlusYears_int() { YearMonthDay test = new YearMonthDay(2002, 5, 3, BuddhistChronology.getInstance()); YearMonthDay result = test.plusYears(1); YearMonthDay expected = new YearMonthDay(2003, 5, 3, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusYears(0); assertSame(test, result); }
public void testPlus_RP() { TimeOfDay test = new TimeOfDay(10, 20, 30, 40, BuddhistChronology.getInstance()); TimeOfDay result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8)); TimeOfDay expected = new TimeOfDay(15, 26, 37, 48, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plus((ReadablePeriod) null); assertSame(test, result); }
public void testPlusHours_int() { TimeOfDay test = new TimeOfDay(1, 2, 3, 4, BuddhistChronology.getInstance()); TimeOfDay result = test.plusHours(1); TimeOfDay expected = new TimeOfDay(2, 2, 3, 4, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusHours(0); assertSame(test, result); }
public void testPlusMinutes_int() { TimeOfDay test = new TimeOfDay(1, 2, 3, 4, BuddhistChronology.getInstance()); TimeOfDay result = test.plusMinutes(1); TimeOfDay expected = new TimeOfDay(1, 3, 3, 4, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusMinutes(0); assertSame(test, result); }
public void testPlusSeconds_int() { TimeOfDay test = new TimeOfDay(1, 2, 3, 4, BuddhistChronology.getInstance()); TimeOfDay result = test.plusSeconds(1); TimeOfDay expected = new TimeOfDay(1, 2, 4, 4, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusSeconds(0); assertSame(test, result); }
public void testPlusMillis_int() { TimeOfDay test = new TimeOfDay(1, 2, 3, 4, BuddhistChronology.getInstance()); TimeOfDay result = test.plusMillis(1); TimeOfDay expected = new TimeOfDay(1, 2, 3, 5, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusMillis(0); assertSame(test, result); }
public void testMinus_RP() { TimeOfDay test = new TimeOfDay(10, 20, 30, 40, BuddhistChronology.getInstance()); TimeOfDay result = test.minus(new Period(1, 1, 1, 1, 1, 1, 1, 1)); TimeOfDay expected = new TimeOfDay(9, 19, 29, 39, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minus((ReadablePeriod) null); assertSame(test, result); }
public void testMinusHours_int() { TimeOfDay test = new TimeOfDay(1, 2, 3, 4, BuddhistChronology.getInstance()); TimeOfDay result = test.minusHours(1); TimeOfDay expected = new TimeOfDay(0, 2, 3, 4, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minusHours(0); assertSame(test, result); }
public void testMinusMinutes_int() { TimeOfDay test = new TimeOfDay(1, 2, 3, 4, BuddhistChronology.getInstance()); TimeOfDay result = test.minusMinutes(1); TimeOfDay expected = new TimeOfDay(1, 1, 3, 4, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minusMinutes(0); assertSame(test, result); }
public void testMinusSeconds_int() { TimeOfDay test = new TimeOfDay(1, 2, 3, 4, BuddhistChronology.getInstance()); TimeOfDay result = test.minusSeconds(1); TimeOfDay expected = new TimeOfDay(1, 2, 2, 4, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minusSeconds(0); assertSame(test, result); }
public void testMinusMillis_int() { TimeOfDay test = new TimeOfDay(1, 2, 3, 4, BuddhistChronology.getInstance()); TimeOfDay result = test.minusMillis(1); TimeOfDay expected = new TimeOfDay(1, 2, 3, 3, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.minusMillis(0); assertSame(test, result); }
public void testPlusMonths_int() { YearMonthDay test = new YearMonthDay(2002, 5, 3, BuddhistChronology.getInstance()); YearMonthDay result = test.plusMonths(1); YearMonthDay expected = new YearMonthDay(2002, 6, 3, BuddhistChronology.getInstance()); assertEquals(expected, result); result = test.plusMonths(0); assertSame(test, result); }