Java Code Examples for org.joda.time.DateTimeUtils#getChronology()

The following examples show how to use org.joda.time.DateTimeUtils#getChronology() . 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: 1_DateTimeFormatter.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines the correct chronology to use.
 *
 * @param chrono  the proposed chronology
 * @return the actual chronology
 */
private Chronology selectChronology(Chronology chrono) {
    chrono = DateTimeUtils.getChronology(chrono);
    if (iChrono != null) {
        chrono = iChrono;
    }
    if (iZone != null) {
        chrono = chrono.withZone(iZone);
    }
    return chrono;
}
 
Example 2
Source File: Time_7_DateTimeFormatter_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines the correct chronology to use.
 *
 * @param chrono  the proposed chronology
 * @return the actual chronology
 */
private Chronology selectChronology(Chronology chrono) {
    chrono = DateTimeUtils.getChronology(chrono);
    if (iChrono != null) {
        chrono = iChrono;
    }
    if (iZone != null) {
        chrono = chrono.withZone(iZone);
    }
    return chrono;
}
 
Example 3
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 4
Source File: DateTimeFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines the correct chronology to use.
 *
 * @param chrono  the proposed chronology
 * @return the actual chronology
 */
private Chronology selectChronology(Chronology chrono) {
    chrono = DateTimeUtils.getChronology(chrono);
    if (iChrono != null) {
        chrono = iChrono;
    }
    if (iZone != null) {
        chrono = chrono.withZone(iZone);
    }
    return chrono;
}
 
Example 5
Source File: Cardumen_0073_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Determines the correct chronology to use.
 *
 * @param chrono  the proposed chronology
 * @return the actual chronology
 */
private Chronology selectChronology(Chronology chrono) {
    chrono = DateTimeUtils.getChronology(chrono);
    if (iChrono != null) {
        chrono = iChrono;
    }
    if (iZone != null) {
        chrono = chrono.withZone(iZone);
    }
    return chrono;
}
 
Example 6
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a period from the given interval endpoints.
 *
 * @param startInstant  interval start, in milliseconds
 * @param endInstant  interval end, in milliseconds
 * @param type  which set of fields this period supports, null means standard
 * @param chrono  the chronology to use, null means ISO default
 * @throws IllegalArgumentException if period type is invalid
 */
protected BasePeriod(long startInstant, long endInstant, PeriodType type, Chronology chrono) {
    super();
    type = checkPeriodType(type);
    chrono = DateTimeUtils.getChronology(chrono);
    iType = type;
    iValues = chrono.get(this, startInstant, endInstant);
}
 
Example 7
Source File: HourMinuteSecond.java    From fenixedu-academic with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Creates a new HourMinuteSecond instance with the specified chronology.
 * This instance is immutable and unaffected by this method call.
 * <p>
 * This method retains the values of the fields, thus the result will typically refer to a different instant.
 * <p>
 * The time zone of the specified chronology is ignored, as HourMinuteSecond operates without a time zone.
 * 
 * @param newChronology
 *            the new chronology, null means ISO
 * @return a copy of this datetime with a different chronology
 * @throws IllegalArgumentException
 *             if the values are invalid for the new chronology
 */
public HourMinuteSecond withChronologyRetainFields(Chronology newChronology) {
    newChronology = DateTimeUtils.getChronology(newChronology);
    newChronology = newChronology.withUTC();
    if (newChronology == getChronology()) {
        return this;
    } else {
        HourMinuteSecond newHourMinuteSecond = new HourMinuteSecond(this, newChronology);
        newChronology.validate(newHourMinuteSecond, getValues());
        return newHourMinuteSecond;
    }
}
 
Example 8
Source File: BaseInterval.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an interval from a start and end instant.
 * 
 * @param startInstant  start of this interval, as milliseconds from 1970-01-01T00:00:00Z.
 * @param endInstant  end of this interval, as milliseconds from 1970-01-01T00:00:00Z.
 * @param chrono  the chronology to use, null is ISO default
 * @throws IllegalArgumentException if the end is before the start
 */
protected BaseInterval(long startInstant, long endInstant, Chronology chrono) {
    super();
    iChronology = DateTimeUtils.getChronology(chrono);
    checkInterval(startInstant, endInstant);
    iStartMillis = startInstant;
    iEndMillis = endInstant;
}
 
Example 9
Source File: ReadableInstantConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the chronology, which is taken from the ReadableInstant.
 * <p>
 * If the passed in chronology is non-null, it is used.
 * Otherwise the chronology from the instant is used.
 * 
 * @param object  the ReadableInstant to convert, must not be null
 * @param chrono  the chronology to use, null means use that from object
 * @return the chronology, never null
 */
public Chronology getChronology(Object object, Chronology chrono) {
    if (chrono == null) {
        chrono = ((ReadableInstant) object).getChronology();
        chrono = DateTimeUtils.getChronology(chrono);
    }
    return chrono;
}
 
Example 10
Source File: BasePartial.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a partial from an Object that represents a time, using the
 * specified chronology.
 * <p>
 * The recognised object types are defined in
 * {@link org.joda.time.convert.ConverterManager ConverterManager} and
 * include ReadableInstant, String, Calendar and Date.
 * <p>
 * The constructor uses the time zone of the chronology specified.
 * Once the constructor is complete, all further calculations are performed
 * without reference to a timezone (by switching to UTC).
 *
 * @param instant  the datetime object
 * @param chronology  the chronology, null means use converter
 * @throws IllegalArgumentException if the date is invalid
 */
