| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.lum.common.client.widgets; |
| 17 |
|
|
| 18 |
|
import java.util.Date; |
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
@author |
| 27 |
|
@version |
| 28 |
|
|
| 29 |
|
|
|
|
|
| 0% |
Uncovered Elements: 301 (301) |
Complexity: 116 |
Complexity Density: 0.52 |
|
| 30 |
|
public class GregorianCalendar extends Calendar |
| 31 |
|
{ |
| 32 |
|
public static final int BC = 0; |
| 33 |
|
public static final int AD = 1; |
| 34 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 35 |
0
|
public GregorianCalendar() {... |
| 36 |
0
|
super(); |
| 37 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 38 |
0
|
public GregorianCalendar(Date date) {... |
| 39 |
0
|
setTime(date); |
| 40 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 41 |
0
|
public GregorianCalendar(int year, int month, int date) {... |
| 42 |
0
|
set(year, month, date); |
| 43 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 44 |
0
|
public GregorianCalendar(int year, int month, int date, int hour) {... |
| 45 |
0
|
set(year, month, date, hour); |
| 46 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 47 |
0
|
public GregorianCalendar(int year, int month, int date, int hour, int minute) {... |
| 48 |
0
|
set(year, month, date, hour, minute); |
| 49 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
0
|
public GregorianCalendar(int year, int month, int date, int hour, int minute, int second) {... |
| 51 |
0
|
set(year, month, date, hour, minute, second); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
protected static int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31 ,30, 31, 30, 31}; |
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
| 55 |
0
|
public static int getMaxDaysInMonth(int year, int month) {... |
| 56 |
0
|
if (month == Calendar.FEBRUARY && isLeapYear(year)) |
| 57 |
0
|
return daysInMonth[month] + 1; |
| 58 |
|
else |
| 59 |
0
|
return daysInMonth[month]; |
| 60 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 61 |
0
|
public int getMaxDaysInMonth() {... |
| 62 |
0
|
return getMaxDaysInMonth(this.year, this.month); |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 10 |
Complexity Density: 1.11 |
|
| 65 |
0
|
public static int getNumOfWeeksInMonth(int year, int month, int firstDayOfWeek) {... |
| 66 |
0
|
int day1 = getWeekDay(year, month, 1); |
| 67 |
0
|
int maxDays = getMaxDaysInMonth(year, month); |
| 68 |
0
|
if (month == Calendar.FEBRUARY && !isLeapYear(year) && day1 == firstDayOfWeek) |
| 69 |
0
|
return 4; |
| 70 |
0
|
if (maxDays == 30 && (day1 > firstDayOfWeek + 5 || day1 < firstDayOfWeek)) |
| 71 |
0
|
return 6; |
| 72 |
0
|
if (maxDays == 31 && (day1 > firstDayOfWeek + 4 || day1 < firstDayOfWeek)) |
| 73 |
0
|
return 6; |
| 74 |
0
|
return 5; |
| 75 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
0
|
public int getNumOfWeeksInMonth() {... |
| 77 |
0
|
return getNumOfWeeksInMonth(this.year, this.month, this.firstWeekDayOfWeek); |
| 78 |
|
} |
| 79 |
|
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 13 |
Complexity Density: 0.62 |
|
| 80 |
0
|
public static int getWeekDay(int year, int month, int dayOfMonth) {... |
| 81 |
0
|
int weekDay = year - 1900; |
| 82 |
0
|
weekDay += weekDay/4; |
| 83 |
0
|
weekDay %= 7; |
| 84 |
0
|
if (month <= Calendar.FEBRUARY && isLeapYear(weekDay)) |
| 85 |
0
|
weekDay -= 1; |
| 86 |
0
|
weekDay += dayOfMonth; |
| 87 |
0
|
weekDay %= 7; |
| 88 |
0
|
if (month == Calendar.MAY) |
| 89 |
0
|
weekDay += 1; |
| 90 |
0
|
else if (month == Calendar.AUGUST) |
| 91 |
0
|
weekDay += 2; |
| 92 |
0
|
else if (month == Calendar.FEBRUARY || month == Calendar.MARCH || month == Calendar.NOVEMBER) |
| 93 |
0
|
weekDay += 3; |
| 94 |
0
|
else if (month == Calendar.JUNE) |
| 95 |
0
|
weekDay += 4; |
| 96 |
0
|
else if (month == Calendar.SEPTEMBER || month == Calendar.DECEMBER) |
| 97 |
0
|
weekDay += 5; |
| 98 |
0
|
else if (month == Calendar.APRIL || month == Calendar.JULY) |
| 99 |
0
|
weekDay += 6; |
| 100 |
0
|
weekDay %= 7; |
| 101 |
|
|
| 102 |
0
|
return Calendar.SUNDAY + weekDay; |
| 103 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 104 |
0
|
public int getWeekDay() {... |
| 105 |
0
|
return getWeekDay(this.year, this.month, this.dayOfMonth); |
| 106 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
0
|
public int getFirstWeekDayOfMonth() {... |
| 108 |
0
|
return getWeekDay(this.year, this.month, 1); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 112 |
0
|
public int getMinimum(int fieldCode) {... |
| 113 |
0
|
switch (fieldCode) { |
| 114 |
0
|
case Calendar.MILLISECOND: |
| 115 |
0
|
return 0; |
| 116 |
0
|
case Calendar.SECOND: |
| 117 |
0
|
return 0; |
| 118 |
0
|
case Calendar.MINUTE: |
| 119 |
0
|
return 0; |
| 120 |
0
|
case Calendar.HOUR: |
| 121 |
0
|
return 0; |
| 122 |
0
|
case Calendar.HOUR_OF_DAY: |
| 123 |
0
|
return 0; |
| 124 |
0
|
case Calendar.DATE: |
| 125 |
0
|
return 1; |
| 126 |
0
|
case Calendar.MONTH: |
| 127 |
0
|
return Calendar.JANUARY; |
| 128 |
0
|
default: |
| 129 |
0
|
return -1; |
| 130 |
|
} |
| 131 |
|
} |
| 132 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 133 |
0
|
public int getActualMinimum(int fieldCode) {... |
| 134 |
0
|
return getMinimum(fieldCode); |
| 135 |
|
} |
| 136 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 137 |
0
|
public int getGreatestMinimum(int fieldCode) {... |
| 138 |
0
|
return getMinimum(fieldCode); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 142 |
0
|
public int getMaximum(int fieldCode) {... |
| 143 |
0
|
switch (fieldCode) { |
| 144 |
0
|
case Calendar.MILLISECOND: |
| 145 |
0
|
return 999; |
| 146 |
0
|
case Calendar.SECOND: |
| 147 |
0
|
return 59; |
| 148 |
0
|
case Calendar.MINUTE: |
| 149 |
0
|
return 59; |
| 150 |
0
|
case Calendar.HOUR: |
| 151 |
0
|
return 11; |
| 152 |
0
|
case Calendar.HOUR_OF_DAY: |
| 153 |
0
|
return 23; |
| 154 |
0
|
case Calendar.DATE: |
| 155 |
0
|
return 31; |
| 156 |
0
|
case Calendar.MONTH: |
| 157 |
0
|
return Calendar.DECEMBER; |
| 158 |
0
|
default: |
| 159 |
0
|
return -1; |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 163 |
0
|
public int getActualMaximum(int fieldCode) {... |
| 164 |
0
|
switch (fieldCode) { |
| 165 |
0
|
case Calendar.MILLISECOND: |
| 166 |
0
|
return 999; |
| 167 |
0
|
case Calendar.SECOND: |
| 168 |
0
|
return 59; |
| 169 |
0
|
case Calendar.MINUTE: |
| 170 |
0
|
return 59; |
| 171 |
0
|
case Calendar.HOUR: |
| 172 |
0
|
return 11; |
| 173 |
0
|
case Calendar.HOUR_OF_DAY: |
| 174 |
0
|
return 23; |
| 175 |
0
|
case Calendar.DATE: |
| 176 |
0
|
return getMaxDaysInMonth(); |
| 177 |
0
|
case Calendar.MONTH: |
| 178 |
0
|
return Calendar.DECEMBER; |
| 179 |
0
|
default: |
| 180 |
0
|
return -1; |
| 181 |
|
} |
| 182 |
|
} |
| 183 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 184 |
0
|
public int getLeastMaximum(int fieldCode) {... |
| 185 |
0
|
switch (fieldCode) { |
| 186 |
0
|
case Calendar.MILLISECOND: |
| 187 |
0
|
return 999; |
| 188 |
0
|
case Calendar.SECOND: |
| 189 |
0
|
return 59; |
| 190 |
0
|
case Calendar.MINUTE: |
| 191 |
0
|
return 59; |
| 192 |
0
|
case Calendar.HOUR: |
| 193 |
0
|
return 11; |
| 194 |
0
|
case Calendar.HOUR_OF_DAY: |
| 195 |
0
|
return 23; |
| 196 |
0
|
case Calendar.DATE: |
| 197 |
0
|
return 28; |
| 198 |
0
|
case Calendar.MONTH: |
| 199 |
0
|
return Calendar.DECEMBER; |
| 200 |
0
|
default: |
| 201 |
0
|
return -1; |
| 202 |
|
} |
| 203 |
|
} |
| 204 |
|
|
| 205 |
|
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 11 |
Complexity Density: 0.34 |
|
| 206 |
0
|
public void set(int fieldCode, int value) {... |
| 207 |
0
|
switch (fieldCode) { |
| 208 |
0
|
case Calendar.SECOND: |
| 209 |
0
|
this.second = value; |
| 210 |
0
|
break; |
| 211 |
0
|
case Calendar.MINUTE: |
| 212 |
0
|
this.minute = value; |
| 213 |
0
|
break; |
| 214 |
0
|
case Calendar.HOUR: |
| 215 |
0
|
this.hour = value; |
| 216 |
0
|
break; |
| 217 |
0
|
case Calendar.HOUR_OF_DAY: |
| 218 |
0
|
if (value <= 12) { |
| 219 |
0
|
this.hour = value; |
| 220 |
0
|
this.amPm = Calendar.AM; |
| 221 |
|
} else { |
| 222 |
0
|
this.hour = value - 12; |
| 223 |
0
|
this.amPm = Calendar.PM; |
| 224 |
|
} |
| 225 |
0
|
break; |
| 226 |
0
|
case Calendar.DATE: |
| 227 |
0
|
this.dayOfMonth = value; |
| 228 |
0
|
break; |
| 229 |
0
|
case Calendar.MONTH: |
| 230 |
0
|
this.month = value; |
| 231 |
0
|
if (this.dayOfMonth > getMaxDaysInMonth()) |
| 232 |
0
|
this.dayOfMonth = getMaxDaysInMonth(); |
| 233 |
0
|
break; |
| 234 |
0
|
case Calendar.YEAR: |
| 235 |
0
|
this.year = value; |
| 236 |
0
|
break; |
| 237 |
0
|
case Calendar.AM_PM: |
| 238 |
0
|
this.amPm = value; |
| 239 |
0
|
break; |
| 240 |
|
} |
| 241 |
0
|
computeTime(); |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
|
| 245 |
|
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 10 |
Complexity Density: 0.37 |
|
| 246 |
0
|
public void add(int fieldCode, int amount) {... |
| 247 |
0
|
switch (fieldCode) { |
| 248 |
0
|
case Calendar.DATE: |
| 249 |
0
|
amount *= 24; |
| 250 |
0
|
case Calendar.HOUR: |
| 251 |
0
|
amount *= 60; |
| 252 |
0
|
case Calendar.MINUTE: |
| 253 |
0
|
amount *= 60; |
| 254 |
0
|
case Calendar.SECOND: |
| 255 |
0
|
amount *= 1000; |
| 256 |
0
|
case Calendar.MILLISECOND: |
| 257 |
0
|
this.date.setTime(this.date.getTime() + amount); |
| 258 |
0
|
computeFields(); |
| 259 |
0
|
break; |
| 260 |
0
|
case Calendar.MONTH: |
| 261 |
0
|
this.year += (this.month + amount) / 12; |
| 262 |
0
|
this.month = (this.month + amount) % 12; |
| 263 |
0
|
if (this.month < 0) { |
| 264 |
0
|
this.year -= 1; |
| 265 |
0
|
this.month += 12; |
| 266 |
|
} |
| 267 |
0
|
if (this.dayOfMonth > getMaxDaysInMonth()) |
| 268 |
0
|
this.dayOfMonth = getMaxDaysInMonth(); |
| 269 |
0
|
computeTime(); |
| 270 |
0
|
break; |
| 271 |
0
|
case Calendar.YEAR: |
| 272 |
0
|
this.year += amount; |
| 273 |
0
|
computeTime(); |
| 274 |
0
|
break; |
| 275 |
|
} |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
|
|
|
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 13 |
Complexity Density: 0.41 |
|
| 279 |
0
|
public void roll(int fieldCode, int amount) {... |
| 280 |
0
|
switch (fieldCode) { |
| 281 |
0
|
case Calendar.SECOND: |
| 282 |
0
|
this.second = (this.second + amount) % 60; |
| 283 |
0
|
if (this.second < 0) |
| 284 |
0
|
this.second += 60; |
| 285 |
0
|
break; |
| 286 |
0
|
case Calendar.MINUTE: |
| 287 |
0
|
this.minute = (this.minute + amount) % 60; |
| 288 |
0
|
if (this.minute < 0) |
| 289 |
0
|
this.minute += 60; |
| 290 |
0
|
break; |
| 291 |
0
|
case Calendar.HOUR: |
| 292 |
0
|
this.hour = (this.hour + amount) % 24; |
| 293 |
0
|
if (this.hour < 0) |
| 294 |
0
|
this.hour += 24; |
| 295 |
0
|
break; |
| 296 |
0
|
case Calendar.DATE: { |
| 297 |
0
|
this.dayOfMonth = (this.dayOfMonth + amount) % getActualMaximum(Calendar.DATE); |
| 298 |
0
|
if (this.dayOfMonth < 0) |
| 299 |
0
|
this.dayOfMonth += getActualMaximum(Calendar.DATE); |
| 300 |
0
|
break; |
| 301 |
|
} |
| 302 |
0
|
case Calendar.MONTH: { |
| 303 |
0
|
this.month = (this.month + amount) % 12; |
| 304 |
0
|
if (this.month < 0) |
| 305 |
0
|
this.month += 12; |
| 306 |
0
|
if (this.dayOfMonth > getActualMaximum(Calendar.DATE)) |
| 307 |
0
|
this.dayOfMonth = getActualMaximum(Calendar.DATE); |
| 308 |
0
|
break; |
| 309 |
|
} |
| 310 |
0
|
case Calendar.YEAR: |
| 311 |
0
|
this.year += amount; |
| 312 |
0
|
break; |
| 313 |
|
} |
| 314 |
0
|
computeTime(); |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
|
| 318 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 319 |
0
|
public boolean before(GregorianCalendar when) {... |
| 320 |
0
|
return this.date.before(when.getTime()); |
| 321 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 322 |
0
|
public boolean after(GregorianCalendar when) {... |
| 323 |
0
|
return this.date.after(when.getTime()); |
| 324 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 325 |
0
|
public boolean equals(GregorianCalendar obj) {... |
| 326 |
0
|
return this.date.equals(obj.getTime()); |
| 327 |
|
} |
| 328 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 329 |
0
|
public boolean isLeapYear() {... |
| 330 |
0
|
return isLeapYear(this.year); |
| 331 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 4 |
Complexity Density: 1.33 |
|
| 332 |
0
|
public static boolean isLeapYear(int year) {... |
| 333 |
0
|
if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0)) |
| 334 |
0
|
return true; |
| 335 |
0
|
return false; |
| 336 |
|
} |
| 337 |
|
|
| 338 |
|
|
| 339 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 340 |
0
|
protected void computeFields() {... |
| 341 |
0
|
this.second = this.date.getSeconds(); |
| 342 |
0
|
this.minute = this.date.getMinutes(); |
| 343 |
0
|
this.hour = this.date.getHours(); |
| 344 |
0
|
if (this.hour < 12) { |
| 345 |
0
|
this.amPm = Calendar.AM; |
| 346 |
|
} else { |
| 347 |
0
|
this.hour -= 12; |
| 348 |
0
|
this.amPm = Calendar.PM; |
| 349 |
|
} |
| 350 |
0
|
this.dayOfMonth = this.date.getDate(); |
| 351 |
0
|
this.month = this.date.getMonth(); |
| 352 |
0
|
this.year = this.date.getYear() + 1900; |
| 353 |
|
|
| 354 |
|
} |
| 355 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 356 |
0
|
protected void computeTime() {... |
| 357 |
0
|
this.date = new Date(this.year - 1900, this.month, this.dayOfMonth, this.hour, this.minute, this.second); |
| 358 |
|
} |
| 359 |
|
|
| 360 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 361 |
0
|
public Object clone() {... |
| 362 |
0
|
GregorianCalendar newCal = new GregorianCalendar(); |
| 363 |
0
|
newCal.setTime(this.date); |
| 364 |
0
|
return newCal; |
| 365 |
|
} |
| 366 |
|
|
| 367 |
|
} |