Refine search
/** * 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); }
/** * Restricted constructor. */ private ISOYearOfEraDateTimeField() { super(GregorianChronology.getInstanceUTC().year(), DateTimeFieldType.yearOfEra()); }
zone = DateTimeZone.getDefault(); if (chrono == null) { if (zone == DateTimeZone.UTC) { chrono = new GregorianChronology(null, null, minDaysInFirstWeek); } else { chrono = getInstance(DateTimeZone.UTC, minDaysInFirstWeek); chrono = new GregorianChronology (ZonedChronology.getInstance(chrono, zone), null, minDaysInFirstWeek);
@Override public DurationField getRangeDurationField() { return GregorianChronology.getInstanceUTC().eras(); }
/** * Serialization singleton */ private Object readResolve() { Chronology base = getBase(); int minDays = getMinimumDaysInFirstWeek(); minDays = (minDays == 0 ? 4 : minDays); // handle rename of BaseGJChronology return base == null ? getInstance(DateTimeZone.UTC, minDays) : getInstance(base.getZone(), minDays); }
m_dpIterator = new ArrayList<DataPoint>().iterator(); Chronology chronology = GregorianChronology.getInstance(m_timeZone); m_unitField = chronology.year(); break; case MONTHS: m_unitField = chronology.monthOfYear(); break; case WEEKS: m_unitField = chronology.weekOfWeekyear(); break; case DAYS:
protected void assemble(Fields fields) { Object[] params = (Object[])getParam(); iCutoverInstant = cutoverInstant; if (getBase() != null) { return; if (julian.getMinimumDaysInFirstWeek() != gregorian.getMinimumDaysInFirstWeek()) { throw new IllegalArgumentException(); iGapDuration = iCutoverMillis - julianToGregorianByYear(iCutoverMillis); if (gregorian.millisOfDay().get(iCutoverMillis) == 0) { long cutover = gregorian.year().roundCeiling(iCutoverMillis); fields.dayOfYear = new CutoverField( julian.dayOfYear(), fields.dayOfYear, fields.years, cutover, false); long cutover = gregorian.weekyear().roundCeiling(iCutoverMillis); fields.weekOfWeekyear = new CutoverField( julian.weekOfWeekyear(), fields.weekOfWeekyear, fields.weekyears, cutover, true);
/** * Gets an instance of the GregorianChronology in the default time zone. * * @return a chronology in the default time zone */ public static GregorianChronology getInstance() { return getInstance(DateTimeZone.getDefault(), 4); }
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; }
@Test(groups = "slow", enabled = false) public void testWithGMTPlus8() throws SQLException { final LocalDate date1_1 = new LocalDate(2014, 10, 1, GregorianChronology.getInstance(DATE_TZ_PLUS_8_GMT)); // We chose a time such that it moves to next day final DateTime date2_1 = new DateTime(2014, 10, 1, 22, 48, 56, DATE_TZ_PLUS_8_GMT); insertData(date1_1, date2_1, date2_1); final FullOfDates result = readData(); assertEquals(result.getDate1().compareTo(date1_1), 0); assertEquals(result.getDate2().compareTo(date2_1), 0); assertEquals(result.getDate2().getZone().toString(), "UTC"); }
} 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,
/** * 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); } }
long calculateFirstDayOfYearMillis(int year) { // Initial value is just temporary. int leapYears = year / 100; if (year < 0) { // Add 3 before shifting right since /4 and >>2 behave differently // on negative numbers. When the expression is written as // (year / 4) - (year / 100) + (year / 400), // it works for both positive and negative values, except this optimization // eliminates two divisions. leapYears = ((year + 3) >> 2) - leapYears + ((leapYears + 3) >> 2) - 1; } else { leapYears = (year >> 2) - leapYears + (leapYears >> 2); if (isLeapYear(year)) { leapYears--; } } return (year * 365L + (leapYears - DAYS_0000_TO_1970)) * DateTimeConstants.MILLIS_PER_DAY; }
/** * Gets an instance of the GregorianChronology 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 GregorianChronology getInstance(DateTimeZone zone) { return getInstance(zone, 4); }
protected void assemble(Fields fields) { if (getBase() == null) { super.assemble(fields); } }
/** * Gets the minimum days needed for a week to be the first week in a year. * * @return the minimum days */ public int getMinimumDaysInFirstWeek() { return iGregorianChronology.getMinimumDaysInFirstWeek(); }
protected void assemble(Fields fields) { Object[] params = (Object[])getParam(); iCutoverInstant = cutoverInstant; if (getBase() != null) { return; if (julian.getMinimumDaysInFirstWeek() != gregorian.getMinimumDaysInFirstWeek()) { throw new IllegalArgumentException(); iGapDuration = iCutoverMillis - julianToGregorianByYear(iCutoverMillis); if (gregorian.millisOfDay().get(iCutoverMillis) == 0) { long cutover = gregorian.year().roundCeiling(iCutoverMillis); fields.dayOfYear = new CutoverField( julian.dayOfYear(), fields.dayOfYear, fields.years, cutover, false); long cutover = gregorian.weekyear().roundCeiling(iCutoverMillis); fields.weekOfWeekyear = new CutoverField( julian.weekOfWeekyear(), fields.weekOfWeekyear, fields.weekyears, cutover, true);
/** * Gets an instance of the GregorianChronology in the default time zone. * * @return a chronology in the default time zone */ public static GregorianChronology getInstance() { return getInstance(DateTimeZone.getDefault(), 4); }
/** * Serialization singleton */ private Object readResolve() { Chronology base = getBase(); int minDays = getMinimumDaysInFirstWeek(); minDays = (minDays == 0 ? 4 : minDays); // handle rename of BaseGJChronology return base == null ? getInstance(DateTimeZone.UTC, minDays) : getInstance(base.getZone(), minDays); }