Java Code Examples for java.time.temporal.WeekFields#weekBasedYear()
The following examples show how to use
java.time.temporal.WeekFields#weekBasedYear() .
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: TCKWeekFields.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@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 } }
Example 2
Source File: TCKWeekFields.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@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); } }
Example 3
Source File: TCKWeekFields.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@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 } }
Example 4
Source File: TCKWeekFields.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@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 } }
Example 5
Source File: TCKWeekFields.java From j2objc with Apache License 2.0 | 6 votes |
@Test @UseDataProvider("data_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(" ::" + str + ": :" + i + "::" + j, parsed, date.plusWeeks(j - wowby)); } date = date.plusDays(1); } }
Example 6
Source File: TCKWeekFields.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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); } }
Example 7
Source File: TCKWeekFields.java From hottub with GNU General Public License v2.0 | 6 votes |
@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 } }
Example 8
Source File: TCKLocalizedFieldParser.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 9
Source File: TCKWeekFields.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * 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); } }
Example 10
Source File: TCKWeekFields.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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"); }
Example 11
Source File: TCKWeekFields.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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); } }
Example 12
Source File: TCKLocalizedFieldParser.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 13
Source File: TCKLocalizedFieldParser.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 14
Source File: TCKWeekFields.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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); } }
Example 15
Source File: TCKWeekFields.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * 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); } }
Example 16
Source File: TCKWeekFields.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 17
Source File: TCKWeekFields.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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"); }
Example 18
Source File: TCKWeekFields.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@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"); }
Example 19
Source File: TCKWeekFields.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@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"); }
Example 20
Source File: DateTimeFormatterBuilder.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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); }