/** * Gets the day-of-year field. * <p> * This method returns the primitive {@code int} value for the day-of-year. * * @return the day-of-year, from 1 to 365, or 366 in a leap year */ public int getDayOfYear() { return date.getDayOfYear(); }
/** * Gets the day-of-year field. * <p> * This method returns the primitive {@code int} value for the day-of-year. * * @return the day-of-year, from 1 to 365, or 366 in a leap year */ public int getDayOfYear() { return date.getDayOfYear(); }
private long getDayOfYear() { if (yearOfEra == 1) { return isoDate.getDayOfYear() - era.startDate().getDayOfYear() + 1; } return isoDate.getDayOfYear(); }
private long getDayOfYear() { if (yearOfEra == 1) { return isoDate.getDayOfYear() - era.startDate().getDayOfYear() + 1; } return isoDate.getDayOfYear(); }
/** * Returns a copy of this date with the day-of-year altered. * If the resulting date is invalid, an exception is thrown. * <p> * This instance is immutable and unaffected by this method call. * * @param dayOfYear the day-of-year to set in the result, from 1 to 365-366 * @return a {@code LocalDate} based on this date with the requested day, not null * @throws DateTimeException if the day-of-year value is invalid * @throws DateTimeException if the day-of-year is invalid for the year */ public LocalDate withDayOfYear(int dayOfYear) { if (this.getDayOfYear() == dayOfYear) { return this; } return ofYearDay(year, dayOfYear); }
/** * Returns a copy of this date with the day-of-year altered. * If the resulting date is invalid, an exception is thrown. * <p> * This instance is immutable and unaffected by this method call. * * @param dayOfYear the day-of-year to set in the result, from 1 to 365-366 * @return a {@code LocalDate} based on this date with the requested day, not null * @throws DateTimeException if the day-of-year value is invalid * @throws DateTimeException if the day-of-year is invalid for the year */ public LocalDate withDayOfYear(int dayOfYear) { if (this.getDayOfYear() == dayOfYear) { return this; } return ofYearDay(year, dayOfYear); }
private int get0(TemporalField field) { switch ((ChronoField) field) { case DAY_OF_WEEK: return getDayOfWeek().getValue(); case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((day - 1) % 7) + 1; case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1; case DAY_OF_MONTH: return day; case DAY_OF_YEAR: return getDayOfYear(); case EPOCH_DAY: throw new DateTimeException("Field too large for an int: " + field); case ALIGNED_WEEK_OF_MONTH: return ((day - 1) / 7) + 1; case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1; case MONTH_OF_YEAR: return month; case PROLEPTIC_MONTH: throw new DateTimeException("Field too large for an int: " + field); case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year); case YEAR: return year; case ERA: return (year >= 1 ? 1 : 0); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); }
private int get0(TemporalField field) { switch ((ChronoField) field) { case DAY_OF_WEEK: return getDayOfWeek().getValue(); case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((day - 1) % 7) + 1; case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1; case DAY_OF_MONTH: return day; case DAY_OF_YEAR: return getDayOfYear(); case EPOCH_DAY: throw new DateTimeException("Field too large for an int: " + field); case ALIGNED_WEEK_OF_MONTH: return ((day - 1) / 7) + 1; case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1; case MONTH_OF_YEAR: return month; case PROLEPTIC_MONTH: throw new DateTimeException("Field too large for an int: " + field); case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year); case YEAR: return year; case ERA: return (year >= 1 ? 1 : 0); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); }
private static int getWeekBasedYear(LocalDate date) { int year = date.getYear(); int doy = date.getDayOfYear(); if (doy <= 3) { int dow = date.getDayOfWeek().ordinal(); if (doy - dow < -2) { year--; } } else if (doy >= 363) { int dow = date.getDayOfWeek().ordinal(); doy = doy - 363 - (date.isLeapYear() ? 1 : 0); if (doy - dow >= 0) { year++; } } return year; } }
private static int getWeekBasedYear(LocalDate date) { int year = date.getYear(); int doy = date.getDayOfYear(); if (doy <= 3) { int dow = date.getDayOfWeek().ordinal(); if (doy - dow < -2) { year--; } } else if (doy >= 363) { int dow = date.getDayOfWeek().ordinal(); doy = doy - 363 - (date.isLeapYear() ? 1 : 0); if (doy - dow >= 0) { year++; } } return year; } }
private static int getWeek(LocalDate date) { int dow0 = date.getDayOfWeek().ordinal(); int doy0 = date.getDayOfYear() - 1; int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero) int alignedWeek = doyThu0 / 7; int firstThuDoy0 = doyThu0 - (alignedWeek * 7); int firstMonDoy0 = firstThuDoy0 - 3; if (firstMonDoy0 < -3) { firstMonDoy0 += 7; } if (doy0 < firstMonDoy0) { return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum(); } int week = ((doy0 - firstMonDoy0) / 7) + 1; if (week == 53) { if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) { week = 1; } } return week; }
private static int getWeek(LocalDate date) { int dow0 = date.getDayOfWeek().ordinal(); int doy0 = date.getDayOfYear() - 1; int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero) int alignedWeek = doyThu0 / 7; int firstThuDoy0 = doyThu0 - (alignedWeek * 7); int firstMonDoy0 = firstThuDoy0 - 3; if (firstMonDoy0 < -3) { firstMonDoy0 += 7; } if (doy0 < firstMonDoy0) { return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum(); } int week = ((doy0 - firstMonDoy0) / 7) + 1; if (week == 53) { if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) { week = 1; } } return week; }
LocalDate eraEndDate = era.endDate(); if (yearOfEra == 1) { dayOfYear += eraStartDate.getDayOfYear() - 1; if (dayOfYear > eraStartDate.lengthOfYear()) { throw new DateTimeException("DayOfYear exceeds maximum allowed in the first year of era " + era);
LocalDate eraEndDate = era.endDate(); if (yearOfEra == 1) { dayOfYear += eraStartDate.getDayOfYear() - 1; if (dayOfYear > eraStartDate.lengthOfYear()) { throw new DateTimeException("DayOfYear exceeds maximum allowed in the first year of era " + era);
int min = 366; for (int i = 0; i < eras.length; i++) { min = Math.min(min, eras[i].startDate().lengthOfYear() - eras[i].startDate().getDayOfYear() + 1);
int min = 366; for (int i = 0; i < eras.length; i++) { min = Math.min(min, eras[i].startDate().lengthOfYear() - eras[i].startDate().getDayOfYear() + 1);