当前位置: 首页>>代码示例>>Java>>正文


Java WeekFields.weekBasedYear方法代码示例

本文整理汇总了Java中java.time.temporal.WeekFields.weekBasedYear方法的典型用法代码示例。如果您正苦于以下问题:Java WeekFields.weekBasedYear方法的具体用法?Java WeekFields.weekBasedYear怎么用?Java WeekFields.weekBasedYear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.temporal.WeekFields的用法示例。


在下文中一共展示了WeekFields.weekBasedYear方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_parse_resolve_localizedWoWBY

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(yowbyField).appendLiteral(':')
                .appendValue(wowbyField).appendLiteral(':')
                .appendValue(DAY_OF_WEEK).toFormatter();
        String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" +
                date.get(DAY_OF_WEEK);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);

        date = date.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:TCKWeekFields.java

示例2: test_parse_resolve_localizedWoWBY_lenient

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY_lenient(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(yowbyField).appendLiteral(':')
                .appendValue(wowbyField).appendLiteral(':')
                .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
        int wowby = date.get(wowbyField);
        int dow = date.get(DAY_OF_WEEK);
        for (int j = wowby - 60; j < wowby + 60; j++) {
            String str = date.get(yowbyField) + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
        }

        date = date.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:TCKWeekFields.java

示例3: test_parse_resolve_localizedWoWBY_strict

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY_strict(DayOfWeek firstDayOfWeek, int minDays) {
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();
    DateTimeFormatter f = new DateTimeFormatterBuilder()
            .appendValue(yowbyField).appendLiteral(':')
            .appendValue(wowbyField).appendLiteral(':')
            .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
    String str = "2012:0:1";
    try {
        LocalDate date = LocalDate.parse(str, f);
        assertEquals(date.get(yowbyField), 2012);
        assertEquals(date.get(wowbyField), 0);
        assertEquals(date.get(DAY_OF_WEEK), 1);
    } catch (DateTimeException ex) {
        // expected
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKWeekFields.java

示例4: test_parse_resolve_localizedWoWBYDow

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBYDow(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(yowbyField).appendLiteral(':')
                .appendValue(wowbyField).appendLiteral(':')
                .appendValue(dowField).toFormatter();
        String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" +
                date.get(dowField);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);

        date = date.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TCKWeekFields.java

示例5: test_parse_resolve_localizedWoWBYDow_lenient

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBYDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(yowbyField).appendLiteral(':')
                .appendValue(wowbyField).appendLiteral(':')
                .appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
        int wowby = date.get(wowbyField);
        int dow = date.get(dowField);
        for (int j = wowby - 60; j < wowby + 60; j++) {
            String str = date.get(yowbyField) + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
        }

        date = date.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:TCKWeekFields.java

示例6: printerParser

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
/**
 * Gets the printerParser to use based on the field and the locale.
 *
 * @param locale  the locale to use, not null
 * @return the formatter, not null
 * @throws IllegalArgumentException if the formatter cannot be found
 */
private DateTimePrinterParser printerParser(Locale locale) {
    WeekFields weekDef = WeekFields.of(locale);
    TemporalField field = null;
    switch (chr) {
        case 'Y':
            field = weekDef.weekBasedYear();
            if (count == 2) {
                return new ReducedPrinterParser(field, 2, 2, 0, ReducedPrinterParser.BASE_DATE, 0);
            } else {
                return new NumberPrinterParser(field, count, 19,
                        (count < 4) ? SignStyle.NORMAL : SignStyle.EXCEEDS_PAD, -1);
            }
        case 'e':
        case 'c':
            field = weekDef.dayOfWeek();
            break;
        case 'w':
            field = weekDef.weekOfWeekBasedYear();
            break;
        case 'W':
            field = weekDef.weekOfMonth();
            break;
        default:
            throw new IllegalStateException("unreachable");
    }
    return new NumberPrinterParser(field, (count == 2 ? 2 : 1), 2, SignStyle.NOT_NEGATIVE);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:DateTimeFormatterBuilder.java

示例7: test_weekOfWeekBasedYearField

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
/**
 * Verify that the date can be reconstructed from the DOW, WeekOfWeekBasedYear,
 * and WeekBasedYear for every combination of start of week
 * and minimal days in week.
 * @param firstDayOfWeek the first day of the week
 * @param minDays the minimum number of days in the week
 */
@Test(dataProvider="weekFields")
public void test_weekOfWeekBasedYearField(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);  // Known to be ISO Monday
    WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = weekDef.dayOfWeek();
    TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
    TemporalField yowbyField = weekDef.weekBasedYear();

    for (int i = 1; i <= 15; i++) {
        int actualDOW = day.get(dowField);
        int actualWOWBY = day.get(wowbyField);
        int actualYOWBY = day.get(yowbyField);

        // Verify that the combination of day of week and week of month can be used
        // to reconstruct the same date.
        LocalDate day1 = LocalDate.of(actualYOWBY, 1, 1);
        DayOfWeek isoDOW = day1.getDayOfWeek();
        int dow = (7 + isoDOW.getValue() - firstDayOfWeek.getValue()) % 7 + 1;

        int weekStart = Math.floorMod(1 - dow, 7);
        if (weekStart + 1 > weekDef.getMinimalDaysInFirstWeek()) {
            // The previous week has the minimum days in the current month to be a 'week'
            weekStart -= 7;
        }
        weekStart += actualDOW - 1;
        weekStart += (actualWOWBY - 1) * 7;
        LocalDate result = day1.plusDays(weekStart);

        assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
                + String.format("%s, ISO Dow: %s, weekStart: %s, actualDOW: %s, actualWOWBY: %s, YearOfWBY: %d, expected day: %s, result: %s%n",
                weekDef, day.getDayOfWeek(), weekStart, actualDOW, actualWOWBY, actualYOWBY, day, result));
        day = day.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:TCKWeekFields.java

示例8: test_withWeekOfWeekBasedYear

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    int dowExpected = (day.get(dowField) - 1) % 7 + 1;
    LocalDate dowDate = day.with(dowField, dowExpected);
    int dowResult = dowDate.get(dowField);
    assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);

    int weekExpected = day.get(wowbyField) + 1;
    ValueRange range = day.range(wowbyField);
    weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
    LocalDate weekDate = day.with(wowbyField, weekExpected);
    int weekResult = weekDate.get(wowbyField);
    assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);

    int yearExpected = day.get(yowbyField) + 1;

    LocalDate yearDate = day.with(yowbyField, yearExpected);
    int yearResult = yearDate.get(yowbyField);
    assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day  + " --> " + yearDate);

    range = yearDate.range(wowbyField);
    weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());

    int weekActual = yearDate.get(wowbyField);
    assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:TCKWeekFields.java

