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);
}
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;
}
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);
}
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);
}
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];
}
Aggregations