Package org.threeten.bp.chrono

Examples of org.threeten.bp.chrono.ChronoLocalDate


            int sow = weekDef.getFirstDayOfWeek().getValue();
            int isoDow = temporal.get(DAY_OF_WEEK);
            int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
            long woy = localizedWeekOfYear(temporal, dow);
            if (woy == 0) {
                ChronoLocalDate previous = Chronology.from(temporal).date(temporal).minus(1, ChronoUnit.WEEKS);
                return (int) localizedWeekOfYear(previous, dow) + 1;
            } else if (woy >= 53) {
                int offset = startOfWeekOffset(temporal.get(DAY_OF_YEAR), dow);
                int year = temporal.get(YEAR);
                int yearLen = Year.isLeap(year) ? 366 : 365;
View Full Code Here


                }
                Chronology chrono = Chronology.from(partialTemporal)// defaults to ISO
                int isoDow = DAY_OF_WEEK.checkValidIntValue(fieldValues.get(DAY_OF_WEEK));
                int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
                final int wby = range().checkValidIntValue(fieldValues.get(this), this);
                ChronoLocalDate date;
                long days;
                if (resolverStyle == ResolverStyle.LENIENT) {
                    date = chrono.date(wby, 1, weekDef.getMinimalDaysInFirstWeek());
                    long wowby = fieldValues.get(weekDef.weekOfWeekBasedYear);
                    int dateDow = localizedDayOfWeek(date, sow);
                    long weeks = wowby - localizedWeekOfYear(date, dateDow);
                    days = weeks * 7 + (dow - dateDow);
                } else {
                    date = chrono.date(wby, 1, weekDef.getMinimalDaysInFirstWeek());
                    long wowby = weekDef.weekOfWeekBasedYear.range().checkValidIntValue(
                                    fieldValues.get(weekDef.weekOfWeekBasedYear), weekDef.weekOfWeekBasedYear);
                    int dateDow = localizedDayOfWeek(date, sow);
                    long weeks = wowby - localizedWeekOfYear(date, dateDow);
                    days = weeks * 7 + (dow - dateDow);
                }
                date = date.plus(days, DAYS);
                if (resolverStyle == ResolverStyle.STRICT) {
                    if (date.getLong(this) != fieldValues.get(this)) {
                        throw new DateTimeException("Strict mode rejected date parsed to a different year");
                    }
                }
                fieldValues.remove(this);
                fieldValues.remove(weekDef.weekOfWeekBasedYear);
                fieldValues.remove(DAY_OF_WEEK);
                return date;
            }
           
            if (fieldValues.containsKey(YEAR) == false) {
                return null;
            }
            int isoDow = DAY_OF_WEEK.checkValidIntValue(fieldValues.get(DAY_OF_WEEK));
            int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
            int year = YEAR.checkValidIntValue(fieldValues.get(YEAR));
            Chronology chrono = Chronology.from(partialTemporal)// defaults to ISO
            if (rangeUnit == MONTHS) {  // week-of-month
                if (fieldValues.containsKey(MONTH_OF_YEAR) == false) {
                    return null;
                }
                final long value = fieldValues.remove(this);
                ChronoLocalDate date;
                long days;
                if (resolverStyle == ResolverStyle.LENIENT) {
                    long month = fieldValues.get(MONTH_OF_YEAR);
                    date = chrono.date(year, 1, 1);
                    date = date.plus(month - 1, MONTHS);
                    int dateDow = localizedDayOfWeek(date, sow);
                    long weeks = value - localizedWeekOfMonth(date, dateDow);
                    days = weeks * 7 + (dow - dateDow);
                } else {
                    int month = MONTH_OF_YEAR.checkValidIntValue(fieldValues.get(MONTH_OF_YEAR));
                    date = chrono.date(year, month, 8);
                    int dateDow = localizedDayOfWeek(date, sow);
                    int wom = range.checkValidIntValue(value, this);
                    long weeks = wom - localizedWeekOfMonth(date, dateDow);
                    days = weeks * 7 + (dow - dateDow);
                }
                date = date.plus(days, DAYS);
                if (resolverStyle == ResolverStyle.STRICT) {
                    if (date.getLong(MONTH_OF_YEAR) != fieldValues.get(MONTH_OF_YEAR)) {
                        throw new DateTimeException("Strict mode rejected date parsed to a different month");
                    }
                }
                fieldValues.remove(this);
                fieldValues.remove(YEAR);
                fieldValues.remove(MONTH_OF_YEAR);
                fieldValues.remove(DAY_OF_WEEK);
                return date;
            } else if (rangeUnit == YEARS) {  // week-of-year
                final long value = fieldValues.remove(this);
                ChronoLocalDate date = chrono.date(year, 1, 1);
                long days;
                if (resolverStyle == ResolverStyle.LENIENT) {
                    int dateDow = localizedDayOfWeek(date, sow);
                    long weeks = value - localizedWeekOfYear(date, dateDow);
                    days = weeks * 7 + (dow - dateDow);
                } else {
                    int dateDow = localizedDayOfWeek(date, sow);
                    int woy = range.checkValidIntValue(value, this);
                    long weeks = woy - localizedWeekOfYear(date, dateDow);
                    days = weeks * 7 + (dow - dateDow);
                }
                date = date.plus(days, DAYS);
                if (resolverStyle == ResolverStyle.STRICT) {
                    if (date.getLong(YEAR) != fieldValues.get(YEAR)) {
                        throw new DateTimeException("Strict mode rejected date parsed to a different year");
                    }
                }
                fieldValues.remove(this);
                fieldValues.remove(YEAR);
View Full Code Here

    }

    private static void newPackagePluggable() {
        Chronology chrono = MinguoChronology.INSTANCE;

        ChronoLocalDate date = chrono.dateNow();
        System.out.printf("now: %s%n", date);

        date = date.with(DAY_OF_MONTH, 1);
        System.out.printf("first of month: %s%n", date);

        int month = (int) date.get(ChronoField.MONTH_OF_YEAR);
        date = date.with(DAY_OF_WEEK, 1);
        System.out.printf("start of first week: %s%n", date);

        while (date.get(ChronoField.MONTH_OF_YEAR) <= month) {
            String row = "";
            for (int i = 0; i < 7; i++) {
                row += date.get(ChronoField.DAY_OF_MONTH) + " ";
                date = date.plus(1, ChronoUnit.DAYS);
            }
            System.out.println(row);
        }
    }
