1 7 package com.ibm.icu.util; 8 9 import java.util.Date ; 10 import java.util.Locale ; 11 12 16 class CECalendar extends Calendar { 17 private static final long serialVersionUID = -999547623066414271L; 19 20 private static final int LIMITS[][] = { 21 {0, 0, 1, 1 }, {1, 1, 5828963, 5838270 }, {0, 0, 13, 13 }, {1, 1, 52, 53 }, {0, 0, 1, 6 }, {1, 1, 5, 30 }, {1, 1, 365, 366 }, {}, {-1, -1, 4, 6 }, {}, {}, {}, {}, {}, {}, {}, {}, {-5838270, -5838270, 5828964, 5838271}, {}, {-5838269, -5838269, 5828963, 5838270}, {}, {}, }; 46 47 private static final int[][] ceMONTH_COUNT = { 48 {30, 30, 0, 0}, {30, 30, 30, 30}, {30, 30, 60, 60}, {30, 30, 90, 90}, {30, 30, 120, 120}, {30, 30, 150, 150}, {30, 30, 180, 180}, {30, 30, 210, 210}, {30, 30, 240, 244}, {30, 30, 270, 270}, {30, 30, 300, 300}, {30, 30, 330, 330}, { 5, 6, 360, 360} }; 67 68 protected int jdEpochOffset = -1; 74 75 76 protected int handleGetLimit(int field, int limitType) { 77 return LIMITS[field][limitType]; 78 } 79 80 84 88 protected CECalendar() { 89 this(TimeZone.getDefault(), ULocale.getDefault()); 90 } 91 92 98 protected CECalendar(TimeZone zone) { 99 this(zone, ULocale.getDefault()); 100 } 101 102 108 protected CECalendar(Locale aLocale) { 109 this(TimeZone.getDefault(), aLocale); 110 } 111 112 118 protected CECalendar(ULocale locale) { 119 this(TimeZone.getDefault(), locale); 120 } 121 122 130 protected CECalendar(TimeZone zone, Locale aLocale) { 131 super(zone, aLocale); 132 setTimeInMillis(System.currentTimeMillis()); 133 } 134 135 143 protected CECalendar(TimeZone zone, ULocale locale) { 144 super(zone, locale); 145 setTimeInMillis(System.currentTimeMillis()); 146 } 147 148 159 protected CECalendar(int year, int month, int date) { 160 super(TimeZone.getDefault(), ULocale.getDefault()); 161 this.set(year, month, date); 162 } 163 164 170 protected CECalendar(Date date) { 171 super(TimeZone.getDefault(), ULocale.getDefault()); 172 this.setTime(date); 173 } 174 175 187 protected CECalendar(int year, int month, int date, int hour, 188 int minute, int second) 189 { 190 super(TimeZone.getDefault(), ULocale.getDefault()); 191 this.set(year, month, date, hour, minute, second); 192 } 193 194 195 199 202 protected int handleComputeMonthStart(int eyear, 203 int emonth, 204 boolean useMonth) { 205 return ceToJD(eyear, emonth, 0, jdEpochOffset); 206 } 207 208 211 protected int handleGetExtendedYear() { 212 int year; 213 if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) { 214 year = internalGet(EXTENDED_YEAR, 1); } else { 216 year = internalGet(YEAR, 1); } 218 return year; 219 } 220 221 224 protected void handleComputeFields(int julianDay) { 225 Integer [] date = getDateFromJD(julianDay, jdEpochOffset); 226 int _year = date[0].intValue(); 227 int _month = date[1].intValue(); 228 int _day = date[2].intValue(); 229 int ceyear = 0; 230 231 int era = GregorianCalendar.AD; 233 if (_year < 0) { era = GregorianCalendar.BC; 235 ceyear = 1 - _year; 236 } else { 237 ceyear = _year; 238 } 239 240 internalSet(MONTH, _month); 241 internalSet(DAY_OF_MONTH, _day); 242 internalSet(DAY_OF_YEAR, (30 * _month) + _day); 243 internalSet(EXTENDED_YEAR, ceyear); 244 internalSet(ERA, era); 245 internalSet(YEAR, _year); 246 } 247 248 251 public static int ceToJD(long year, int month, int date, int jdEpochOffset) { 252 253 257 return (int) ( 258 (jdEpochOffset+365) + 365 * (year - 1) + quotient(year, 4) + 30 * (month + 1) + date - 31 ); 265 } 266 267 271 public static Integer [] getDateFromJD(int julianDay, int jdEpochOffset) { 272 long r4 = mod(julianDay - jdEpochOffset, 1461); long n = mod(r4, 365) + 365 * quotient(r4, 1460); 276 long aprime = 4 * quotient(julianDay - jdEpochOffset, 1461) + quotient(r4, 365) - quotient(r4, 1460) - 1; 281 282 int _year = (int) (aprime + 1); 283 int _month = (int) (quotient(n, 30)); 284 int _day = mod(n, 30) + 1; 285 286 return new Integer []{ new Integer (_year), new Integer (_month), new Integer (_day) }; 287 } 288 289 293 static int mod(long i, int j) { 294 return (int) (i - (long) j * quotient(i, j)); 295 } 296 297 static int quotient(long i, int j) { 298 return (int) Math.floor((double) i / j); 299 } 300 } 301 | Popular Tags |