下面是一些用Java 给出的代码示例(Sample code),是作者最喜欢的Date Range。
 class DateRange...
 public DateRange (Date start, Date end) {
 this (new MfDate(start), new MfDate(end));
 }
 public DateRange (MfDate start, MfDate end) {
this.start = start;
 this.end = end;
 }
 class DateRange...
 public MfDate end(){
 return end;
 }
 public MfDate start() {
 return start;
 }
 public String toString() {
 if (isEmpty()) return "Empty Date Range";
 return start.toString() + " - " + end.toString();
 }
 public boolean isEmpty() {
 return start.after(end);
 }
 Range 最关键的方法:includes()方法。
 class DateRange...
 public boolean includes (MfDate arg) {
 return !arg.before(start) && !arg.after(end);
 }
 为开区间和空白范围提供的构造函数。
 class DateRange...
 public static DateRange upTo(MfDate end) {
return new DateRange(MfDate.PAST, end);
 }
 public static DateRange startingOn(MfDate start) {
 return new DateRange(start, MfDate.FUTURE);
 }
 public static DateRange EMPTY = new DateRange(new MfDate(2000,4,1), new MfDate(2000,1,1));
 对范围进行比较的方法也非常有用。
 class DateRange...
 public boolean equals (Object arg) {
 if (! (arg instanceof DateRange)) return false;
 DateRange other = (DateRange) arg;
 return start.equals(other.start) && end.equals(other.end);
 }
 public int hashCode() {
 return start.hashCode();
 }
 public boolean overlaps(DateRange arg) {
 return arg.includes(start) || arg.includes(end) || this.includes(arg);
 }
 public boolean includes(DateRange arg) {
 return this.includes(arg.start) && this.includes(arg.end);
 }
 其他一些可能有用的方法,例如两个范围的差(返回一个范围的下限和另一个范围上限之间的范围)
 class DateRange...