The HijrahDate class incorrectly calculates the aligned-day-of-week field. It based the calculation on the day-of-week, when it should be based on the day-of-month.
HijrahDate line 372:
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((getDayOfWeek() - 1) % 7) + 1;
should be:
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfMonth - 1) % 7) + 1;
Proposed test case:
public void test_alignedDayOfWeekInMonth() {
for (int dom = 1; dom <= 29; dom++) {
HijrahDate date = HijrahChronology.INSTANCE.date(1437, 10, dom);
assertEquals(date.getLong(ALIGNED_WEEK_OF_MONTH), ((dom - 1) / 7) + 1);
assertEquals(date.getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH), ((dom - 1) % 7) + 1);
date = date.plus(1, ChronoUnit.DAYS);
}
}
Spotted by Martin Baker:
https://github.com/ThreeTen/threetenbp/pull/47
https://github.com/kemokid
HijrahDate line 372:
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((getDayOfWeek() - 1) % 7) + 1;
should be:
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfMonth - 1) % 7) + 1;
Proposed test case:
public void test_alignedDayOfWeekInMonth() {
for (int dom = 1; dom <= 29; dom++) {
HijrahDate date = HijrahChronology.INSTANCE.date(1437, 10, dom);
assertEquals(date.getLong(ALIGNED_WEEK_OF_MONTH), ((dom - 1) / 7) + 1);
assertEquals(date.getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH), ((dom - 1) % 7) + 1);
date = date.plus(1, ChronoUnit.DAYS);
}
}
Spotted by Martin Baker:
https://github.com/ThreeTen/threetenbp/pull/47
https://github.com/kemokid