private static int resolvePreviousValid(int year, int month, int day) { switch (month) { case 2: day = Math.min(day, IsoChronology.INSTANCE.isLeapYear(year) ? 29 : 28); break; case 4: case 6: case 9: case 11: day = Math.min(day, 30); break; } return pack((short) year, (byte) month, (byte) day); }
if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { temporal = LocalDate.from(temporal);
public static LocalDate dateNow(IsoChronology instance) { return instance.dateNow(MockClock.systemDefaultZone()); }
/** * Obtains an ISO local date from the era, year-of-era, month-of-year * and day-of-month fields. * * @param era the ISO era, not null * @param yearOfEra the ISO year-of-era * @param month the ISO month-of-year * @param dayOfMonth the ISO day-of-month * @return the ISO local date, not null * @throws DateTimeException if unable to create the date */ @Override // override with covariant return type public LocalDate date(Era era, int yearOfEra, int month, int dayOfMonth) { return date(prolepticYear(era, yearOfEra), month, dayOfMonth); }
/** * Obtains an ISO local date from the era, year-of-era and day-of-year fields. * * @param era the ISO era, not null * @param yearOfEra the ISO year-of-era * @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(Era era, int yearOfEra, int dayOfYear) { return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear); }
/** * Obtains the current ISO local date from the specified clock. * <p> * This will query the specified clock to obtain the current date - today. * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@link Clock dependency injection}. * * @param clock the clock to use, not null * @return the current ISO local date, not null * @throws DateTimeException if unable to create the date */ @Override // override with covariant return type public LocalDate dateNow(Clock clock) { Jdk8Methods.requireNonNull(clock, "clock"); return date(LocalDate.now(clock)); }
public final class IsoChronology extends AbstractChronology implements Serializable { public static final IsoChronology INSTANCE = new IsoChronology();
if (!IsoChronology.INSTANCE.equals(Chronology.from(temporal))) { temporal = LocalDate.from(temporal);
public static LocalDate dateNow(IsoChronology instance, ZoneId zone) { return instance.dateNow(MockClock.system(zone)); }
public static List<Person> createRoster() { final List<Person> roster = new ArrayList<>(); roster.add(new Person("Fred", IsoChronology.INSTANCE.date(1980, 6, 20), Person.Sex.MALE, "fred@example.com", Money.of(100000, "USD"))); roster.add(new Person("Jane", IsoChronology.INSTANCE.date(1990, 7, 15), Person.Sex.FEMALE, "jane@example.com", Money.of(80000, "USD"))); roster.add(new Person("George", IsoChronology.INSTANCE .date(1991, 8, 13), Person.Sex.MALE, "george@example.com", Money.of(70000, "USD"))); roster.add(new Person("Bob", IsoChronology.INSTANCE.date(2000, 9, 12), Person.Sex.MALE, "bob@example.com", Money.of(25000, "USD"))); return roster; }
public static boolean isLeapYear(int packedDate) { return IsoChronology.INSTANCE.isLeapYear(getYear(packedDate)); }
if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { temporal = LocalDate.from(temporal);
/** * Obtains the current ISO local date from the system clock in the specified time-zone. * <p> * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date. * Specifying the time-zone avoids dependence on the default time-zone. * <p> * Using this method will prevent the ability to use an alternate clock for testing * because the clock is hard-coded. * * @return the current ISO local date using the system clock, not null * @throws DateTimeException if unable to create the date */ @Override // override with covariant return type public LocalDate dateNow(ZoneId zone) { return dateNow(Clock.system(zone)); }
public static boolean isLeapYear(long packedDateTime) { if (packedDateTime == missingValueIndicator()) return false; return IsoChronology.INSTANCE.isLeapYear(getYear(packedDateTime)); }
if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { temporal = LocalDate.from(temporal);
/** * Obtains the current ISO local date from the system clock in the default time-zone. * <p> * This will query the {@link Clock#systemDefaultZone() system clock} in the default * time-zone to obtain the current date. * <p> * Using this method will prevent the ability to use an alternate clock for testing * because the clock is hard-coded. * * @return the current ISO local date using the system clock and default time-zone, not null * @throws DateTimeException if unable to create the date */ @Override // override with covariant return type public LocalDate dateNow() { return dateNow(Clock.systemDefaultZone()); }
/** * Checks if the specified year is a leap year. * <p> * Thai Buddhist leap years occur exactly in line with ISO leap years. * This method does not validate the year passed in, and only has a * well-defined result for years in the supported range. * * @param prolepticYear the proleptic-year to check, not validated for range * @return true if the year is a leap year */ @Override public boolean isLeapYear(long prolepticYear) { return IsoChronology.INSTANCE.isLeapYear(prolepticYear - YEARS_DIFFERENCE); }
if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { temporal = LocalDate.from(temporal);
public int getAge() { return birthday.until(IsoChronology.INSTANCE.dateNow()).getYears(); }
/** * Checks if the specified year is a leap year. * <p> * Japanese calendar leap years occur exactly in line with ISO leap years. * This method does not validate the year passed in, and only has a * well-defined result for years in the supported range. * * @param prolepticYear the proleptic-year to check, not validated for range * @return true if the year is a leap year */ @Override public boolean isLeapYear(long prolepticYear) { return IsoChronology.INSTANCE.isLeapYear(prolepticYear); }