java.time.temporal.IsoFields Java Examples
The following examples show how to use
java.time.temporal.IsoFields.
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: TCKDateTimeParseResolver.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="resolveTwoNoChange") Object[][] data_resolveTwoNoChange() { return new Object[][]{ {YEAR, 2012, MONTH_OF_YEAR, 5}, {YEAR, 2012, DAY_OF_MONTH, 5}, {YEAR, 2012, DAY_OF_WEEK, 5}, {YEAR, 2012, ALIGNED_WEEK_OF_YEAR, 5}, {YEAR, 2012, ALIGNED_WEEK_OF_MONTH, 5}, {YEAR, 2012, IsoFields.QUARTER_OF_YEAR, 3}, {YEAR, 2012, MINUTE_OF_HOUR, 5}, {YEAR, 2012, SECOND_OF_MINUTE, 5}, {YEAR, 2012, NANO_OF_SECOND, 5}, {MONTH_OF_YEAR, 5, DAY_OF_MONTH, 5}, {MONTH_OF_YEAR, 5, DAY_OF_WEEK, 5}, {MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_YEAR, 5}, {MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_MONTH, 5}, {MONTH_OF_YEAR, 3, IsoFields.QUARTER_OF_YEAR, 5}, {MONTH_OF_YEAR, 5, MINUTE_OF_HOUR, 5}, {MONTH_OF_YEAR, 5, SECOND_OF_MINUTE, 5}, {MONTH_OF_YEAR, 5, NANO_OF_SECOND, 5}, }; }
Example #2
Source File: TCKIsoFields.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "parseLenientWeek") public void test_parse_parseLenientWeek_SMART(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':') .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':') .appendValue(DAY_OF_WEEK) .toFormatter().withResolverStyle(ResolverStyle.SMART); if (smart) { LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); } else { try { LocalDate.parse(str, f); fail("Should have failed"); } catch (DateTimeParseException ex) { // expected } } }
Example #3
Source File: TCKIsoFields.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "parseLenientWeek") public void test_parse_parseLenientWeek_SMART(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':') .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':') .appendValue(DAY_OF_WEEK) .toFormatter().withResolverStyle(ResolverStyle.SMART); if (smart) { LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); } else { try { LocalDate.parse(str, f); fail("Should have failed"); } catch (DateTimeParseException ex) { // expected } } }
Example #4
Source File: TCKIsoFields.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "parseLenientQuarter") public void test_parse_parseLenientQuarter_SMART(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.SMART); if (smart) { LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); } else { try { LocalDate.parse(str, f); fail("Should have failed"); } catch (DateTimeParseException ex) { // expected } } }
Example #5
Source File: TCKDateTimeParseResolver.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="resolveTwoNoChange") Object[][] data_resolveTwoNoChange() { return new Object[][]{ {YEAR, 2012, MONTH_OF_YEAR, 5}, {YEAR, 2012, DAY_OF_MONTH, 5}, {YEAR, 2012, DAY_OF_WEEK, 5}, {YEAR, 2012, ALIGNED_WEEK_OF_YEAR, 5}, {YEAR, 2012, ALIGNED_WEEK_OF_MONTH, 5}, {YEAR, 2012, IsoFields.QUARTER_OF_YEAR, 3}, {YEAR, 2012, MINUTE_OF_HOUR, 5}, {YEAR, 2012, SECOND_OF_MINUTE, 5}, {YEAR, 2012, NANO_OF_SECOND, 5}, {MONTH_OF_YEAR, 5, DAY_OF_MONTH, 5}, {MONTH_OF_YEAR, 5, DAY_OF_WEEK, 5}, {MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_YEAR, 5}, {MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_MONTH, 5}, {MONTH_OF_YEAR, 3, IsoFields.QUARTER_OF_YEAR, 5}, {MONTH_OF_YEAR, 5, MINUTE_OF_HOUR, 5}, {MONTH_OF_YEAR, 5, SECOND_OF_MINUTE, 5}, {MONTH_OF_YEAR, 5, NANO_OF_SECOND, 5}, }; }
Example #6
Source File: TCKIsoFields.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "parseLenientQuarter") public void test_parse_parseLenientQuarter_SMART(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.SMART); if (smart) { LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); } else { try { LocalDate.parse(str, f); fail("Should have failed"); } catch (DateTimeParseException ex) { // expected } } }
Example #7
Source File: TCKIsoFields.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "parseLenientQuarter") public void test_parse_parseLenientQuarter_SMART(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.SMART); if (smart) { LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); } else { try { LocalDate.parse(str, f); fail("Should have failed"); } catch (DateTimeParseException ex) { // expected } } }
Example #8
Source File: TCKDateTimeParseResolver.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="resolveTwoNoChange") Object[][] data_resolveTwoNoChange() { return new Object[][]{ {YEAR, 2012, MONTH_OF_YEAR, 5}, {YEAR, 2012, DAY_OF_MONTH, 5}, {YEAR, 2012, DAY_OF_WEEK, 5}, {YEAR, 2012, ALIGNED_WEEK_OF_YEAR, 5}, {YEAR, 2012, ALIGNED_WEEK_OF_MONTH, 5}, {YEAR, 2012, IsoFields.QUARTER_OF_YEAR, 3}, {YEAR, 2012, MINUTE_OF_HOUR, 5}, {YEAR, 2012, SECOND_OF_MINUTE, 5}, {YEAR, 2012, NANO_OF_SECOND, 5}, {MONTH_OF_YEAR, 5, DAY_OF_MONTH, 5}, {MONTH_OF_YEAR, 5, DAY_OF_WEEK, 5}, {MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_YEAR, 5}, {MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_MONTH, 5}, {MONTH_OF_YEAR, 3, IsoFields.QUARTER_OF_YEAR, 5}, {MONTH_OF_YEAR, 5, MINUTE_OF_HOUR, 5}, {MONTH_OF_YEAR, 5, SECOND_OF_MINUTE, 5}, {MONTH_OF_YEAR, 5, NANO_OF_SECOND, 5}, }; }
Example #9
Source File: TCKDateTimeParseResolver.java From hottub with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="resolveTwoNoChange") Object[][] data_resolveTwoNoChange() { return new Object[][]{ {YEAR, 2012, MONTH_OF_YEAR, 5}, {YEAR, 2012, DAY_OF_MONTH, 5}, {YEAR, 2012, DAY_OF_WEEK, 5}, {YEAR, 2012, ALIGNED_WEEK_OF_YEAR, 5}, {YEAR, 2012, ALIGNED_WEEK_OF_MONTH, 5}, {YEAR, 2012, IsoFields.QUARTER_OF_YEAR, 3}, {YEAR, 2012, MINUTE_OF_HOUR, 5}, {YEAR, 2012, SECOND_OF_MINUTE, 5}, {YEAR, 2012, NANO_OF_SECOND, 5}, {MONTH_OF_YEAR, 5, DAY_OF_MONTH, 5}, {MONTH_OF_YEAR, 5, DAY_OF_WEEK, 5}, {MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_YEAR, 5}, {MONTH_OF_YEAR, 5, ALIGNED_WEEK_OF_MONTH, 5}, {MONTH_OF_YEAR, 3, IsoFields.QUARTER_OF_YEAR, 5}, {MONTH_OF_YEAR, 5, MINUTE_OF_HOUR, 5}, {MONTH_OF_YEAR, 5, SECOND_OF_MINUTE, 5}, {MONTH_OF_YEAR, 5, NANO_OF_SECOND, 5}, }; }
Example #10
Source File: TCKIsoFields.java From j2objc with Apache License 2.0 | 5 votes |
@Test @UseDataProvider("data_quarter") public void test_parse_quarters_LENIENT(LocalDate date, int doq, int qoy) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.LENIENT); LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f); assertEquals(parsed, date); }
Example #11
Source File: TCKIsoFields.java From j2objc with Apache License 2.0 | 5 votes |
public void test_loop() { // loop round at least one 400 year cycle, including before 1970 LocalDate date = LocalDate.of(1960, 1, 5); // Tuseday of week 1 1960 int year = 1960; int wby = 1960; int weekLen = 52; int week = 1; while (date.getYear() < 2400) { DayOfWeek loopDow = date.getDayOfWeek(); if (date.getYear() != year) { year = date.getYear(); } if (loopDow == MONDAY) { week++; if ((week == 53 && weekLen == 52) || week == 54) { week = 1; LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1); DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek(); weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52); wby++; } } assertEquals("Failed on " + date + " " + date.getDayOfWeek(), IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen)); assertEquals("Failed on " + date + " " + date.getDayOfWeek(), IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week); assertEquals("Failed on " + date + " " + date.getDayOfWeek(), date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week); assertEquals("Failed on " + date + " " + date.getDayOfWeek(), IsoFields.WEEK_BASED_YEAR.getFrom(date), wby); assertEquals("Failed on " + date + " " + date.getDayOfWeek(), date.get(IsoFields.WEEK_BASED_YEAR), wby); date = date.plusDays(1); } }
Example #12
Source File: TCKIsoFields.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="week") public void test_parse_weeks_LENIENT(LocalDate date, DayOfWeek dow, int week, int wby) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-') .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral('-') .appendValue(DAY_OF_WEEK) .toFormatter().withResolverStyle(ResolverStyle.LENIENT); LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f); assertEquals(parsed, date); }
Example #13
Source File: TestIsoWeekFields.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "fields") Object[][] data_Fields() { return new Object[][] { {IsoFields.WEEK_OF_WEEK_BASED_YEAR, IsoFields.WEEK_BASED_YEAR}, {WeekFields.ISO.weekOfWeekBasedYear(), WeekFields.ISO.weekBasedYear()}, }; }
Example #14
Source File: TCKIsoFields.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "quarter") public void test_parse_quarters_SMART(LocalDate date, int doq, int qoy) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.SMART); LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f); assertEquals(parsed, date); }
Example #15
Source File: TestIsoWeekFields.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "fields") public void test_WOWBY_basics(TemporalField weekField, TemporalField yearField) { assertEquals(weekField.isDateBased(), true); assertEquals(weekField.isTimeBased(), false); assertEquals(weekField.getBaseUnit(), ChronoUnit.WEEKS); assertEquals(weekField.getRangeUnit(), IsoFields.WEEK_BASED_YEARS); }
Example #16
Source File: TCKDateTimeFormatters.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_weekDate_largeYear() { TemporalAccessor parsed = DateTimeFormatter.ISO_WEEK_DATE.parseUnresolved("+123456-W04-5", new ParsePosition(0)); assertEquals(parsed.getLong(IsoFields.WEEK_BASED_YEAR), 123456L); assertEquals(parsed.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR), 4L); assertEquals(parsed.getLong(DAY_OF_WEEK), 5L); }
Example #17
Source File: TCKIsoFields.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "parseLenientQuarter") public void test_parse_parseLenientQuarter_LENIENT(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.LENIENT); LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); }
Example #18
Source File: TCKIsoFields.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="week") public void test_parse_weeks_LENIENT(LocalDate date, DayOfWeek dow, int week, int wby) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-') .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral('-') .appendValue(DAY_OF_WEEK) .toFormatter().withResolverStyle(ResolverStyle.LENIENT); LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f); assertEquals(parsed, date); }
Example #19
Source File: TCKIsoFields.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "parseLenientWeek") public void test_parse_parseLenientWeek_LENIENT(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':') .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':') .appendValue(DAY_OF_WEEK) .toFormatter().withResolverStyle(ResolverStyle.LENIENT); LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); }
Example #20
Source File: TCKIsoFields.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void test_loop() { // loop round at least one 400 year cycle, including before 1970 LocalDate date = LocalDate.of(1960, 1, 5); // Tuseday of week 1 1960 int year = 1960; int wby = 1960; int weekLen = 52; int week = 1; while (date.getYear() < 2400) { DayOfWeek loopDow = date.getDayOfWeek(); if (date.getYear() != year) { year = date.getYear(); } if (loopDow == MONDAY) { week++; if ((week == 53 && weekLen == 52) || week == 54) { week = 1; LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1); DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek(); weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52); wby++; } } assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek()); assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek()); assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek()); assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek()); assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek()); date = date.plusDays(1); } }
Example #21
Source File: TCKIsoFields.java From j2objc with Apache License 2.0 | 5 votes |
@Test @UseDataProvider("data_quarter") public void test_parse_quarters_SMART(LocalDate date, int doq, int qoy) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.SMART); LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f); assertEquals(parsed, date); }
Example #22
Source File: TCKIsoFields.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "quarter") public void test_parse_quarters(LocalDate date, int doq, int qoy) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.STRICT); LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f); assertEquals(parsed, date); }
Example #23
Source File: TCKIsoFields.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="week") public void test_parse_weeks_STRICT(LocalDate date, DayOfWeek dow, int week, int wby) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-') .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral('-') .appendValue(DAY_OF_WEEK) .toFormatter().withResolverStyle(ResolverStyle.STRICT); LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f); assertEquals(parsed, date); }
Example #24
Source File: TCKIsoFields.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "parseLenientQuarter") public void test_parse_parseLenientQuarter_LENIENT(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':') .appendValue(IsoFields.DAY_OF_QUARTER) .toFormatter().withResolverStyle(ResolverStyle.LENIENT); LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); }
Example #25
Source File: TCKDateTimeFormatters.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_weekDate_largeYear() { TemporalAccessor parsed = DateTimeFormatter.ISO_WEEK_DATE.parseUnresolved("+123456-W04-5", new ParsePosition(0)); assertEquals(parsed.getLong(IsoFields.WEEK_BASED_YEAR), 123456L); assertEquals(parsed.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR), 4L); assertEquals(parsed.getLong(DAY_OF_WEEK), 5L); }
Example #26
Source File: TestIsoWeekFields.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "fields") public void test_WOWBY_basics(TemporalField weekField, TemporalField yearField) { assertEquals(weekField.isDateBased(), true); assertEquals(weekField.isTimeBased(), false); assertEquals(weekField.getBaseUnit(), ChronoUnit.WEEKS); assertEquals(weekField.getRangeUnit(), IsoFields.WEEK_BASED_YEARS); }
Example #27
Source File: TCKIsoFields.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "parseLenientWeek") public void test_parse_parseLenientWeek_LENIENT(String str, LocalDate expected, boolean smart) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':') .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':') .appendValue(DAY_OF_WEEK) .toFormatter().withResolverStyle(ResolverStyle.LENIENT); LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, expected); }
Example #28
Source File: TCKDateTimeFormatters.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
void setFields(LocalDateTime dt) { if (dt != null) { fields.put(YEAR, (long) dt.getYear()); fields.put(MONTH_OF_YEAR, (long) dt.getMonthValue()); fields.put(DAY_OF_MONTH, (long) dt.getDayOfMonth()); fields.put(DAY_OF_YEAR, (long) dt.getDayOfYear()); fields.put(DAY_OF_WEEK, (long) dt.getDayOfWeek().getValue()); fields.put(IsoFields.WEEK_BASED_YEAR, dt.getLong(IsoFields.WEEK_BASED_YEAR)); fields.put(IsoFields.WEEK_OF_WEEK_BASED_YEAR, dt.getLong(IsoFields.WEEK_OF_WEEK_BASED_YEAR)); fields.put(HOUR_OF_DAY, (long) dt.getHour()); fields.put(MINUTE_OF_HOUR, (long) dt.getMinute()); fields.put(SECOND_OF_MINUTE, (long) dt.getSecond()); fields.put(NANO_OF_SECOND, (long) dt.getNano()); } }
Example #29
Source File: TestIsoWeekFields.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "fields") public void test_addTo_weekBasedYears(TemporalField weekField, TemporalField yearField) { // tests every day from 2012 to 2016 inclusive LocalDate date = LocalDate.of(2012, 1, 2); int wby = 2012; int week = 1; int dow = 1; for (int i = 1; i <= ((52 + 52 + 52 + 53 + 52) * 7); i++) { for (int j = -5; j <= 5; j++) { LocalDate adjusted = IsoFields.WEEK_BASED_YEARS.addTo(date, j); assertEquals(adjusted.get(yearField), wby + j); assertEquals(adjusted.get(DAY_OF_WEEK), dow); assertEquals(adjusted.get(weekField), (week == 53 && wbyLen(wby + j) == 52 ? 52 : week), "" + date + " " + adjusted); } if (dow == 7) { dow = 1; week++; } else { dow++; } if (week > wbyLen(wby)) { week = 1; wby++; } date = date.plusDays(1); } }
Example #30
Source File: TestLocalDate.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="quarterYearsToAdd") public void test_plus_QuarterYears(long quarterYears) { LocalDate t0 = TEST_2007_07_15 .plus(quarterYears, IsoFields.QUARTER_YEARS); LocalDate t1 = TEST_2007_07_15 .plus(quarterYears, ChronoUnit.MONTHS) .plus(quarterYears, ChronoUnit.MONTHS) .plus(quarterYears, ChronoUnit.MONTHS); assertEquals(t0, t1); }