next method
Implementation
SolarWeek next(int weeks, bool separateMonth) {
if (0 == weeks) {
return SolarWeek.fromYmd(_year, _month, _day, _start);
}
Solar solar = Solar.fromYmd(_year, _month, _day);
if (separateMonth) {
int n = weeks;
SolarWeek week = SolarWeek.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay(), _start);
int month = _month;
bool plus = n > 0;
while (0 != n) {
solar = solar.next(plus ? 7 : -7);
week = SolarWeek.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay(), _start);
int weekMonth = week.getMonth();
if (month != weekMonth) {
int index = week.getIndex();
if (plus) {
if (1 == index) {
Solar firstDay = week.getFirstDay();
week = SolarWeek.fromYmd(firstDay.getYear(), firstDay.getMonth(), firstDay.getDay(), _start);
weekMonth = week.getMonth();
} else {
solar = Solar.fromYmd(week.getYear(), week.getMonth(), 1);
week = SolarWeek.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay(), _start);
}
} else {
if (SolarUtil.getWeeksOfMonth(week.getYear(), week.getMonth(), _start) == index) {
Solar lastDay = week.getFirstDay().next(6);
week = SolarWeek.fromYmd(lastDay.getYear(), lastDay.getMonth(), lastDay.getDay(), _start);
weekMonth = week.getMonth();
} else {
solar = Solar.fromYmd(week.getYear(), week.getMonth(), SolarUtil.getDaysOfMonth(week.getYear(), week.getMonth()));
week = SolarWeek.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay(), _start);
}
}
month = weekMonth;
}
n -= plus ? 1 : -1;
}
return week;
} else {
solar = solar.next(weeks * 7);
return SolarWeek.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay(), _start);
}
}