org.onetwo.common.date.timegen.DateOfMonthCycleGenerator Maven / Gradle / Ivy
package org.onetwo.common.date.timegen;
import java.util.Collection;
import java.util.LinkedHashSet;
import org.onetwo.common.date.DateRange;
import org.onetwo.common.date.DateRangeStaticFacotry;
import org.onetwo.common.date.timegen.TimeRule.RuleType;
import org.onetwo.common.utils.Assert;
public class DateOfMonthCycleGenerator implements DateGenerator {
public RuleType getRuleType(){
return RuleType.PERIOD_MONTH;
}
public Collection generate(TimeRule rule){
Assert.state(rule.getRuleType()==RuleType.PERIOD_MONTH);
Assert.notNull(rule.getStartTime());
Assert.notNull(rule.getEndTime());
Assert.notNull(rule.getStartIndex());
Assert.notNull(rule.getEndIndex());
Collection drs = DateRangeStaticFacotry.splitAsDateRangeByMonth(rule.getStartTime(), rule.getEndTime());
Collection genDateRangs = new LinkedHashSet(drs.size());
for(DateRange dr : drs){
int startIndex = rule.getStartIndex();
if(startIndexdr.getEnd().getDayOfMonth())
endIndex = dr.getEnd().getDayOfMonth();
if(startIndex>endIndex)
continue;
DateRange newDr = new DateRange(dr.getStart().withDayOfMonth(startIndex), dr.getStart().withDayOfMonth(endIndex));
System.out.println("new dir: " + newDr);
genDateRangs.add(newDr);
}
return genDateRangs;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy