Search in sources :

Example 31 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class DateTimeFormatter method printTo.

/**
     * Prints a ReadableInstant, using the chronology supplied by the instant.
     *
     * @param appendable  the destination to format to, not null
     * @param instant  instant to format, null means now
     * @since 2.0
     */
public void printTo(Appendable appendable, ReadableInstant instant) throws IOException {
    long millis = DateTimeUtils.getInstantMillis(instant);
    Chronology chrono = DateTimeUtils.getInstantChronology(instant);
    printTo(appendable, millis, chrono);
}
Also used : Chronology(org.joda.time.Chronology)

Example 32 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class GJChronology method getDateTimeMillis.

public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) throws IllegalArgumentException {
    Chronology base;
    if ((base = getBase()) != null) {
        return base.getDateTimeMillis(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
    }
    // Assume date is Gregorian.
    long instant;
    try {
        instant = iGregorianChronology.getDateTimeMillis(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
    } catch (IllegalFieldValueException ex) {
        if (monthOfYear != 2 || dayOfMonth != 29) {
            throw ex;
        }
        instant = iGregorianChronology.getDateTimeMillis(year, monthOfYear, 28, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
        if (instant >= iCutoverMillis) {
            throw ex;
        }
    }
    if (instant < iCutoverMillis) {
        // Maybe it's Julian.
        instant = iJulianChronology.getDateTimeMillis(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
        if (instant >= iCutoverMillis) {
            // Okay, it's in the illegal cutover gap.
            throw new IllegalArgumentException("Specified date does not exist");
        }
    }
    return instant;
}
Also used : IllegalFieldValueException(org.joda.time.IllegalFieldValueException) Chronology(org.joda.time.Chronology)

Example 33 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class GregorianChronology method readResolve.

/**
     * Serialization singleton
     */
private Object readResolve() {
    Chronology base = getBase();
    int minDays = getMinimumDaysInFirstWeek();
    // handle rename of BaseGJChronology
    minDays = (minDays == 0 ? 4 : minDays);
    return base == null ? getInstance(DateTimeZone.UTC, minDays) : getInstance(base.getZone(), minDays);
}
Also used : Chronology(org.joda.time.Chronology)

Example 34 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class JulianChronology method readResolve.

/**
     * Serialization singleton
     */
private Object readResolve() {
    Chronology base = getBase();
    int minDays = getMinimumDaysInFirstWeek();
    // handle rename of BaseGJChronology
    minDays = (minDays == 0 ? 4 : minDays);
    return base == null ? getInstance(DateTimeZone.UTC, minDays) : getInstance(base.getZone(), minDays);
}
Also used : Chronology(org.joda.time.Chronology)

Example 35 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class BaseSingleFieldPeriod method between.

//-----------------------------------------------------------------------
/**
     * Calculates the number of whole units between the two specified partial datetimes.
     * <p>
     * The two partials must contain the same fields, for example you can specify
     * two <code>LocalDate</code> objects.
     *
     * @param start  the start partial date, validated to not be null
     * @param end  the end partial date, validated to not be null
     * @param zeroInstance  the zero instance constant, must not be null
     * @return the period
     * @throws IllegalArgumentException if the partials are null or invalid
     */
protected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance) {
    if (start == null || end == null) {
        throw new IllegalArgumentException("ReadablePartial objects must not be null");
    }
    if (start.size() != end.size()) {
        throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
    }
    for (int i = 0, isize = start.size(); i < isize; i++) {
        if (start.getFieldType(i) != end.getFieldType(i)) {
            throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
        }
    }
    if (DateTimeUtils.isContiguous(start) == false) {
        throw new IllegalArgumentException("ReadablePartial objects must be contiguous");
    }
    Chronology chrono = DateTimeUtils.getChronology(start.getChronology()).withUTC();
    int[] values = chrono.get(zeroInstance, chrono.set(start, START_1972), chrono.set(end, START_1972));
    return values[0];
}
Also used : Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology)

Aggregations

Chronology (org.joda.time.Chronology)69 DateTime (org.joda.time.DateTime)32 ISOChronology (org.joda.time.chrono.ISOChronology)30 GJChronology (org.joda.time.chrono.GJChronology)18 BuddhistChronology (org.joda.time.chrono.BuddhistChronology)17 LocalDate (org.joda.time.LocalDate)14 DateTimeZone (org.joda.time.DateTimeZone)13 MutableDateTime (org.joda.time.MutableDateTime)7 LocalDateTime (org.joda.time.LocalDateTime)4 ReadableDateTime (org.joda.time.ReadableDateTime)4 JulianChronology (org.joda.time.chrono.JulianChronology)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Serializable (java.io.Serializable)2 Date (java.util.Date)2 Duration (org.joda.time.Duration)2 Period (org.joda.time.Period)2 ReadableDuration (org.joda.time.ReadableDuration)2 ReadableInstant (org.joda.time.ReadableInstant)2 ReadablePartial (org.joda.time.ReadablePartial)2 Calendar (java.util.Calendar)1