Java Code Examples for org.threeten.bp.LocalDate#isAfter()
The following examples show how to use
org.threeten.bp.LocalDate#isAfter() .
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: JapaneseEra.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Registers an additional instance of {@code JapaneseEra}. * <p> * A new Japanese era can begin at any time. * This method allows one new era to be registered without the need for a new library version. * If needed, callers should assign the result to a static variable accessible * across the application. This must be done once, in early startup code. * <p> * NOTE: This method does not exist in Java SE 8. * * @param since the date representing the first date of the era, validated not null * @param name the name * @return the {@code JapaneseEra} singleton, not null * @throws DateTimeException if an additional era has already been registered */ public static JapaneseEra registerEra(LocalDate since, String name) { JapaneseEra[] known = KNOWN_ERAS.get(); if (known.length > 5) { throw new DateTimeException("Only one additional Japanese era can be added"); } Jdk8Methods.requireNonNull(since, "since"); Jdk8Methods.requireNonNull(name, "name"); if (!since.isAfter(REIWA.since)) { throw new DateTimeException("Invalid since date for additional Japanese era, must be after Reiwa"); } JapaneseEra era = new JapaneseEra(ADDITIONAL_VALUE, since, name); JapaneseEra[] newArray = Arrays.copyOf(known, 6); newArray[5] = era; if (!KNOWN_ERAS.compareAndSet(known, newArray)) { throw new DateTimeException("Only one additional Japanese era can be added"); } return era; }
Example 3
Source File: TestChronoUnit.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "yearsBetween") public void test_yearsBetween_LocalDateTimeLaterTime(LocalDate start, LocalDate end, long expected) { if (end.isAfter(start)) { assertEquals(YEARS.between(start.atTime(12, 30), end.atTime(12, 31)), expected); } else { assertEquals(YEARS.between(start.atTime(12, 31), end.atTime(12, 30)), expected); } }
Example 4
Source File: TestChronoUnit.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "yearsBetween") public void test_yearsBetween_ZonedDateLaterOffset(LocalDate start, LocalDate end, long expected) { // +01:00 is later than +02:00 if (end.isAfter(start)) { assertEquals(YEARS.between(start.atStartOfDay(ZoneOffset.ofHours(2)), end.atStartOfDay(ZoneOffset.ofHours(1))), expected); } else { assertEquals(YEARS.between(start.atStartOfDay(ZoneOffset.ofHours(1)), end.atStartOfDay(ZoneOffset.ofHours(2))), expected); } }
Example 5
Source File: TestChronoUnit.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "monthsBetween") public void test_monthsBetween_LocalDateTimeLaterTime(LocalDate start, LocalDate end, long expected) { if (end.isAfter(start)) { assertEquals(MONTHS.between(start.atTime(12, 30), end.atTime(12, 31)), expected); } else { assertEquals(MONTHS.between(start.atTime(12, 31), end.atTime(12, 30)), expected); } }
Example 6
Source File: TestChronoUnit.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "monthsBetween") public void test_monthsBetween_ZonedDateLaterOffset(LocalDate start, LocalDate end, long expected) { // +01:00 is later than +02:00 if (end.isAfter(start)) { assertEquals(MONTHS.between(start.atStartOfDay(ZoneOffset.ofHours(2)), end.atStartOfDay(ZoneOffset.ofHours(1))), expected); } else { assertEquals(MONTHS.between(start.atStartOfDay(ZoneOffset.ofHours(1)), end.atStartOfDay(ZoneOffset.ofHours(2))), expected); } }
Example 7
Source File: TestChronoUnit.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "daysBetween") public void test_daysBetween_LocalDateTimeLaterTime(LocalDate start, LocalDate end, long expected) { if (end.isAfter(start)) { assertEquals(DAYS.between(start.atTime(12, 30), end.atTime(12, 31)), expected); } else { assertEquals(DAYS.between(start.atTime(12, 31), end.atTime(12, 30)), expected); } }
Example 8
Source File: TestChronoUnit.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "daysBetween") public void test_daysBetween_ZonedDateLaterOffset(LocalDate start, LocalDate end, long expected) { // +01:00 is later than +02:00 if (end.isAfter(start)) { assertEquals(DAYS.between(start.atStartOfDay(ZoneOffset.ofHours(2)), end.atStartOfDay(ZoneOffset.ofHours(1))), expected); } else { assertEquals(DAYS.between(start.atStartOfDay(ZoneOffset.ofHours(1)), end.atStartOfDay(ZoneOffset.ofHours(2))), expected); } }
Example 9
Source File: JapaneseDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era, month-of-year and day-of-month fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year and month, otherwise an exception will be thrown. * <p> * The Japanese month and day-of-month are the same as those in the * ISO calendar system. They are not reset when the era changes. * For example: * <pre> * 6th Jan Showa 64 = ISO 1989-01-06 * 7th Jan Showa 64 = ISO 1989-01-07 * 8th Jan Heisei 1 = ISO 1989-01-08 * 9th Jan Heisei 1 = ISO 1989-01-09 * </pre> * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param month the Japanese month-of-year, from 1 to 12 * @param dayOfMonth the Japanese day-of-month, 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-month is invalid for the month-year */ public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) { Jdk8Methods.requireNonNull(era, "era"); if (yearOfEra < 1) { throw new DateTimeException("Invalid YearOfEra: " + yearOfEra); } LocalDate eraStartDate = era.startDate(); LocalDate eraEndDate = era.endDate(); int yearOffset = eraStartDate.getYear() - 1; LocalDate date = LocalDate.of(yearOfEra + yearOffset, month, dayOfMonth); if (date.isBefore(eraStartDate) || date.isAfter(eraEndDate)) { throw new DateTimeException("Requested date is outside bounds of era " + era); } return new JapaneseDate(era, yearOfEra, date); }