/** * Serialization singleton. */ private Object readResolve() { Chronology base = getBase(); return base == null ? getInstanceUTC() : getInstance(base.getZone()); }
if (zone == DateTimeZone.UTC) { chrono = new IslamicChronology(null, null, leapYears); chrono = new IslamicChronology( LimitChronology.getInstance(chrono, lowerLimit, null), null, leapYears); } else { chrono = getInstance(DateTimeZone.UTC, leapYears); chrono = new IslamicChronology (ZonedChronology.getInstance(chrono, zone), null, leapYears);
long setYear(long instant, int year) { // optimsed implementation of set, due to fixed months int thisYear = getYear(instant); int dayOfYear = getDayOfYear(instant, thisYear); int millisOfDay = getMillisOfDay(instant); // Current year is leap, and day is leap. if (dayOfYear > 354 && !isLeapYear(year)) { // Moving to a non-leap year, leap day doesn't exist. dayOfYear--; } instant = getYearMonthDayMillis(year, 1, dayOfYear); instant += millisOfDay; return instant; }
long getYearDifference(long minuendInstant, long subtrahendInstant) { // optimsed implementation of getDifference, due to fixed months int minuendYear = getYear(minuendInstant); int subtrahendYear = getYear(subtrahendInstant); // Inlined remainder method to avoid duplicate calls to get. long minuendRem = minuendInstant - getYearMillis(minuendYear); long subtrahendRem = subtrahendInstant - getYearMillis(subtrahendYear); int difference = minuendYear - subtrahendYear; if (minuendRem < subtrahendRem) { difference--; } return difference; }
/** * Checks if this chronology instance equals another. * * @param obj the object to compare to * @return true if equal * @since 2.3 */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof IslamicChronology) { IslamicChronology chrono = (IslamicChronology) obj; return getLeapYearPatternType().index == chrono.getLeapYearPatternType().index && super.equals(obj); } return false; }
/** * Gets the Chronology in a specific time zone. * * @param zone the zone to get the chronology in, null is default * @return the chronology */ public Chronology withZone(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } if (zone == getZone()) { return this; } return getInstance(zone); }
int getDayOfMonth(long millis) { // optimised for simple months int doy = getDayOfYear(millis) - 1; if (doy == 354) { return 30; } return (doy % MONTH_PAIR_LENGTH) % LONG_MONTH_LENGTH + 1; }
int getMonthOfYear(long millis, int year) { int doyZeroBased = (int) ((millis - getYearMillis(year)) / DateTimeConstants.MILLIS_PER_DAY); if (doyZeroBased == 354) { return 12; } return ((doyZeroBased * 2) / MONTH_PAIR_LENGTH) + 1; // return (int) (doyZeroBased / 29.9f) + 1; // // int monthPairZeroBased = doyZeroBased / MONTH_PAIR_LENGTH; // int monthPairRemainder = doyZeroBased % MONTH_PAIR_LENGTH; // return (monthPairZeroBased * 2) + 1 + (monthPairRemainder >= LONG_MONTH_LENGTH ? 1 : 0); }
protected void assemble(Fields fields) { if (getBase() == null) { super.assemble(fields); fields.era = ERA_FIELD; fields.monthOfYear = new BasicMonthOfYearDateTimeField(this, 12); fields.months = fields.monthOfYear.getDurationField(); } }
/** * Gets an instance of the IslamicChronology in the given time zone. * * @param zone the time zone to get the chronology in, null is default * @return a chronology in the specified time zone */ public static IslamicChronology getInstance(DateTimeZone zone) { return getInstance(zone, LEAP_YEAR_16_BASED); }
long getYearDifference(long minuendInstant, long subtrahendInstant) { // optimsed implementation of getDifference, due to fixed months int minuendYear = getYear(minuendInstant); int subtrahendYear = getYear(subtrahendInstant); // Inlined remainder method to avoid duplicate calls to get. long minuendRem = minuendInstant - getYearMillis(minuendYear); long subtrahendRem = subtrahendInstant - getYearMillis(subtrahendYear); int difference = minuendYear - subtrahendYear; if (minuendRem < subtrahendRem) { difference--; } return difference; }
/** * Checks if this chronology instance equals another. * * @param obj the object to compare to * @return true if equal * @since 2.3 */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof IslamicChronology) { IslamicChronology chrono = (IslamicChronology) obj; return getLeapYearPatternType().index == chrono.getLeapYearPatternType().index && super.equals(obj); } return false; }
/** * Gets the Chronology in a specific time zone. * * @param zone the zone to get the chronology in, null is default * @return the chronology */ public Chronology withZone(DateTimeZone zone) { if (zone == null) { zone = DateTimeZone.getDefault(); } if (zone == getZone()) { return this; } return getInstance(zone); }
int getDayOfMonth(long millis) { // optimised for simple months int doy = getDayOfYear(millis) - 1; if (doy == 354) { return 30; } return (doy % MONTH_PAIR_LENGTH) % LONG_MONTH_LENGTH + 1; }
int getMonthOfYear(long millis, int year) { int doyZeroBased = (int) ((millis - getYearMillis(year)) / DateTimeConstants.MILLIS_PER_DAY); if (doyZeroBased == 354) { return 12; } return ((doyZeroBased * 2) / MONTH_PAIR_LENGTH) + 1; // return (int) (doyZeroBased / 29.9f) + 1; // // int monthPairZeroBased = doyZeroBased / MONTH_PAIR_LENGTH; // int monthPairRemainder = doyZeroBased % MONTH_PAIR_LENGTH; // return (monthPairZeroBased * 2) + 1 + (monthPairRemainder >= LONG_MONTH_LENGTH ? 1 : 0); }
protected void assemble(Fields fields) { if (getBase() == null) { super.assemble(fields); fields.era = ERA_FIELD; fields.monthOfYear = new BasicMonthOfYearDateTimeField(this, 12); fields.months = fields.monthOfYear.getDurationField(); } }
/** * Gets an instance of the IslamicChronology in the given time zone. * * @param zone the time zone to get the chronology in, null is default * @return a chronology in the specified time zone */ public static IslamicChronology getInstance(DateTimeZone zone) { return getInstance(zone, LEAP_YEAR_16_BASED); }
long setYear(long instant, int year) { // optimsed implementation of set, due to fixed months int thisYear = getYear(instant); int dayOfYear = getDayOfYear(instant, thisYear); int millisOfDay = getMillisOfDay(instant); // Current year is leap, and day is leap. if (dayOfYear > 354 && !isLeapYear(year)) { // Moving to a non-leap year, leap day doesn't exist. dayOfYear--; } instant = getYearMonthDayMillis(year, 1, dayOfYear); instant += millisOfDay; return instant; }
/** * Serialization singleton. */ private Object readResolve() { Chronology base = getBase(); return base == null ? getInstanceUTC() : getInstance(base.getZone()); }
if (zone == DateTimeZone.UTC) { chrono = new IslamicChronology(null, null, leapYears); chrono = new IslamicChronology( LimitChronology.getInstance(chrono, lowerLimit, null), null, leapYears); } else { chrono = getInstance(DateTimeZone.UTC, leapYears); chrono = new IslamicChronology (ZonedChronology.getInstance(chrono, zone), null, leapYears);