src/edu/kit/informatik/calendar_sample/Date.java
/**
     * Returns the date for the specified year and day of year.
     * 
     * <p>This method handles exceeding days gracefully, i.e. {@code day=0} will be treated as last day of the previous
     * year.
     * 
     * <p>This method can be used to revert the result of the {@linkplain #totalDays()} method by providing {@code 0}
     * for the year and {@code totalDays} for the day.
     * <blockquote><pre>
     * Date d;
     * ...
     * assert d.equals(ofDayOfYear(0, d.totalDays());</pre>
     * </blockquote>
     * 
     * @param  year the year
     * @param  day the day
     * @return the date
     */
Returns the date for the specified year and day of year.

This method handles exceeding days gracefully, i.e.  day=0 will be treated as last day of the previous
year.

This method can be used to revert the result of the  #totalDays() method by providing  0
for the year and  totalDays for the day.

@param  year the year
@param  day the day
@return the date
Returns the date for the specified year and day of year . This method handles exceeding days gracefully i . e . day = 0 will be treated as last day of the previous year . This method can be used to revert the result of the #totalDays () method by providing 0 for the year and totalDays for the day . @param year the year @param day the day @return the date
private static Date ofDayOfYear(
            final int year,
            final int day) {
        int remainingDays = day;
        final int daysIn400Years = 365 * 400 + 100 - 4 + 1;
        int nYear = year + remainingDays / daysIn400Years * 400;
        remainingDays %= daysIn400Years;
        if (remainingDays <= 0) {
            for (; remainingDays <= 0; remainingDays += daysInYear(--nYear)) { }
        } else {
            for (int diy; remainingDays > (diy = daysInYear(nYear)); remainingDays -= diy, nYear++) { }
        }
        final YearKind yearKind = YearKind.of(nYear);
        final Month    month    = yearKind.monthByDayOfYear(remainingDays);
        return new Date(nYear, month.toIndex(), remainingDays - yearKind.zerothDayOf(month));
    }
private static Date ofDayOfYear ( final int year , final int day ) { int remainingDays = day ; final int daysIn400Years = 365 * 400 + 100 - 4 + 1 ; int nYear = year + remainingDays / daysIn400Years * 400 ; remainingDays %= daysIn400Years ; if ( remainingDays <= 0 ) { for ( ; remainingDays <= 0 ; remainingDays += daysInYear ( -- nYear ) ) { } } else { for ( int diy ; remainingDays > ( diy = daysInYear ( nYear ) ) ; remainingDays -= diy , nYear ++ ) { } } final YearKind yearKind = YearKind . of ( nYear ) ; final Month month = yearKind . monthByDayOfYear ( remainingDays ) ; return new Date ( nYear , month . toIndex ( ) , remainingDays - yearKind . zerothDayOf ( month ) ) ; }
Returns the date for the specified year and day of year.
Returns the date for the specified year and day of year .
//// // Adding/subtracting 365/366 days until day is within the current year