/** * Constructs a time interval converting or copying from another object * that describes an interval. * * @param interval the time interval to copy * @param chrono the chronology to use, null means let converter decide * @throws IllegalArgumentException if the interval is invalid */ protected BaseInterval(Object interval, Chronology chrono) { super(); IntervalConverter converter = ConverterManager.getInstance().getIntervalConverter(interval); if (converter.isReadableInterval(interval, chrono)) { ReadableInterval input = (ReadableInterval) interval; iChronology = (chrono != null ? chrono : input.getChronology()); iStartMillis = input.getStartMillis(); iEndMillis = input.getEndMillis(); } else if (this instanceof ReadWritableInterval) { converter.setInto((ReadWritableInterval) this, interval, chrono); } else { MutableInterval mi = new MutableInterval(); converter.setInto(mi, interval, chrono); iChronology = mi.getChronology(); iStartMillis = mi.getStartMillis(); iEndMillis = mi.getEndMillis(); } checkInterval(iStartMillis, iEndMillis); }
/** * Creates a new period based on another using the {@link ConverterManager}. * * @param period the period to convert * @param type which set of fields this period supports, null means use type from object * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period is invalid * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected BasePeriod(Object period, PeriodType type, Chronology chrono) { super(); PeriodConverter converter = ConverterManager.getInstance().getPeriodConverter(period); type = (type == null ? converter.getPeriodType(period) : type); type = checkPeriodType(type); iType = type; if (this instanceof ReadWritablePeriod) { iValues = new int[size()]; chrono = DateTimeUtils.getChronology(chrono); converter.setInto((ReadWritablePeriod) this, period, chrono); } else { iValues = new MutablePeriod(period, type, chrono).getValues(); } }
/** * Compare two objects against only the range of date time fields as * specified in the constructor. * * @param lhsObj the first object, * logically on the left of a < comparison, null means now * @param rhsObj the second object, * logically on the right of a < comparison, null means now * @return zero if order does not matter, * negative value if lhsObj < rhsObj, positive value otherwise. * @throws IllegalArgumentException if either argument is not supported */ public int compare(Object lhsObj, Object rhsObj) { InstantConverter conv = ConverterManager.getInstance().getInstantConverter(lhsObj); Chronology lhsChrono = conv.getChronology(lhsObj, (Chronology) null); long lhsMillis = conv.getInstantMillis(lhsObj, lhsChrono); conv = ConverterManager.getInstance().getInstantConverter(rhsObj); Chronology rhsChrono = conv.getChronology(rhsObj, (Chronology) null); long rhsMillis = conv.getInstantMillis(rhsObj, rhsChrono); if (iLowerLimit != null) { lhsMillis = iLowerLimit.getField(lhsChrono).roundFloor(lhsMillis); rhsMillis = iLowerLimit.getField(rhsChrono).roundFloor(rhsMillis); } if (iUpperLimit != null) { lhsMillis = iUpperLimit.getField(lhsChrono).remainder(lhsMillis); rhsMillis = iUpperLimit.getField(rhsChrono).remainder(rhsMillis); } if (lhsMillis < rhsMillis) { return -1; } else if (lhsMillis > rhsMillis) { return 1; } else { return 0; } }
/** * Test constructor (Object=null) */ public void testConstructor_badconverterObject() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); DateMidnight test = new DateMidnight(new Integer(0)); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object, DateTimeZone) */ public void testConstructor_badconverterObject_DateTimeZone() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); DateMidnight test = new DateMidnight(new Integer(0), GregorianChronology.getInstance()); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object, Chronology) */ public void testConstructor_badconverterObject_Chronology() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); DateMidnight test = new DateMidnight(new Integer(0), GregorianChronology.getInstance()); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object=null) */ public void testConstructor_badconverterObject() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); Instant test = new Instant(new Integer(0)); assertEquals(ISOChronology.getInstanceUTC(), test.getChronology()); assertEquals(0L, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object=null) */ public void testConstructor_badconverterObject() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); MutableDateTime test = new MutableDateTime(new Integer(0)); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object, DateTimeZone) */ public void testConstructor_badconverterObject_DateTimeZone() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); MutableDateTime test = new MutableDateTime(new Integer(0), GregorianChronology.getInstance()); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object, Chronology) */ public void testConstructor_badconverterObject_Chronology() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); MutableDateTime test = new MutableDateTime(new Integer(0), GregorianChronology.getInstance()); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object=null) */ public void testConstructor_badconverterObject() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); DateTime test = new DateTime(new Integer(0)); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object, DateTimeZone) */ public void testConstructor_badconverterObject_DateTimeZone() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); DateTime test = new DateTime(new Integer(0), GregorianChronology.getInstance()); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }
/** * Test constructor (Object, Chronology) */ public void testConstructor_badconverterObject_Chronology() throws Throwable { try { ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE); DateTime test = new DateTime(new Integer(0), GregorianChronology.getInstance()); assertEquals(ISOChronology.getInstance(), test.getChronology()); assertEquals(0L, test.getMillis()); } finally { ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE); } }