package ch.pollet.jzic.timezone;
import ch.pollet.jzic.datetime.DateTime;
import ch.pollet.jzic.datetime.DateTimeException;
import java.util.TreeSet;
/**
*
* @author Christophe Pollet
*/
public class Rule {
private String name;
private int fromYear;
private int toYear;
private String type;
private DateTime at;
private int offset;
private String format;
public void dump() {
System.out.println(" from " + fromYear);
System.out.println(" to " + toYear);
System.out.println(" type " + type);
System.out.println(" at " + at);
System.out.println(" offset " + offset);
System.out.println(" format " + format);
}
public TreeSet<Period> toPeriods(Period zonePeriod) throws DateTimeException {
TreeSet<Period> periods = new TreeSet<Period>();
int startYear = Math.max(this.fromYear, zonePeriod.getFrom().getYear());
int endYear = Math.min(this.toYear, zonePeriod.getTo().getYear());
Period period;
DateTime from = null;
for (int i = startYear; i <= endYear; i++) {
period = new Period();
from = at.clone();
from.setYear(i);
from.computeDayOfMonth();
if (from.compareTo(zonePeriod.getFrom()) < 0) {
continue;
}
if (from.compareTo(zonePeriod.getTo()) > 0) {
continue;
}
period.setFrom(from);
period.setPeriodName(String.format(zonePeriod.getFormat(), format));
period.setOffset(zonePeriod.getOffset() + offset);
if (offset > 0) {
period.isStdOffset(false);
} else {
period.isStdOffset(true);
}
periods.add(period);
}
return periods;
}
//<editor-fold defaultstate="collapsed" desc="getters/setters">
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getFromYear() {
return fromYear;
}
public void setFromYear(int fromYear) {
this.fromYear = fromYear;
}
public int getToYear() {
return toYear;
}
public void setToYear(int toYear) {
this.toYear = toYear;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public DateTime getAt() {
return at;
}
public void setAt(DateTime at) {
this.at = at;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
//</editor-fold>
}