View Full Code Here

     */
    static void example1() {
        System.out.printf("Available Calendars%n");

        // Print the Minguo date
        ChronoLocalDate now1 = MinguoChronology.INSTANCE.dateNow();
        int day = now1.get(ChronoField.DAY_OF_MONTH);
        int dow = now1.get(ChronoField.DAY_OF_WEEK);
        int month = now1.get(ChronoField.MONTH_OF_YEAR);
        int year = now1.get(ChronoField.YEAR);
        System.out.printf("  Today is %s %s %d-%s-%d%n", now1.getChronology().getId(),
                DayOfWeek.of(dow), year, month, day);

        // Print today's date and the last day of the year for the Minguo Calendar.
        ChronoLocalDate first = now1
                .with(ChronoField.DAY_OF_MONTH, 1)
                .with(ChronoField.MONTH_OF_YEAR, 1);
        ChronoLocalDate last = first
                .plus(1, ChronoUnit.YEARS)
                .minus(1, ChronoUnit.DAYS);
        System.out.printf("  1st of year: %s; end of year: %s%n", first, last);

        // Enumerate the list of available calendars and print today for each
        LocalDate  before = LocalDate.of(-500, 1, 1);
        Set<Chronology> chronos = Chronology.getAvailableChronologies();
        for (Chronology chrono : chronos) {
            ChronoLocalDate date = chrono.dateNow();
            ChronoLocalDate date2 = chrono.date(before);
            System.out.printf("   %20s: %22s, %22s%n", chrono.getId(), date, date2);
        }
    }
View Full Code Here

     * Prints a Minguo calendar for the current month.
     */
    private static void printMinguoCal() {
        String chronoName = "Minguo";
        Chronology chrono = Chronology.of(chronoName);
        ChronoLocalDate today = chrono.dateNow();
        printMonthCal(today, System.out);
    }
