/** * Factory method returns instances of the GJ cutover chronology. Any * cutover date may be specified. * * @param zone the time zone to use, null is default * @param gregorianCutover the cutover to use * @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4 */ public static GJChronology getInstance( DateTimeZone zone, long gregorianCutover, int minDaysInFirstWeek) { Instant cutoverInstant; if (gregorianCutover == DEFAULT_CUTOVER.getMillis()) { cutoverInstant = null; } else { cutoverInstant = new Instant(gregorianCutover); } return getInstance(zone, cutoverInstant, minDaysInFirstWeek); }
long gregorianToJulianByWeekyear(long instant) { return convertByWeekyear(instant, iGregorianChronology, iJulianChronology); }
long julianToGregorianByYear(long instant) { return convertByYear(instant, iJulianChronology, iGregorianChronology); }
/** * Serialization singleton */ private Object readResolve() { return getInstance(getZone(), iCutoverInstant, getMinimumDaysInFirstWeek()); }
/** * 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, iCutoverInstant, getMinimumDaysInFirstWeek()); }
/** * Checks if this chronology instance equals another. * * @param obj the object to compare to * @return true if equal * @since 1.6 */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof GJChronology) { GJChronology chrono = (GJChronology) obj; return iCutoverMillis == chrono.iCutoverMillis && getMinimumDaysInFirstWeek() == chrono.getMinimumDaysInFirstWeek() && getZone().equals(chrono.getZone()); } return false; }
protected void assemble(Fields fields) { Object[] params = (Object[])getParam(); iCutoverMillis = cutoverInstant.getMillis(); iCutoverInstant = cutoverInstant; if (getBase() != null) { return; if (julian.getMinimumDaysInFirstWeek() != gregorian.getMinimumDaysInFirstWeek()) { throw new IllegalArgumentException(); iGapDuration = iCutoverMillis - julianToGregorianByYear(iCutoverMillis); if (gregorian.millisOfDay().get(iCutoverMillis) == 0) { fields.years = fields.year.getDurationField(); fields.yearOfEra = new ImpreciseCutoverField( julian.yearOfEra(), fields.yearOfEra, fields.years, iCutoverMillis); fields.centuries = fields.centuryOfEra.getDurationField(); long cutover = gregorian.year().roundCeiling(iCutoverMillis); fields.dayOfYear = new CutoverField( julian.dayOfYear(), fields.dayOfYear, fields.years, cutover, false);
for (int i=chronos.size(); --i>=0; ) { chrono = chronos.get(i); if (minDaysInFirstWeek == chrono.getMinimumDaysInFirstWeek() && cutoverInstant.equals(chrono.getGregorianCutover())) { chrono = new GJChronology (JulianChronology.getInstance(zone, minDaysInFirstWeek), GregorianChronology.getInstance(zone, minDaysInFirstWeek), cutoverInstant); } else { chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek); chrono = new GJChronology (ZonedChronology.getInstance(chrono, zone), chrono.iJulianChronology,
/** * Gets a debugging toString. * * @return a debugging string */ public String toString() { StringBuffer sb = new StringBuffer(60); sb.append("GJChronology"); sb.append('['); sb.append(getZone().getID()); if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) { sb.append(",cutover="); DateTimeFormatter printer; if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) { printer = ISODateTimeFormat.date(); } else { printer = ISODateTimeFormat.dateTime(); } printer.withChronology(withUTC()).printTo(sb, iCutoverMillis); } if (getMinimumDaysInFirstWeek() != 4) { sb.append(",mdfw="); sb.append(getMinimumDaysInFirstWeek()); } sb.append(']'); return sb.toString(); }
} else { cutoverInstant = gregorianCutover.toInstant(); LocalDate cutoverDate = new LocalDate(cutoverInstant.getMillis(), GregorianChronology.getInstance(zone)); if (cutoverDate.getYear() <= 0) { throw new IllegalArgumentException("Cutover too early. Must be on or after 0001-01-01."); if (chrono == null) { if (zone == DateTimeZone.UTC) { chrono = new GJChronology (JulianChronology.getInstance(zone, minDaysInFirstWeek), GregorianChronology.getInstance(zone, minDaysInFirstWeek), cutoverInstant); } else { chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek); chrono = new GJChronology (ZonedChronology.getInstance(chrono, zone), chrono.iJulianChronology,
/** * Factory method returns instances of the default GJ cutover * chronology. This uses a cutover date of October 15, 1582 (Gregorian) * 00:00:00 UTC. For this value, October 4, 1582 (Julian) is followed by * October 15, 1582 (Gregorian). * * <p>The first day of the week is designated to be * {@link org.joda.time.DateTimeConstants#MONDAY Monday}, * and the minimum days in the first week of the year is 4. * * <p>The returned chronology is in the default time zone. */ public static GJChronology getInstance() { return getInstance(DateTimeZone.getDefault(), DEFAULT_CUTOVER, 4); }
public int getMaximumValue(ReadablePartial partial, int[] values) { Chronology chrono = GJChronology.getInstanceUTC(); long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { DateTimeField field = partial.getFieldType(i).getField(chrono); if (values[i] <= field.getMaximumValue(instant)) { instant = field.set(instant, values[i]); } } return getMaximumValue(instant); }
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) { // overridden as superclass algorithm can't handle // 2004-02-29 + 48 months -> 2008-02-29 type dates if (valueToAdd == 0) { return values; } if (DateTimeUtils.isContiguous(partial)) { long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { instant = partial.getFieldType(i).getField(GJChronology.this).set(instant, values[i]); } instant = add(instant, valueToAdd); return GJChronology.this.get(partial, instant); } else { return super.add(partial, fieldIndex, values, valueToAdd); } }
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int millisOfDay) throws IllegalArgumentException { Chronology base; if ((base = getBase()) != null) { return base.getDateTimeMillis(year, monthOfYear, dayOfMonth, millisOfDay); } // Assume date is Gregorian. long instant = iGregorianChronology.getDateTimeMillis (year, monthOfYear, dayOfMonth, millisOfDay); if (instant < iCutoverMillis) { // Maybe it's Julian. instant = iJulianChronology.getDateTimeMillis (year, monthOfYear, dayOfMonth, millisOfDay); if (instant >= iCutoverMillis) { // Okay, it's in the illegal cutover gap. throw new IllegalArgumentException("Specified date does not exist"); } } return instant; }
/** * A suitable hash code for the chronology. * * @return the hash code * @since 1.6 */ public int hashCode() { return "GJ".hashCode() * 11 + getZone().hashCode() + getMinimumDaysInFirstWeek() + iCutoverInstant.hashCode(); }
/** * Gets the chronology, which is the GJChronology if a GregorianCalendar is used, * BuddhistChronology if a BuddhistCalendar is used or ISOChronology otherwise. * The time zone specified is used in preference to that on the calendar. * * @param object the Calendar to convert, must not be null * @param zone the specified zone to use, null means default zone * @return the chronology, never null * @throws NullPointerException if the object is null * @throws ClassCastException if the object is an invalid type */ public Chronology getChronology(Object object, DateTimeZone zone) { if (object.getClass().getName().endsWith(".BuddhistCalendar")) { return BuddhistChronology.getInstance(zone); } else if (object instanceof GregorianCalendar) { GregorianCalendar gc = (GregorianCalendar) object; long cutover = gc.getGregorianChange().getTime(); if (cutover == Long.MIN_VALUE) { return GregorianChronology.getInstance(zone); } else if (cutover == Long.MAX_VALUE) { return JulianChronology.getInstance(zone); } else { return GJChronology.getInstance(zone, cutover, 4); } } else { return ISOChronology.getInstance(zone); } }
public int getMaximumValue(ReadablePartial partial) { long instant = GJChronology.getInstanceUTC().set(partial, 0L); return getMaximumValue(instant); }
/** * Factory method returns instances of the default GJ cutover * chronology. This uses a cutover date of October 15, 1582 (Gregorian) * 00:00:00 UTC. For this value, October 4, 1582 (Julian) is followed by * October 15, 1582 (Gregorian). * * <p>The first day of the week is designated to be * {@link org.joda.time.DateTimeConstants#MONDAY Monday}, * and the minimum days in the first week of the year is 4. * * <p>The time zone of the returned instance is UTC. */ public static GJChronology getInstanceUTC() { return getInstance(DateTimeZone.UTC, DEFAULT_CUTOVER, 4); }
protected void assemble(Fields fields) { Object[] params = (Object[])getParam(); iCutoverMillis = cutoverInstant.getMillis(); iCutoverInstant = cutoverInstant; if (getBase() != null) { return; if (julian.getMinimumDaysInFirstWeek() != gregorian.getMinimumDaysInFirstWeek()) { throw new IllegalArgumentException(); iGapDuration = iCutoverMillis - julianToGregorianByYear(iCutoverMillis); if (gregorian.millisOfDay().get(iCutoverMillis) == 0) { fields.years = fields.year.getDurationField(); fields.yearOfEra = new ImpreciseCutoverField( julian.yearOfEra(), fields.yearOfEra, fields.years, iCutoverMillis); fields.centuries = fields.centuryOfEra.getDurationField(); long cutover = gregorian.year().roundCeiling(iCutoverMillis); fields.dayOfYear = new CutoverField( julian.dayOfYear(), fields.dayOfYear, fields.years, cutover, false);