1 44 45 package org.jfree.date; 46 47 53 public class DayOfWeekInMonthRule extends AnnualDateRule { 54 55 56 private int count; 57 58 59 private int dayOfWeek; 60 61 62 private int month; 63 64 67 public DayOfWeekInMonthRule() { 68 this(1, SerialDate.MONDAY, MonthConstants.JANUARY); 69 } 70 71 78 public DayOfWeekInMonthRule(final int count, final int dayOfWeek, final int month) { 79 this.count = count; 80 this.dayOfWeek = dayOfWeek; 81 this.month = month; 82 } 83 84 89 public int getCount() { 90 return this.count; 91 } 92 93 98 public void setCount(final int count) { 99 this.count = count; 100 } 101 102 107 public int getDayOfWeek() { 108 return this.dayOfWeek; 109 } 110 111 116 public void setDayOfWeek(final int dayOfWeek) { 117 this.dayOfWeek = dayOfWeek; 118 } 119 120 125 public int getMonth() { 126 return this.month; 127 } 128 129 134 public void setMonth(final int month) { 135 this.month = month; 136 } 137 138 145 public SerialDate getDate(final int year) { 146 SerialDate result; 147 if (this.count != SerialDate.LAST_WEEK_IN_MONTH) { 148 result = SerialDate.createInstance(1, this.month, year); 150 while (result.getDayOfWeek() != this.dayOfWeek) { 151 result = SerialDate.addDays(1, result); 152 } 153 result = SerialDate.addDays(7 * (this.count - 1), result); 154 155 } 156 else { 157 result = SerialDate.createInstance(1, this.month, year); 159 result = result.getEndOfCurrentMonth(result); 160 while (result.getDayOfWeek() != this.dayOfWeek) { 161 result = SerialDate.addDays(-1, result); 162 } 163 164 } 165 return result; 166 } 167 168 } 169 | Popular Tags |