Package java.time.chrono

Examples of java.time.chrono.ChronoLocalDate


         * @param dow the day of the week
         * @return a ChronoLocalDate for the requested year, week of year, and day of week
         */
        private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
                int yowby, int wowby, int dow) {
            ChronoLocalDate date = chrono.date(yowby, 1, 1);
            int ldow = localizedDayOfWeek(date);
            int offset = startOfWeekOffset(1, ldow);

            // Clamp the week of year to keep it in the same year
            int yearLen = date.lengthOfYear();
            int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
            wowby = Math.min(wowby, newYearWeek - 1);

            int days = -offset + (dow - 1) + (wowby - 1) * 7;
            return date.plus(days, DAYS);
        }
View Full Code Here


            int offset = startOfWeekOffset(doy, dow);
            int week = computeWeek(offset, doy);
            if (week == 0) {
                // Day is in end of week of previous year
                // Recompute from the last day of the previous year
                ChronoLocalDate date = Chronology.from(temporal).date(temporal);
                date = date.minus(doy, DAYS);   // Back down into previous year
                return localizedWeekOfWeekBasedYear(date);
            } else if (week > 50) {
                // If getting close to end of year, use higher precision logic
                // Check if date of year is in partial week associated with next year
                ValueRange dayRange = temporal.range(DAY_OF_YEAR);
View Full Code Here

            return null;
        }

        private ChronoLocalDate resolveWoM(
                Map<TemporalField, Long> fieldValues, Chronology chrono, int year, long month, long wom, int localDow, ResolverStyle resolverStyle) {
            ChronoLocalDate date;
            if (resolverStyle == ResolverStyle.LENIENT) {
                date = chrono.date(year, 1, 1).plus(Math.subtractExact(month, 1), MONTHS);
                long weeks = Math.subtractExact(wom, localizedWeekOfMonth(date));
                int days = localDow - localizedDayOfWeek(date)// safe from overflow
                date = date.plus(Math.addExact(Math.multiplyExact(weeks, 7), days), DAYS);
            } else {
                int monthValid = MONTH_OF_YEAR.checkValidIntValue(month)// validate
                date = chrono.date(year, monthValid, 1);
                int womInt = range.checkValidIntValue(wom, this)// validate
                int weeks = (int) (womInt - localizedWeekOfMonth(date))// safe from overflow
                int days = localDow - localizedDayOfWeek(date)// safe from overflow
                date = date.plus(weeks * 7 + days, DAYS);
                if (resolverStyle == ResolverStyle.STRICT && date.getLong(MONTH_OF_YEAR) != month) {
                    throw new DateTimeException("Strict mode rejected resolved date as it is in a different month");
                }
            }
            fieldValues.remove(this);
            fieldValues.remove(YEAR);
View Full Code Here

            return date;
        }

        private ChronoLocalDate resolveWoY(
                Map<TemporalField, Long> fieldValues, Chronology chrono, int year, long woy, int localDow, ResolverStyle resolverStyle) {
            ChronoLocalDate date = chrono.date(year, 1, 1);
            if (resolverStyle == ResolverStyle.LENIENT) {
                long weeks = Math.subtractExact(woy, localizedWeekOfYear(date));
                int days = localDow - localizedDayOfWeek(date)// safe from overflow
                date = date.plus(Math.addExact(Math.multiplyExact(weeks, 7), days), DAYS);
            } else {
                int womInt = range.checkValidIntValue(woy, this)// validate
                int weeks = (int) (womInt - localizedWeekOfYear(date))// safe from overflow
                int days = localDow - localizedDayOfWeek(date)// safe from overflow
                date = date.plus(weeks * 7 + days, DAYS);
                if (resolverStyle == ResolverStyle.STRICT && date.getLong(YEAR) != year) {
                    throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
                }
            }
            fieldValues.remove(this);
            fieldValues.remove(YEAR);
View Full Code Here

        private ChronoLocalDate resolveWBY(
                Map<TemporalField, Long> fieldValues, Chronology chrono, int localDow, ResolverStyle resolverStyle) {
            int yowby = weekDef.weekBasedYear.range().checkValidIntValue(
                    fieldValues.get(weekDef.weekBasedYear), weekDef.weekBasedYear);
            ChronoLocalDate date;
            if (resolverStyle == ResolverStyle.LENIENT) {
                date = ofWeekBasedYear(chrono, yowby, 1, localDow);
                long wowby = fieldValues.get(weekDef.weekOfWeekBasedYear);
                long weeks = Math.subtractExact(wowby, 1);
                date = date.plus(weeks, WEEKS);
            } else {
                int wowby = weekDef.weekOfWeekBasedYear.range().checkValidIntValue(
                        fieldValues.get(weekDef.weekOfWeekBasedYear), weekDef.weekOfWeekBasedYear)// validate
                date = ofWeekBasedYear(chrono, yowby, wowby, localDow);
                if (resolverStyle == ResolverStyle.STRICT && localizedWeekBasedYear(date) != yowby) {
View Full Code Here

            int offset = startOfWeekOffset(doy, dow);
            int week = computeWeek(offset, doy);
            if (week == 0) {
                // Day is in end of week of previous year
                // Recompute from the last day of the previous year
                ChronoLocalDate date = Chronology.from(temporal).date(temporal);
                date = date.minus(doy + 7, DAYS);   // Back down into previous year
                return rangeWeekOfWeekBasedYear(date);
            }
            // Check if day of year is in partial week associated with next year
            ValueRange dayRange = temporal.range(DAY_OF_YEAR);
            int yearLen = (int)dayRange.getMaximum();
            int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());

            if (week >= newYearWeek) {
                // Overlaps with weeks of following year; recompute from a week in following year
                ChronoLocalDate date = Chronology.from(temporal).date(temporal);
                date = date.plus(yearLen - doy + 1 + 7, ChronoUnit.DAYS);
                return rangeWeekOfWeekBasedYear(date);
            }
            return ValueRange.of(1, newYearWeek-1);
        }
View Full Code Here

    assertTrue( constraint.isValid( null, null ), "null fails validation." );
  }

  @Test
  public void testIsValidForLocalDate() {
    ChronoLocalDate future = LocalDate.now().plusDays( 1 );
    ChronoLocalDate past = LocalDate.now().minusDays( 1 );

    assertTrue( constraint.isValid( future, null ), "Future LocalDate '" + future + "' fails validation.");
    assertFalse( constraint.isValid( past, null ), "Past LocalDate '" + past + "' validated as future.");
  }
View Full Code Here

    assertFalse( constraint.isValid( past, null ), "Past LocalDate '" + past + "' validated as future.");
  }

  @Test
  public void testIsValidForJapaneseDate() {
    ChronoLocalDate future = JapaneseDate.now().plus( 1, DAYS );
    ChronoLocalDate past = JapaneseDate.now().minus( 1, DAYS );

    assertTrue( constraint.isValid( future, null ), "Future JapaneseDate '" + future + "' fails validation.");
    assertFalse( constraint.isValid( past, null ), "Past JapaneseDate '" + past + "' validated as future.");
  }
View Full Code Here

    assertFalse( constraint.isValid( past, null ), "Past JapaneseDate '" + past + "' validated as future.");
  }

  @Test
  public void testIsValidForHijrahDate() {
    ChronoLocalDate future = HijrahDate.now().plus( 1, DAYS );
    ChronoLocalDate past = HijrahDate.now().minus( 1, DAYS );

    assertTrue( constraint.isValid( future, null ), "Future HijrahDate '" + future + "' fails validation.");
    assertFalse( constraint.isValid( past, null ), "Past HijrahDate '" + past + "' validated as future.");
  }
View Full Code Here

    assertFalse( constraint.isValid( past, null ), "Past HijrahDate '" + past + "' validated as future.");
  }

  @Test
  public void testIsValidForMinguoDate() {
    ChronoLocalDate future = MinguoDate.now().plus( 1, DAYS );
    ChronoLocalDate past = MinguoDate.now().minus( 1, DAYS );

    assertTrue( constraint.isValid( future, null ), "Future MinguoDate '" + future + "' fails validation.");
    assertFalse( constraint.isValid( past, null ), "Past MinguoDate '" + past + "' validated as future.");
  }
View Full Code Here

TOP

Related Classes of java.time.chrono.ChronoLocalDate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.