View Full Code Here

     * @param out a PrintStream
     */
    private static void printMonthCal(ChronoLocalDate date, PrintStream out) {

        int lengthOfMonth = (int) date.lengthOfMonth();
        ChronoLocalDate end = date.with(ChronoField.DAY_OF_MONTH, lengthOfMonth);
        end = end.plus(7 - end.get(ChronoField.DAY_OF_WEEK), ChronoUnit.DAYS);
        // Back up to the beginning of the week including the 1st of the month
        ChronoLocalDate start = date.with(ChronoField.DAY_OF_MONTH, 1);
        start = start.minus(start.get(ChronoField.DAY_OF_WEEK), ChronoUnit.DAYS);

        out.printf("%9s Month %2d, %4d%n", date.getChronology().getId(),
                date.get(ChronoField.MONTH_OF_YEAR),
                date.get(ChronoField.YEAR));
        String[] colText = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
        printMonthRow(colText, " ", out);

        String[] cell = new String[7];
        for ( ; start.compareTo(end) <= 0; start = start.plus(1, ChronoUnit.DAYS)) {
            int ndx = start.get(ChronoField.DAY_OF_WEEK) - 1;
            cell[ndx] = Integer.toString((int) start.get(ChronoField.DAY_OF_MONTH));
            if (ndx == 6) {
                printMonthRow(cell, "|", out);
            }
        }
    }
View Full Code Here

            ZoneOffset temporalOffset = temporal.query(TemporalQueries.offset());
            if (normalizedOffset instanceof ZoneOffset && temporalOffset != null && normalizedOffset.equals(temporalOffset) == false) {
                throw new DateTimeException("Invalid override zone for temporal: " + overrideZone + " " + temporal);
            }
        }
        final ChronoLocalDate effectiveDate;
        if (overrideChrono != null) {
            if (temporal.isSupported(EPOCH_DAY)) {
                effectiveDate = effectiveChrono.date(temporal);
            } else {
                // check for date fields other than epoch-day, ignoring case of converting null to ISO
                if (!(overrideChrono == IsoChronology.INSTANCE && temporalChrono == null)) {
                    for (ChronoField f : ChronoField.values()) {
                        if (f.isDateBased() && temporal.isSupported(f)) {
                            throw new DateTimeException("Invalid override chronology for temporal: " + overrideChrono + " " + temporal);
                        }
                    }
                }
                effectiveDate = null;
            }
        } else {
            effectiveDate = null;
        }

        // need class here to handle non-standard cases
        return new DefaultInterfaceTemporalAccessor() {
            @Override
            public boolean isSupported(TemporalField field) {
                if (effectiveDate != null && field.isDateBased()) {
                    return effectiveDate.isSupported(field);
                }
                return temporal.isSupported(field);
            }
            @Override
            public ValueRange range(TemporalField field) {
                if (effectiveDate != null && field.isDateBased()) {
                    return effectiveDate.range(field);
                }
                return temporal.range(field);
            }
            @Override
            public long getLong(TemporalField field) {
                if (effectiveDate != null && field.isDateBased()) {
                    return effectiveDate.getLong(field);
                }
                return temporal.getLong(field);
            }
            @SuppressWarnings("unchecked")
            @Override
View Full Code Here

     * Compute the number of days from the Epoch and compute the date from the number of days.
     */
    @Test(dataProvider = "calendars")
    public void test_epoch(String name, String alias, String description) {
        Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
        ChronoLocalDate date1 = chrono.dateNow();
        long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
        ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
        assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
        long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
        assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
    }
View Full Code Here

    @Test
    public void test_date_withEra() {
        int year = 5;
        int month = 5;
        int dayOfMonth = 5;
        ChronoLocalDate test = IsoChronology.INSTANCE.date(IsoEra.BCE, year, month, dayOfMonth);
        assertEquals(test.getEra(), IsoEra.BCE);
        assertEquals(test.get(ChronoField.YEAR_OF_ERA), year);
        assertEquals(test.get(ChronoField.MONTH_OF_YEAR), month);
        assertEquals(test.get(ChronoField.DAY_OF_MONTH), dayOfMonth);

        assertEquals(test.get(YEAR), 1 + (-1 * year));
        assertEquals(test.get(ERA), 0);
        assertEquals(test.get(YEAR_OF_ERA), year);
    }
View Full Code Here

    //-----------------------------------------------------------------------
    // with(DateTimeAdjuster)
    //-----------------------------------------------------------------------
    @Test
    public void test_adjust1() {
        ChronoLocalDate base = IsoChronology.INSTANCE.date(1728, 10, 28);
        ChronoLocalDate test = base.with(TemporalAdjusters.lastDayOfMonth());
        assertEquals(test, IsoChronology.INSTANCE.date(1728, 10, 31));
    }
View Full Code Here

TOP

Related Classes of org.threeten.bp.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.