/** * Gets the era, as defined by the chronology. * <p> * The era is, conceptually, the largest division of the time-line. * Most calendar systems have a single epoch dividing the time-line into two eras. * However, some have multiple eras, such as one for the reign of each leader. * The exact meaning is determined by the {@code Chronology}. * <p> * All correctly implemented {@code Era} classes are singletons, thus it * is valid code to write {@code date.getEra() == SomeEra.NAME)}. * * @return the chronology specific era constant applicable at this date, not null */ public Era getEra() { return getChronology().eraOf(get(ERA)); }
return get0(field); return super.get(field);
@Override long getValue(DateTimePrintContext context, long value) { long absValue = Math.abs(value); int baseValue = this.baseValue; if (baseDate != null) { Chronology chrono = Chronology.from(context.getTemporal()); baseValue = chrono.date(baseDate).get(field); } if (value >= baseValue && value < baseValue + EXCEED_POINTS[minWidth]) { return absValue % EXCEED_POINTS[minWidth]; } return absValue % EXCEED_POINTS[maxWidth]; }
/** * Searches for the occurrences of a month/day in one chronology within one * gregorian year. * * @param targetMonth * @param targetDay * @param gregorianYear * @param targetChrono * @return the list of gregorian dates. */ private Set<LocalDate> getDatesFromChronologyWithinGregorianYear(int targetMonth, int targetDay, int gregorianYear, Chronology targetChrono) { Set<LocalDate> holidays = new HashSet<>(); LocalDate firstGregorianDate = LocalDate.of(gregorianYear, JANUARY, 1); LocalDate lastGregorianDate = LocalDate.of(gregorianYear, DECEMBER, 31); ChronoLocalDate firstTargetDate = targetChrono.date(firstGregorianDate); ChronoLocalDate lastTargetDate = targetChrono.date(lastGregorianDate); int targetYear = firstTargetDate.get(ChronoField.YEAR); final int lastYear = lastTargetDate.get(ChronoField.YEAR); while (targetYear <= lastYear) { ChronoLocalDate d = targetChrono.date(targetYear, targetMonth, targetDay); if (!firstGregorianDate.isAfter(d) && !lastGregorianDate.isBefore(d)) { holidays.add(LocalDate.from(d)); } targetYear++; } return holidays; }
@Override public int get(TemporalField field) { if (field instanceof ChronoField) { return (field.isTimeBased() ? time.get(field) : date.get(field)); } return range(field).checkValidIntValue(getLong(field), field); }
@Override int setValue(DateTimeParseContext context, long value, int errorPos, int successPos) { int baseValue = this.baseValue; if (baseDate != null) { Chronology chrono = context.getEffectiveChronology(); baseValue = chrono.date(baseDate).get(field); context.addChronologyChangedParser(this, value, errorPos, successPos); } int parseLen = successPos - errorPos; if (parseLen == minWidth && value >= 0) { long range = EXCEED_POINTS[minWidth]; long lastPart = baseValue % range; long basePart = baseValue - lastPart; if (baseValue > 0) { value = basePart + value; } else { value = basePart - value; } if (value < baseValue) { value += range; } } return context.setParsedField(field, value, errorPos, successPos); }