use of java.time.temporal.WeekFields in project j2objc by google.
the class TCKWeekFields method test_parse_resolve_localizedWoWBY.
// -----------------------------------------------------------------------
@Test
@UseDataProvider("data_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(" :: " + str + " " + i, parsed, date);
date = date.plusDays(1);
}
}
use of java.time.temporal.WeekFields in project j2objc by google.
the class TCKWeekFields method test_equals.
// -----------------------------------------------------------------------
// equals() and hashCode().
// -----------------------------------------------------------------------
@Test
public void test_equals() {
WeekFields weekDef_iso = WeekFields.ISO;
WeekFields weekDef_sundayStart = WeekFields.SUNDAY_START;
assertTrue(weekDef_iso.equals(WeekFields.of(DayOfWeek.MONDAY, 4)));
assertTrue(weekDef_sundayStart.equals(WeekFields.of(DayOfWeek.SUNDAY, 1)));
assertEquals(weekDef_iso.hashCode(), WeekFields.of(DayOfWeek.MONDAY, 4).hashCode());
assertEquals(weekDef_sundayStart.hashCode(), WeekFields.of(DayOfWeek.SUNDAY, 1).hashCode());
assertFalse(weekDef_iso.equals(weekDef_sundayStart));
assertNotEquals(weekDef_iso.hashCode(), weekDef_sundayStart.hashCode());
}
use of java.time.temporal.WeekFields in project j2objc by google.
the class TCKLocalizedFieldParser method test_parse_WeekBasedYear.
@Test
@UseDataProvider("provider_patternLocalWeekBasedYearDate")
public void test_parse_WeekBasedYear(String pattern, String text, int pos, int expectedPos, LocalDate expectedValue) {
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 {
WeekFields weekDef = WeekFields.of(locale);
assertEquals("Incorrect ending parse position", ppos.getIndex(), expectedPos);
assertEquals(parsed.isSupported(weekDef.dayOfWeek()), pattern.indexOf('e') >= 0);
assertEquals(parsed.isSupported(weekDef.weekOfWeekBasedYear()), pattern.indexOf('w') >= 0);
assertEquals(parsed.isSupported(weekDef.weekBasedYear()), pattern.indexOf('Y') >= 0);
// ensure combination resolves into a date
LocalDate result = LocalDate.parse(text, dtf);
assertEquals("LocalDate incorrect for " + pattern + ", weekDef: " + weekDef, result, expectedValue);
}
}
use of java.time.temporal.WeekFields in project j2objc by google.
the class TCKWeekFieldsSerialization method test_serializable_singleton.
// -----------------------------------------------------------------------
@Test
@UseDataProvider("data_weekFields")
public void test_serializable_singleton(DayOfWeek firstDayOfWeek, int minDays) throws IOException, ClassNotFoundException {
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
// spec state singleton
assertSerializableSame(weekDef);
}
use of java.time.temporal.WeekFields in project dhis2-core by dhis2.
the class WeeklyAbstractPeriodType method getIsoDate.
@Override
public String getIsoDate(DateTimeUnit dateTimeUnit, Calendar calendar) {
int year;
int week;
if (calendar.isIso8601()) {
LocalDate date = LocalDate.of(dateTimeUnit.getYear(), dateTimeUnit.getMonth(), dateTimeUnit.getDay());
WeekFields weekFields = WeekFields.of(PeriodType.MAP_WEEK_TYPE.get(getName()), 4);
year = date.get(weekFields.weekBasedYear());
week = date.get(weekFields.weekOfWeekBasedYear());
} else {
dateTimeUnit = adjustToStartOfWeek(dateTimeUnit, calendar);
week = calendar.week(dateTimeUnit);
if (week == 1 && dateTimeUnit.getMonth() == calendar.monthsInYear()) {
dateTimeUnit.setYear(dateTimeUnit.getYear() + 1);
}
year = dateTimeUnit.getYear();
}
return String.format("%d%s%d", year, weekPrefix, week);
}
Aggregations