示例9: test_weekBasedYears

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="WeekBasedYearData")
public void test_weekBasedYears(WeekFields weekDef, int weekBasedYear,
        int weekOfWeekBasedYear, int dayOfWeek, LocalDate date) {
    TemporalField dowField = weekDef.dayOfWeek();
    TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
    TemporalField yowbyField = weekDef.weekBasedYear();
    assertEquals(date.get(dowField), dayOfWeek, "DayOfWeek mismatch");
    assertEquals(date.get(wowbyField), weekOfWeekBasedYear, "Week of WeekBasedYear mismatch");
    assertEquals(date.get(yowbyField), weekBasedYear, "Year of WeekBasedYear mismatch");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TCKWeekFields.java

示例10: test_parse_textField

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="FieldPatterns")
public void test_parse_textField(String pattern, String text, int pos, int expectedPos, long expectedValue) {
    WeekFields weekDef = WeekFields.of(locale);
    TemporalField field = null;
    switch(pattern.charAt(0)) {
        case 'e' :
            field = weekDef.dayOfWeek();
            break;
        case 'w':
            field = weekDef.weekOfWeekBasedYear();
            break;
        case 'W':
            field = weekDef.weekOfMonth();
            break;
        case 'Y':
            field = weekDef.weekBasedYear();
            break;
        default:
            throw new IllegalStateException("bad format letter from pattern");
    }
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatterBuilder b
            = new DateTimeFormatterBuilder().appendPattern(pattern);
    DateTimeFormatter dtf = b.toFormatter(locale);
    TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), expectedPos);
    } else {
        assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
        long value = parsed.getLong(field);
        assertEquals(value, expectedValue, "Value incorrect for " + field);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:TCKLocalizedFieldParser.java

示例11: printerParser

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
/**
 * Gets the printerParser to use based on the field and the locale.
 *
 * @param locale  the locale to use, not null
 * @return the formatter, not null
 * @throws IllegalArgumentException if the formatter cannot be found
 */
private DateTimePrinterParser printerParser(Locale locale) {
    WeekFields weekDef = WeekFields.of(locale);
    TemporalField field = null;
    switch (chr) {
        case 'Y':
            field = weekDef.weekBasedYear();
            if (count == 2) {
                return new ReducedPrinterParser(field, 2, 2, 0, ReducedPrinterParser.BASE_DATE,
                        this.subsequentWidth);
            } else {
                return new NumberPrinterParser(field, count, 19,
                        (count < 4) ? SignStyle.NORMAL : SignStyle.EXCEEDS_PAD,
                        this.subsequentWidth);
            }
        case 'e':
        case 'c':
            field = weekDef.dayOfWeek();
            break;
        case 'w':
            field = weekDef.weekOfWeekBasedYear();
            break;
        case 'W':
            field = weekDef.weekOfMonth();
            break;
        default:
            throw new IllegalStateException("unreachable");
    }
    return new NumberPrinterParser(field, minWidth, maxWidth, SignStyle.NOT_NEGATIVE,
            this.subsequentWidth);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:DateTimeFormatterBuilder.java

示例12: test_parse_textField

import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="FieldPatterns")
public void test_parse_textField(String pattern, String text, int pos, int expectedPos, long expectedValue) {
    WeekFields weekDef = WeekFields.of(locale);
    TemporalField field = null;
    switch(pattern.charAt(0)) {
        case 'c' :
        case 'e' :
            field = weekDef.dayOfWeek();
            break;
        case 'w':
            field = weekDef.weekOfWeekBasedYear();
            break;
        case 'W':
            field = weekDef.weekOfMonth();
            break;
        case 'Y':
            field = weekDef.weekBasedYear();
            break;
        default:
            throw new IllegalStateException("bad format letter from pattern");
    }
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatterBuilder b
            = new DateTimeFormatterBuilder().appendPattern(pattern);
    DateTimeFormatter dtf = b.toFormatter(locale);
    TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), expectedPos);
    } else {
        assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
        long value = parsed.getLong(field);
        assertEquals(value, expectedValue, "Value incorrect for " + field);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:TCKLocalizedFieldParser.java


注:本文中的java.time.temporal.WeekFields.weekBasedYear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。