Java Code Examples for java.time.temporal.WeekFields#getMinimalDaysInFirstWeek()
The following examples show how to use
java.time.temporal.WeekFields#getMinimalDaysInFirstWeek() .
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 dragonwell8_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 2
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 3
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 4
Source File: TCKWeekFields.java From openjdk-jdk8u 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 5
Source File: TCKWeekFields.java From openjdk-jdk8u-backup 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 6
Source File: TCKWeekFields.java From openjdk-jdk9 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 7
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 8
Source File: TCKWeekFields.java From hottub 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 9
Source File: TCKWeekFields.java From openjdk-8-source 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-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 11
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 12
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 13
Source File: TCKWeekFields.java From jdk8u-dev-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 14
Source File: TCKWeekFields.java From j2objc with Apache License 2.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 @UseDataProvider("data_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("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), result, day); day = day.plusDays(1); } }