Java Code Examples for org.threeten.bp.LocalDate#ofYearDay()
The following examples show how to use
org.threeten.bp.LocalDate#ofYearDay() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JapaneseDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era and day-of-year fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year, otherwise an exception will be thrown. * The Japanese day-of-year is reset when the era changes. * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param dayOfYear the Japanese day-of-year, from 1 to 31 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-year is invalid for the year */ static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) { Jdk8Methods.requireNonNull(era, "era"); if (yearOfEra < 1) { throw new DateTimeException("Invalid YearOfEra: " + yearOfEra); } LocalDate eraStartDate = era.startDate(); 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 yearOffset = eraStartDate.getYear() - 1; LocalDate isoDate = LocalDate.ofYearDay(yearOfEra + yearOffset, dayOfYear); if (isoDate.isBefore(eraStartDate) || isoDate.isAfter(eraEndDate)) { throw new DateTimeException("Requested date is outside bounds of era " + era); } return new JapaneseDate(era, yearOfEra, isoDate); }
Example 2
Source File: MinguoChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override // override with covariant return type public MinguoDate dateYearDay(int prolepticYear, int dayOfYear) { return new MinguoDate(LocalDate.ofYearDay(prolepticYear + YEARS_DIFFERENCE, dayOfYear)); }
Example 3
Source File: ThaiBuddhistChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override // override with covariant return type public ThaiBuddhistDate dateYearDay(int prolepticYear, int dayOfYear) { return new ThaiBuddhistDate(LocalDate.ofYearDay(prolepticYear - YEARS_DIFFERENCE, dayOfYear)); }
Example 4
Source File: IsoChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Obtains an ISO local date from the proleptic-year and day-of-year fields. * <p> * This is equivalent to {@link LocalDate#ofYearDay(int, int)}. * * @param prolepticYear the ISO proleptic-year * @param dayOfYear the ISO day-of-year * @return the ISO local date, not null * @throws DateTimeException if unable to create the date */ @Override // override with covariant return type public LocalDate dateYearDay(int prolepticYear, int dayOfYear) { return LocalDate.ofYearDay(prolepticYear, dayOfYear); }
Example 5
Source File: JapaneseChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Obtains a local date in Japanese calendar system from the * proleptic-year and day-of-year fields. * <p> * The day-of-year in this factory is expressed relative to the start of the proleptic year. * The Japanese proleptic year and day-of-year are the same as those in the ISO calendar system. * They are not reset when the era changes. * * @param prolepticYear the proleptic-year * @param dayOfYear the day-of-year * @return the Japanese local date, not null * @throws DateTimeException if unable to create the date */ @Override public JapaneseDate dateYearDay(int prolepticYear, int dayOfYear) { LocalDate date = LocalDate.ofYearDay(prolepticYear, dayOfYear); return date(prolepticYear, date.getMonthValue(), date.getDayOfMonth()); }