org.joda.time.convert.ConverterManager Java Examples

The following examples show how to use org.joda.time.convert.ConverterManager. 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: BaseInterval.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #2
Source File: BaseInterval.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #4
Source File: DateTimeComparator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example #5
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example #6
Source File: Time_22_BasePeriod_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example #7
Source File: Time_22_BasePeriod_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example #8
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #9
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #10
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #11
Source File: TestInstant_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #12
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #13
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #14
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #15
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #16
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #17
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example #18
Source File: DateTimeComparator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 &lt; comparison, null means now
 * @param rhsObj  the second object,
 *      logically on the right of a &lt; comparison, null means now
 * @return zero if order does not matter,
 *      negative value if lhsObj &lt; 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;
    }
}
 
Example #19
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #20
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #21
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #22
Source File: TestInstant_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #23
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #24
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #25
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #26
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #27
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #28
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #29
Source File: LocalTime.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an instance from an Object that represents a datetime,
 * forcing the time zone to that specified.
 * <p>
 * If the object contains no chronology, <code>ISOChronology</code> is used.
 * If the specified time zone is null, the default zone is used.
 * Once the constructor is completed, the zone is no longer used.
 * <p>
 * The recognised object types are defined in
 * {@link org.joda.time.convert.ConverterManager ConverterManager} and
 * include ReadablePartial, ReadableInstant, String, Calendar and Date.
 * The String formats are described by {@link ISODateTimeFormat#localTimeParser()}.
 * The default String converter ignores the zone and only parses the field values.
 *
 * @param instant  the datetime object
 * @param zone  the time zone
 * @throws IllegalArgumentException if the instant is invalid
 */
public LocalTime(Object instant, DateTimeZone zone) {
    PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
    Chronology chronology = converter.getChronology(instant, zone);
    chronology = DateTimeUtils.getChronology(chronology);
    iChronology = chronology.withUTC();
    int[] values = converter.getPartialValues(this, instant, chronology, ISODateTimeFormat.localTimeParser());
    iLocalMillis = iChronology.getDateTimeMillis(0L, values[0], values[1], values[2], values[3]);
}
 
Example #30
Source File: LocalDateTime.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an instance from an Object that represents a datetime,
 * using the specified chronology.
 * <p>
 * If the chronology is null, ISO in the default time zone is used.
 * Once the constructor is completed, the zone is no longer used.
 * If the instant contains a chronology, it will be ignored.
 * For example, passing a {@code LocalDate} and a different chronology
 * will return a date with the year/month/day from the date applied
 * unaltered to the specified chronology.
 * <p>
 * The recognised object types are defined in
 * {@link org.joda.time.convert.ConverterManager ConverterManager} and
 * include ReadablePartial, ReadableInstant, String, Calendar and Date.
 * The String formats are described by {@link ISODateTimeFormat#localDateOptionalTimeParser()}.
 * The default String converter ignores the zone and only parses the field values.
 *
 * @param instant  the datetime object
 * @param chronology  the chronology
 * @throws IllegalArgumentException if the instant is invalid
 */
public LocalDateTime(Object instant, Chronology chronology) {
    PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
    chronology = converter.getChronology(instant, chronology);
    chronology = DateTimeUtils.getChronology(chronology);
    iChronology = chronology.withUTC();
    int[] values = converter.getPartialValues(this, instant, chronology, ISODateTimeFormat.localDateOptionalTimeParser());
    iLocalMillis = iChronology.getDateTimeMillis(values[0], values[1], values[2], values[3]);
}