1 7 package com.ibm.icu.util; 8 import com.ibm.icu.util.TimeZone; 9 import java.util.Date ; 10 import java.util.Locale ; 11 12 49 public class JapaneseCalendar extends GregorianCalendar { 50 private static final long serialVersionUID = -2977189902603704691L; 52 53 private static String copyright = "Copyright \u00a9 1998 IBM Corp. All Rights Reserved."; 54 55 59 64 public JapaneseCalendar() { 65 super(); 66 } 67 68 74 public JapaneseCalendar(TimeZone zone) { 75 super(zone); 76 } 77 78 84 public JapaneseCalendar(Locale aLocale) { 85 super(aLocale); 86 } 87 88 95 public JapaneseCalendar(ULocale locale) { 96 super(locale); 97 } 98 99 108 public JapaneseCalendar(TimeZone zone, Locale aLocale) { 109 super(zone, aLocale); 110 } 111 112 122 public JapaneseCalendar(TimeZone zone, ULocale locale) { 123 super(zone, locale); 124 } 125 126 133 public JapaneseCalendar(Date date) { 134 this(); 135 setTime(date); 136 } 137 138 160 public JapaneseCalendar(int era, int year, int month, int date) { 161 super(year, month, date); 162 set(ERA, era); 163 } 164 165 179 public JapaneseCalendar(int year, int month, int date) { 180 super(year, month, date); 181 set(ERA, CURRENT_ERA); 182 } 183 184 204 public JapaneseCalendar(int year, int month, int date, int hour, 205 int minute, int second) 206 { 207 super(year, month, date, hour, minute, second); 208 set(ERA, CURRENT_ERA); 209 } 210 211 213 216 protected int handleGetExtendedYear() { 217 int year; 218 if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR && 219 newerField(EXTENDED_YEAR, ERA) == EXTENDED_YEAR) { 220 year = internalGet(EXTENDED_YEAR, 1); 221 } else { 222 year = internalGet(YEAR, 1) + ERAS[internalGet(ERA, CURRENT_ERA) * 3] - 1; } 227 return year; 228 } 229 230 239 protected int getDefaultMonthInYear(int extendedYear) 240 { 241 int era = internalGet(ERA, CURRENT_ERA); 242 244 if(extendedYear == ERAS[era*3]) { 246 return ERAS[(era*3)+1] -1; } else { 249 return super.getDefaultMonthInYear(extendedYear); 250 } 251 } 252 253 263 protected int getDefaultDayInMonth(int extendedYear, int month) { 264 int era = internalGet(ERA, CURRENT_ERA); 265 266 if(extendedYear == ERAS[era*3]) { if(month == ((ERAS[(era*3)+1])-1)) { return ERAS[(era*3)+2]; } 270 } 271 272 return super.getDefaultDayInMonth(extendedYear, month); 273 } 274 275 278 protected void handleComputeFields(int julianDay) { 279 super.handleComputeFields(julianDay); 280 int year = internalGet(EXTENDED_YEAR); 281 282 int low = 0; 283 284 if (year > ERAS[ERAS.length - 3]) { 289 low = CURRENT_ERA; 290 } else { 291 int high = ERAS.length / 3; 293 294 while (low < high - 1) { 295 int i = (low + high) / 2; 296 int diff = year - ERAS[i*3]; 297 298 if (diff == 0) { 302 diff = internalGet(MONTH) - (ERAS[i*3 + 1] - 1); 303 if (diff == 0) { 304 diff = internalGet(DAY_OF_MONTH) - ERAS[i*3 + 2]; 305 } 306 } 307 if (diff >= 0) { 308 low = i; 309 } else { 310 high = i; 311 } 312 } 313 } 314 315 internalSet(ERA, low); 320 internalSet(YEAR, year - ERAS[low*3] + 1); 321 } 322 323 private static final int[] ERAS = { 324 645, 6, 19, 650, 2, 15, 672, 1, 1, 686, 7, 20, 701, 3, 21, 704, 5, 10, 708, 1, 11, 715, 9, 2, 717, 11, 17, 724, 2, 4, 729, 8, 5, 749, 4, 14, 749, 7, 2, 757, 8, 18, 765, 1, 7, 767, 8, 16, 770, 10, 1, 781, 1, 1, 782, 8, 19, 806, 5, 18, 810, 9, 19, 824, 1, 5, 834, 1, 3, 848, 6, 13, 851, 4, 28, 854, 11, 30, 857, 2, 21, 859, 4, 15, 877, 4, 16, 885, 2, 21, 889, 4, 27, 898, 4, 26, 901, 7, 15, 923, 4, 11, 931, 4, 26, 938, 5, 22, 947, 4, 22, 957, 10, 27, 961, 2, 16, 964, 7, 10, 968, 8, 13, 970, 3, 25, 973, 12, 20, 976, 7, 13, 978, 11, 29, 983, 4, 15, 985, 4, 27, 987, 4, 5, 989, 8, 8, 990, 11, 7, 995, 2, 22, 999, 1, 13, 1004, 7, 20, 1012, 12, 25, 1017, 4, 23, 1021, 2, 2, 1024, 7, 13, 1028, 7, 25, 1037, 4, 21, 1040, 11, 10, 1044, 11, 24, 1046, 4, 14, 1053, 1, 11, 1058, 8, 29, 1065, 8, 2, 1069, 4, 13, 1074, 8, 23, 1077, 11, 17, 1081, 2, 10, 1084, 2, 7, 1087, 4, 7, 1094, 12, 15, 1096, 12, 17, 1097, 11, 21, 1099, 8, 28, 1104, 2, 10, 1106, 4, 9, 1108, 8, 3, 1110, 7, 13, 1113, 7, 13, 1118, 4, 3, 1120, 4, 10, 1124, 4, 3, 1126, 1, 22, 1131, 1, 29, 1132, 8, 11, 1135, 4, 27, 1141, 7, 10, 1142, 4, 28, 1144, 2, 23, 1145, 7, 22, 1151, 1, 26, 1154, 10, 28, 1156, 4, 27, 1159, 4, 20, 1160, 1, 10, 1161, 9, 4, 1163, 3, 29, 1165, 6, 5, 1166, 8, 27, 1169, 4, 8, 1171, 4, 21, 1175, 7, 28, 1177, 8, 4, 1181, 7, 14, 1182, 5, 27, 1184, 4, 16, 1185, 8, 14, 1190, 4, 11, 1199, 4, 27, 1201, 2, 13, 1204, 2, 20, 1206, 4, 27, 1207, 10, 25, 1211, 3, 9, 1213, 12, 6, 1219, 4, 12, 1222, 4, 13, 1224, 11, 20, 1225, 4, 20, 1227, 12, 10, 1229, 3, 5, 1232, 4, 2, 1233, 4, 15, 1234, 11, 5, 1235, 9, 19, 1238, 11, 23, 1239, 2, 7, 1240, 7, 16, 1243, 2, 26, 1247, 2, 28, 1249, 3, 18, 1256, 10, 5, 1257, 3, 14, 1259, 3, 26, 1260, 4, 13, 1261, 2, 20, 1264, 2, 28, 1275, 4, 25, 1278, 2, 29, 1288, 4, 28, 1293, 8, 55, 1299, 4, 25, 1302, 11, 21, 1303, 8, 5, 1306, 12, 14, 1308, 10, 9, 1311, 4, 28, 1312, 3, 20, 1317, 2, 3, 1319, 4, 28, 1321, 2, 23, 1324, 12, 9, 1326, 4, 26, 1329, 8, 29, 1331, 8, 9, 1334, 1, 29, 1336, 2, 29, 1340, 4, 28, 1346, 12, 8, 1370, 7, 24, 1372, 4, 1, 1375, 5, 27, 1379, 3, 22, 1381, 2, 10, 1384, 4, 28, 1384, 2, 27, 1387, 8, 23, 1389, 2, 9, 1390, 3, 26, 1394, 7, 5, 1428, 4, 27, 1429, 9, 5, 1441, 2, 17, 1444, 2, 5, 1449, 7, 28, 1452, 7, 25, 1455, 7, 25, 1457, 9, 28, 1460, 12, 21, 1466, 2, 28, 1467, 3, 3, 1469, 4, 28, 1487, 7, 29, 1489, 8, 21, 1492, 7, 19, 1501, 2, 29, 1504, 2, 30, 1521, 8, 23, 1528, 8, 20, 1532, 7, 29, 1555, 10, 23, 1558, 2, 28, 1570, 4, 23, 1573, 7, 28, 1592, 12, 8, 1596, 10, 27, 1615, 7, 13, 1624, 2, 30, 1644, 12, 16, 1648, 2, 15, 1652, 9, 18, 1655, 4, 13, 1658, 7, 23, 1661, 4, 25, 1673, 9, 21, 1681, 9, 29, 1684, 2, 21, 1688, 9, 30, 1704, 3, 13, 1711, 4, 25, 1716, 6, 22, 1736, 4, 28, 1741, 2, 27, 1744, 2, 21, 1748, 7, 12, 1751, 10, 27, 1764, 6, 2, 1772, 11, 16, 1781, 4, 2, 1789, 1, 25, 1801, 2, 5, 1804, 2, 11, 1818, 4, 22, 1830, 12, 10, 1844, 12, 2, 1848, 2, 28, 1854, 11, 27, 1860, 3, 18, 1861, 2, 19, 1864, 2, 20, 1865, 4, 7, 1868, 9, 8, 1912, 7, 30, 1926, 12, 25, 1989, 1, 8, }; 564 565 569 573 static public final int CURRENT_ERA = (ERAS.length / 3) - 1; 574 575 579 static public final int MEIJI = CURRENT_ERA - 3; 580 581 585 static public final int TAISHO = CURRENT_ERA - 2; 586 587 591 static public final int SHOWA = CURRENT_ERA - 1; 592 593 597 static public final int HEISEI = CURRENT_ERA; 598 599 603 private static int LIMITS[][] = { 604 { 0, 0, CURRENT_ERA, CURRENT_ERA }, { 1, 1, 0, 0 }, }; 609 610 private static boolean YEAR_LIMIT_KNOWN = false; 611 612 618 protected int handleGetLimit(int field, int limitType) { 619 switch (field) { 620 case ERA: 621 return LIMITS[field][limitType]; 622 case YEAR: 623 if (!YEAR_LIMIT_KNOWN) { 624 int min = ERAS[3] - ERAS[0]; 625 int max = min; 626 for (int i=6; i<ERAS.length; i+=3) { 627 int d = ERAS[i] - ERAS[i-3]; 628 if (d < min) { 629 min = d; 630 } 631 if (d > max) { 632 max = d; 633 } 634 } 635 LIMITS[field][LEAST_MAXIMUM] = ++min; LIMITS[field][MAXIMUM] = ++max; 638 YEAR_LIMIT_KNOWN=true; 639 } 640 return LIMITS[field][limitType]; 641 default: 642 return super.handleGetLimit(field, limitType); 643 } 644 } 645 646 652 public String getType() { 653 return "japanese"; 654 } 655 656 673 } 674 | Popular Tags |