protected BasePartial(Object instant, Chronology chronology) {
    super();
    PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
    chronology = converter.getChronology(instant, chronology);
    chronology = DateTimeUtils.getChronology(chronology);
    iChronology = chronology.withUTC();
    iValues = converter.getPartialValues(this, instant, chronology);
}
 
Example 11
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a period from the given millisecond duration, which is only really
 * suitable for durations less than one day.
 * <p>
 * Only fields that are precise will be used.
 * Thus the largest precise field may have a large value.
 *
 * @param duration  the duration, in milliseconds
 * @param type  which set of fields this period supports, null means standard
 * @param chrono  the chronology to use, null means ISO default
 * @throws IllegalArgumentException if period type is invalid
 */
protected BasePeriod(long duration, PeriodType type, Chronology chrono) {
    super();
    type = checkPeriodType(type);
    chrono = DateTimeUtils.getChronology(chrono);
    iType = type;
    iValues = chrono.get(this, duration);
}
 
Example 12
Source File: ReadableInstantConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the chronology, which is taken from the ReadableInstant.
 * <p>
 * If the passed in chronology is non-null, it is used.
 * Otherwise the chronology from the instant is used.
 * 
 * @param object  the ReadableInstant to convert, must not be null
 * @param chrono  the chronology to use, null means use that from object
 * @return the chronology, never null
 */
public Chronology getChronology(Object object, Chronology chrono) {
    if (chrono == null) {
        chrono = ((ReadableInstant) object).getChronology();
        chrono = DateTimeUtils.getChronology(chrono);
    }
    return chrono;
}
 
Example 13
Source File: BaseInterval.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Sets this interval from two millisecond instants and a chronology.
 *
 * @param startInstant  the start of the time interval
 * @param endInstant  the start of the time interval
 * @param chrono  the chronology, not null
 * @throws IllegalArgumentException if the end is before the start
 */
protected void setInterval(long startInstant, long endInstant, Chronology chrono) {
    checkInterval(startInstant, endInstant);
    iStartMillis = startInstant;
    iEndMillis = endInstant;
    iChronology = DateTimeUtils.getChronology(chrono);
}
 
Example 14
Source File: AbstractInstant.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get this object as a MutableDateTime using the same chronology but a different zone.
 * 
 * @param zone time zone to apply, or default if null
 * @return a MutableDateTime using the same millis
 */
public MutableDateTime toMutableDateTime(DateTimeZone zone) {
    Chronology chrono = DateTimeUtils.getChronology(getChronology());
    chrono = chrono.withZone(zone);
    return new MutableDateTime(getMillis(), chrono);
}
 
Example 15
Source File: BaseDateTime.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Checks the specified chronology before storing it, potentially altering it.
 * This method must not access any instance variables.
 * <p>
 * This implementation converts nulls to ISOChronology in the default zone.
 *
 * @param chronology  the chronology to use, may be null
 * @return the chronology to store in this datetime, not null
 */
protected Chronology checkChronology(Chronology chronology) {
    return DateTimeUtils.getChronology(chronology);
}
 
Example 16
Source File: AbstractInstant.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get this object as a DateTime using the same chronology but a different zone.
 * 
 * @param zone time zone to apply, or default if null
 * @return a DateTime using the same millis
 */
public DateTime toDateTime(DateTimeZone zone) {
    Chronology chrono = DateTimeUtils.getChronology(getChronology());
    chrono = chrono.withZone(zone);
    return new DateTime(getMillis(), chrono);
}
 
Example 17
Source File: HourMinuteSecond.java    From fenixedu-academic with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a HourMinuteSecond from an Object that represents a time,
 * using the specified chronology.
 * <p>
 * The recognised object types are defined in {@link org.joda.time.convert.ConverterManager ConverterManager} and include
 * ReadableInstant, String, Calendar and Date.
 * <p>
 * The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations
 * are performed without reference to a timezone (by switching to UTC). The specified chronology overrides that of the object.
 * 
 * @param instant
 *            the datetime object, null means now
 * @param chronology
 *            the chronology, null means ISO default
 * @throws IllegalArgumentException
 *             if the instant is invalid
 */
public HourMinuteSecond(Object instant, Chronology chronology) {
    super(instant, DateTimeUtils.getChronology(chronology));
}
 
Example 18
Source File: AbstractConverter.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Extracts the chronology from an object of this convertor's type
 * where the chronology is specified.
 * <p>
 * This implementation returns the chronology specified, or the
 * ISO chronology in the default zone if null passed in.
 * 
 * @param object  the object to convert
 * @param chrono  the chronology to use, null means ISO default
 * @return the chronology, never null
 */
public Chronology getChronology(Object object, Chronology chrono) {
    return DateTimeUtils.getChronology(chrono);
}
 
Example 19
Source File: BaseDateTime.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Checks the specified chronology before storing it, potentially altering it.
 * This method must not access any instance variables.
 * <p>
 * This implementation converts nulls to ISOChronology in the default zone.
 *
 * @param chronology  the chronology to use, may be null
 * @return the chronology to store in this datetime, not null
 */
protected Chronology checkChronology(Chronology chronology) {
    return DateTimeUtils.getChronology(chronology);
}
 
Example 20
Source File: AbstractInstant.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get this object as a DateTime using the same chronology but a different zone.
 * 
 * @param zone time zone to apply, or default if null
 * @return a DateTime using the same millis
 */
public DateTime toDateTime(DateTimeZone zone) {
    Chronology chrono = DateTimeUtils.getChronology(getChronology());
    chrono = chrono.withZone(zone);
    return new DateTime(getMillis(), chrono);
}