intl/icu/source/i18n/japancal.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/japancal.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,531 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +* Copyright (C) 2003-2009,2012, International Business Machines Corporation and    *
     1.7 +* others. All Rights Reserved.                                                *
     1.8 +*******************************************************************************
     1.9 +*
    1.10 +* File JAPANCAL.CPP
    1.11 +*
    1.12 +* Modification History:
    1.13 +*  05/16/2003    srl     copied from buddhcal.cpp
    1.14 +*
    1.15 +*/
    1.16 +
    1.17 +#include "unicode/utypes.h"
    1.18 +
    1.19 +#if !UCONFIG_NO_FORMATTING
    1.20 +
    1.21 +#include "japancal.h"
    1.22 +#include "unicode/gregocal.h"
    1.23 +#include "umutex.h"
    1.24 +#include "uassert.h"
    1.25 +
    1.26 +//#define U_DEBUG_JCAL
    1.27 +
    1.28 +#ifdef U_DEBUG_JCAL
    1.29 +#include <stdio.h>
    1.30 +#endif
    1.31 +
    1.32 +U_NAMESPACE_BEGIN
    1.33 +
    1.34 +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(JapaneseCalendar)
    1.35 +
    1.36 +//  Gregorian date of each emperor's ascension
    1.37 +//  Years are AD, months are 1-based.
    1.38 +static const struct { 
    1.39 +    int16_t year;
    1.40 +    int8_t  month;
    1.41 +    int8_t  day;
    1.42 +} kEraInfo[] =  {
    1.43 +    //  Year  Month Day
    1.44 +    {   645,    6, 19 },   // Taika   0
    1.45 +    {   650,    2, 15 },   // Hakuchi 1
    1.46 +    {   672,    1,  1 },   // Hakuho  2
    1.47 +    {   686,    7, 20 },   // Shucho  3
    1.48 +    {   701,    3, 21 },   // Taiho   4
    1.49 +    {   704,    5, 10 },   // Keiun   5
    1.50 +    {   708,    1, 11 },   // Wado    6
    1.51 +    {   715,    9,  2 },   // Reiki   7
    1.52 +    {   717,   11, 17 },   // Yoro    8
    1.53 +    {   724,    2,  4 },   // Jinki   9
    1.54 +    {   729,    8,  5 },   // Tempyo  10
    1.55 +    {   749,    4, 14 },   // Tempyo-kampo 11
    1.56 +    {   749,    7,  2 },   // Tempyo-shoho 12
    1.57 +    {   757,    8, 18 },   // Tempyo-hoji  13
    1.58 +    {   765,    1,  7 },   // Tempho-jingo 14
    1.59 +    {   767,    8, 16 },   // Jingo-keiun  15
    1.60 +    {   770,   10,  1 },   // Hoki         16
    1.61 +    {   781,    1,  1 },   // Ten-o        17
    1.62 +    {   782,    8, 19 },   // Enryaku      18
    1.63 +    {   806,    5, 18 },   // Daido        19
    1.64 +    {   810,    9, 19 },   // Konin        20
    1.65 +    {   824,    1,  5 },   // Tencho
    1.66 +    {   834,    1,  3 },   // Showa
    1.67 +    {   848,    6, 13 },   // Kajo
    1.68 +    {   851,    4, 28 },   // Ninju
    1.69 +    {   854,   11, 30 },   // Saiko
    1.70 +    {   857,    2, 21 },   // Tennan
    1.71 +    {   859,    4, 15 },   // Jogan
    1.72 +    {   877,    4, 16 },   // Genkei
    1.73 +    {   885,    2, 21 },   // Ninna
    1.74 +    {   889,    4, 27 },   // Kampyo       30
    1.75 +    {   898,    4, 26 },   // Shotai
    1.76 +    {   901,    7, 15 },   // Engi
    1.77 +    {   923,    4, 11 },   // Encho
    1.78 +    {   931,    4, 26 },   // Shohei
    1.79 +    {   938,    5, 22 },   // Tengyo
    1.80 +    {   947,    4, 22 },   // Tenryaku
    1.81 +    {   957,   10, 27 },   // Tentoku
    1.82 +    {   961,    2, 16 },   // Owa
    1.83 +    {   964,    7, 10 },   // Koho
    1.84 +    {   968,    8, 13 },   // Anna        40
    1.85 +    {   970,    3, 25 },   // Tenroku
    1.86 +    {   973,   12, 20 },   // Ten-en
    1.87 +    {   976,    7, 13 },   // Jogen
    1.88 +    {   978,   11, 29 },   // Tengen
    1.89 +    {   983,    4, 15 },   // Eikan
    1.90 +    {   985,    4, 27 },   // Kanna
    1.91 +    {   987,    4,  5 },   // Ei-en
    1.92 +    {   989,    8,  8 },   // Eiso
    1.93 +    {   990,   11,  7 },   // Shoryaku
    1.94 +    {   995,    2, 22 },   // Chotoku      50
    1.95 +    {   999,    1, 13 },   // Choho
    1.96 +    {  1004,    7, 20 },   // Kanko
    1.97 +    {  1012,   12, 25 },   // Chowa
    1.98 +    {  1017,    4, 23 },   // Kannin
    1.99 +    {  1021,    2,  2 },   // Jian
   1.100 +    {  1024,    7, 13 },   // Manju
   1.101 +    {  1028,    7, 25 },   // Chogen
   1.102 +    {  1037,    4, 21 },   // Choryaku
   1.103 +    {  1040,   11, 10 },   // Chokyu
   1.104 +    {  1044,   11, 24 },   // Kantoku      60
   1.105 +    {  1046,    4, 14 },   // Eisho
   1.106 +    {  1053,    1, 11 },   // Tengi
   1.107 +    {  1058,    8, 29 },   // Kohei
   1.108 +    {  1065,    8,  2 },   // Jiryaku
   1.109 +    {  1069,    4, 13 },   // Enkyu
   1.110 +    {  1074,    8, 23 },   // Shoho
   1.111 +    {  1077,   11, 17 },   // Shoryaku
   1.112 +    {  1081,    2, 10 },   // Eiho
   1.113 +    {  1084,    2,  7 },   // Otoku
   1.114 +    {  1087,    4,  7 },   // Kanji       70
   1.115 +    {  1094,   12, 15 },   // Kaho
   1.116 +    {  1096,   12, 17 },   // Eicho
   1.117 +    {  1097,   11, 21 },   // Shotoku
   1.118 +    {  1099,    8, 28 },   // Kowa
   1.119 +    {  1104,    2, 10 },   // Choji
   1.120 +    {  1106,    4,  9 },   // Kasho
   1.121 +    {  1108,    8,  3 },   // Tennin
   1.122 +    {  1110,    7, 13 },   // Ten-ei
   1.123 +    {  1113,    7, 13 },   // Eikyu
   1.124 +    {  1118,    4,  3 },   // Gen-ei      80
   1.125 +    {  1120,    4, 10 },   // Hoan
   1.126 +    {  1124,    4,  3 },   // Tenji
   1.127 +    {  1126,    1, 22 },   // Daiji
   1.128 +    {  1131,    1, 29 },   // Tensho
   1.129 +    {  1132,    8, 11 },   // Chosho
   1.130 +    {  1135,    4, 27 },   // Hoen
   1.131 +    {  1141,    7, 10 },   // Eiji
   1.132 +    {  1142,    4, 28 },   // Koji
   1.133 +    {  1144,    2, 23 },   // Tenyo
   1.134 +    {  1145,    7, 22 },   // Kyuan      90
   1.135 +    {  1151,    1, 26 },   // Ninpei
   1.136 +    {  1154,   10, 28 },   // Kyuju
   1.137 +    {  1156,    4, 27 },   // Hogen
   1.138 +    {  1159,    4, 20 },   // Heiji
   1.139 +    {  1160,    1, 10 },   // Eiryaku
   1.140 +    {  1161,    9,  4 },   // Oho
   1.141 +    {  1163,    3, 29 },   // Chokan
   1.142 +    {  1165,    6,  5 },   // Eiman
   1.143 +    {  1166,    8, 27 },   // Nin-an
   1.144 +    {  1169,    4,  8 },   // Kao       100
   1.145 +    {  1171,    4, 21 },   // Shoan
   1.146 +    {  1175,    7, 28 },   // Angen
   1.147 +    {  1177,    8,  4 },   // Jisho
   1.148 +    {  1181,    7, 14 },   // Yowa
   1.149 +    {  1182,    5, 27 },   // Juei
   1.150 +    {  1184,    4, 16 },   // Genryuku
   1.151 +    {  1185,    8, 14 },   // Bunji
   1.152 +    {  1190,    4, 11 },   // Kenkyu
   1.153 +    {  1199,    4, 27 },   // Shoji
   1.154 +    {  1201,    2, 13 },   // Kennin     110
   1.155 +    {  1204,    2, 20 },   // Genkyu
   1.156 +    {  1206,    4, 27 },   // Ken-ei
   1.157 +    {  1207,   10, 25 },   // Shogen
   1.158 +    {  1211,    3,  9 },   // Kenryaku
   1.159 +    {  1213,   12,  6 },   // Kenpo
   1.160 +    {  1219,    4, 12 },   // Shokyu
   1.161 +    {  1222,    4, 13 },   // Joo
   1.162 +    {  1224,   11, 20 },   // Gennin
   1.163 +    {  1225,    4, 20 },   // Karoku
   1.164 +    {  1227,   12, 10 },   // Antei      120
   1.165 +    {  1229,    3,  5 },   // Kanki
   1.166 +    {  1232,    4,  2 },   // Joei
   1.167 +    {  1233,    4, 15 },   // Tempuku
   1.168 +    {  1234,   11,  5 },   // Bunryaku
   1.169 +    {  1235,    9, 19 },   // Katei
   1.170 +    {  1238,   11, 23 },   // Ryakunin
   1.171 +    {  1239,    2,  7 },   // En-o
   1.172 +    {  1240,    7, 16 },   // Ninji
   1.173 +    {  1243,    2, 26 },   // Kangen
   1.174 +    {  1247,    2, 28 },   // Hoji      130
   1.175 +    {  1249,    3, 18 },   // Kencho
   1.176 +    {  1256,   10,  5 },   // Kogen
   1.177 +    {  1257,    3, 14 },   // Shoka
   1.178 +    {  1259,    3, 26 },   // Shogen
   1.179 +    {  1260,    4, 13 },   // Bun-o
   1.180 +    {  1261,    2, 20 },   // Kocho
   1.181 +    {  1264,    2, 28 },   // Bun-ei
   1.182 +    {  1275,    4, 25 },   // Kenji
   1.183 +    {  1278,    2, 29 },   // Koan
   1.184 +    {  1288,    4, 28 },   // Shoo      140
   1.185 +    {  1293,    8, 55 },   // Einin
   1.186 +    {  1299,    4, 25 },   // Shoan
   1.187 +    {  1302,   11, 21 },   // Kengen
   1.188 +    {  1303,    8,  5 },   // Kagen
   1.189 +    {  1306,   12, 14 },   // Tokuji
   1.190 +    {  1308,   10,  9 },   // Enkei
   1.191 +    {  1311,    4, 28 },   // Ocho
   1.192 +    {  1312,    3, 20 },   // Showa
   1.193 +    {  1317,    2,  3 },   // Bunpo
   1.194 +    {  1319,    4, 28 },   // Geno      150
   1.195 +    {  1321,    2, 23 },   // Genkyo
   1.196 +    {  1324,   12,  9 },   // Shochu
   1.197 +    {  1326,    4, 26 },   // Kareki
   1.198 +    {  1329,    8, 29 },   // Gentoku
   1.199 +    {  1331,    8,  9 },   // Genko
   1.200 +    {  1334,    1, 29 },   // Kemmu
   1.201 +    {  1336,    2, 29 },   // Engen
   1.202 +    {  1340,    4, 28 },   // Kokoku
   1.203 +    {  1346,   12,  8 },   // Shohei
   1.204 +    {  1370,    7, 24 },   // Kentoku       160
   1.205 +    {  1372,    4,  1 },   // Bunch\u0169
   1.206 +    {  1375,    5, 27 },   // Tenju
   1.207 +    {  1379,    3, 22 },   // Koryaku
   1.208 +    {  1381,    2, 10 },   // Kowa
   1.209 +    {  1384,    4, 28 },   // Gench\u0169
   1.210 +    {  1384,    2, 27 },   // Meitoku
   1.211 +    {  1387,    8, 23 },   // Kakei
   1.212 +    {  1389,    2,  9 },   // Koo
   1.213 +    {  1390,    3, 26 },   // Meitoku
   1.214 +    {  1394,    7,  5 },   // Oei           170
   1.215 +    {  1428,    4, 27 },   // Shocho
   1.216 +    {  1429,    9,  5 },   // Eikyo
   1.217 +    {  1441,    2, 17 },   // Kakitsu
   1.218 +    {  1444,    2,  5 },   // Bun-an
   1.219 +    {  1449,    7, 28 },   // Hotoku
   1.220 +    {  1452,    7, 25 },   // Kyotoku
   1.221 +    {  1455,    7, 25 },   // Kosho
   1.222 +    {  1457,    9, 28 },   // Choroku
   1.223 +    {  1460,   12, 21 },   // Kansho
   1.224 +    {  1466,    2, 28 },   // Bunsho        180
   1.225 +    {  1467,    3,  3 },   // Onin
   1.226 +    {  1469,    4, 28 },   // Bunmei
   1.227 +    {  1487,    7, 29 },   // Chokyo
   1.228 +    {  1489,    8, 21 },   // Entoku
   1.229 +    {  1492,    7, 19 },   // Meio
   1.230 +    {  1501,    2, 29 },   // Bunki
   1.231 +    {  1504,    2, 30 },   // Eisho
   1.232 +    {  1521,    8, 23 },   // Taiei
   1.233 +    {  1528,    8, 20 },   // Kyoroku
   1.234 +    {  1532,    7, 29 },   // Tenmon       190
   1.235 +    {  1555,   10, 23 },   // Koji
   1.236 +    {  1558,    2, 28 },   // Eiroku
   1.237 +    {  1570,    4, 23 },   // Genki
   1.238 +    {  1573,    7, 28 },   // Tensho
   1.239 +    {  1592,   12,  8 },   // Bunroku
   1.240 +    {  1596,   10, 27 },   // Keicho
   1.241 +    {  1615,    7, 13 },   // Genwa
   1.242 +    {  1624,    2, 30 },   // Kan-ei
   1.243 +    {  1644,   12, 16 },   // Shoho
   1.244 +    {  1648,    2, 15 },   // Keian       200
   1.245 +    {  1652,    9, 18 },   // Shoo
   1.246 +    {  1655,    4, 13 },   // Meiryaku
   1.247 +    {  1658,    7, 23 },   // Manji
   1.248 +    {  1661,    4, 25 },   // Kanbun
   1.249 +    {  1673,    9, 21 },   // Enpo
   1.250 +    {  1681,    9, 29 },   // Tenwa
   1.251 +    {  1684,    2, 21 },   // Jokyo
   1.252 +    {  1688,    9, 30 },   // Genroku
   1.253 +    {  1704,    3, 13 },   // Hoei
   1.254 +    {  1711,    4, 25 },   // Shotoku      210
   1.255 +    {  1716,    6, 22 },   // Kyoho
   1.256 +    {  1736,    4, 28 },   // Genbun
   1.257 +    {  1741,    2, 27 },   // Kanpo
   1.258 +    {  1744,    2, 21 },   // Enkyo
   1.259 +    {  1748,    7, 12 },   // Kan-en
   1.260 +    {  1751,   10, 27 },   // Horyaku
   1.261 +    {  1764,    6,  2 },   // Meiwa
   1.262 +    {  1772,   11, 16 },   // An-ei
   1.263 +    {  1781,    4,  2 },   // Tenmei
   1.264 +    {  1789,    1, 25 },   // Kansei      220
   1.265 +    {  1801,    2,  5 },   // Kyowa
   1.266 +    {  1804,    2, 11 },   // Bunka
   1.267 +    {  1818,    4, 22 },   // Bunsei
   1.268 +    {  1830,   12, 10 },   // Tenpo
   1.269 +    {  1844,   12,  2 },   // Koka
   1.270 +    {  1848,    2, 28 },   // Kaei
   1.271 +    {  1854,   11, 27 },   // Ansei
   1.272 +    {  1860,    3, 18 },   // Man-en
   1.273 +    {  1861,    2, 19 },   // Bunkyu
   1.274 +    {  1864,    2, 20 },   // Genji        230
   1.275 +    {  1865,    4,  7 },   // Keio     231
   1.276 +    {  1868,    9,  8 },   // Meiji    232
   1.277 +    {  1912,    7, 30 },   // Taisho   233
   1.278 +    {  1926,   12, 25 },   // Showa    234
   1.279 +    {  1989,    1,  8 }   // Heisei    235
   1.280 +};
   1.281 +
   1.282 +#define kEraCount (sizeof(kEraInfo)/sizeof(kEraInfo[0]))
   1.283 +
   1.284 +/**
   1.285 + * The current era, for reference. 
   1.286 + */
   1.287 +static const int32_t kCurrentEra = (kEraCount-1);  // int32_t to match the calendar field type
   1.288 +
   1.289 +static const int32_t kGregorianEpoch = 1970;    // used as the default value of EXTENDED_YEAR
   1.290 +
   1.291 +/* Some platforms don't like to export constants, like old Palm OS and some z/OS configurations. */
   1.292 +uint32_t JapaneseCalendar::getCurrentEra() {
   1.293 +    return kCurrentEra;
   1.294 +}
   1.295 +
   1.296 +JapaneseCalendar::JapaneseCalendar(const Locale& aLocale, UErrorCode& success)
   1.297 +:   GregorianCalendar(aLocale, success)
   1.298 +{
   1.299 +    setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
   1.300 +}
   1.301 +
   1.302 +JapaneseCalendar::~JapaneseCalendar()
   1.303 +{
   1.304 +}
   1.305 +
   1.306 +JapaneseCalendar::JapaneseCalendar(const JapaneseCalendar& source)
   1.307 +: GregorianCalendar(source)
   1.308 +{
   1.309 +}
   1.310 +
   1.311 +JapaneseCalendar& JapaneseCalendar::operator= ( const JapaneseCalendar& right)
   1.312 +{
   1.313 +    GregorianCalendar::operator=(right);
   1.314 +    return *this;
   1.315 +}
   1.316 +
   1.317 +Calendar* JapaneseCalendar::clone(void) const
   1.318 +{
   1.319 +    return new JapaneseCalendar(*this);
   1.320 +}
   1.321 +
   1.322 +const char *JapaneseCalendar::getType() const
   1.323 +{
   1.324 +    return "japanese";
   1.325 +}
   1.326 +
   1.327 +int32_t JapaneseCalendar::getDefaultMonthInYear(int32_t eyear) 
   1.328 +{
   1.329 +    int32_t era = internalGetEra();
   1.330 +    // TODO do we assume we can trust 'era'?  What if it is denormalized?
   1.331 +
   1.332 +    int32_t month = 0;
   1.333 +
   1.334 +    // Find out if we are at the edge of an era
   1.335 +
   1.336 +    if(eyear == kEraInfo[era].year) {
   1.337 +        // Yes, we're in the first year of this era.
   1.338 +        return kEraInfo[era].month-1;
   1.339 +    }
   1.340 +
   1.341 +    return month;
   1.342 +}
   1.343 +
   1.344 +int32_t JapaneseCalendar::getDefaultDayInMonth(int32_t eyear, int32_t month) 
   1.345 +{
   1.346 +    int32_t era = internalGetEra();
   1.347 +    int32_t day = 1;
   1.348 +
   1.349 +    if(eyear == kEraInfo[era].year) {
   1.350 +        if(month == (kEraInfo[era].month-1)) {
   1.351 +            return kEraInfo[era].day;
   1.352 +        }
   1.353 +    }
   1.354 +
   1.355 +    return day;
   1.356 +}
   1.357 +
   1.358 +
   1.359 +int32_t JapaneseCalendar::internalGetEra() const
   1.360 +{
   1.361 +    return internalGet(UCAL_ERA, kCurrentEra);
   1.362 +}
   1.363 +
   1.364 +int32_t JapaneseCalendar::handleGetExtendedYear()
   1.365 +{
   1.366 +    // EXTENDED_YEAR in JapaneseCalendar is a Gregorian year
   1.367 +    // The default value of EXTENDED_YEAR is 1970 (Showa 45)
   1.368 +    int32_t year;
   1.369 +
   1.370 +    if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR &&
   1.371 +        newerField(UCAL_EXTENDED_YEAR, UCAL_ERA) == UCAL_EXTENDED_YEAR) {
   1.372 +            year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
   1.373 +        } else {
   1.374 +            // Subtract one because year starts at 1
   1.375 +            year = internalGet(UCAL_YEAR) + kEraInfo[internalGetEra()].year - 1;
   1.376 +        }
   1.377 +        return year;
   1.378 +}
   1.379 +
   1.380 +
   1.381 +void JapaneseCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status)
   1.382 +{
   1.383 +    //Calendar::timeToFields(theTime, quick, status);
   1.384 +    GregorianCalendar::handleComputeFields(julianDay, status);
   1.385 +    int32_t year = internalGet(UCAL_EXTENDED_YEAR); // Gregorian year
   1.386 +
   1.387 +    int32_t low = 0;
   1.388 +
   1.389 +    // Short circuit for recent years.  Most modern computations will
   1.390 +    // occur in the current era and won't require the binary search.
   1.391 +    // Note that if the year is == the current era year, then we use
   1.392 +    // the binary search to handle the month/dom comparison.
   1.393 +#ifdef U_DEBUG_JCAL
   1.394 +    fprintf(stderr, "==  %d \n", year);
   1.395 +#endif
   1.396 +
   1.397 +    if (year > kEraInfo[kCurrentEra].year) {
   1.398 +        low = kCurrentEra;
   1.399 +#ifdef U_DEBUG_JCAL
   1.400 +        fprintf(stderr, " low=%d (special)\n", low);
   1.401 +#endif
   1.402 +    } else {
   1.403 +        // Binary search
   1.404 +        int32_t high = kEraCount;
   1.405 +
   1.406 +#ifdef U_DEBUG_JCAL
   1.407 +        fprintf(stderr, " high=%d\n", high);
   1.408 +#endif
   1.409 +        while (low < high - 1) {
   1.410 +            int32_t i = (low + high) / 2;
   1.411 +            int32_t diff = year - kEraInfo[i].year;
   1.412 +
   1.413 +#ifdef U_DEBUG_JCAL
   1.414 +            fprintf(stderr, "  d=%d   low=%d, high=%d. Considering %d:M%d D%d Y%d. { we are ?:M%d D%d Y%d }\n",
   1.415 +                diff,low, high, i, kEraInfo[i].month-1, kEraInfo[i].day,  kEraInfo[i].year, internalGet(UCAL_MONTH), internalGet(UCAL_DATE),year);
   1.416 +#endif
   1.417 +
   1.418 +            // If years are the same, then compare the months, and if those
   1.419 +            // are the same, compare days of month.  In the ERAS array
   1.420 +            // months are 1-based for easier maintenance.
   1.421 +            if (diff == 0) {
   1.422 +                diff = internalGet(UCAL_MONTH) - (kEraInfo[i].month - 1);
   1.423 +#ifdef U_DEBUG_JCAL
   1.424 +                fprintf(stderr, "diff now %d (M)  = %d - %d - 1\n", diff, internalGet(UCAL_MONTH), kEraInfo[i].month);
   1.425 +#endif
   1.426 +                if (diff == 0) {
   1.427 +                    diff = internalGet(UCAL_DATE) - kEraInfo[i].day;
   1.428 +#ifdef U_DEBUG_JCAL
   1.429 +                    fprintf(stderr, "diff now %d (D)\n", diff);
   1.430 +#endif
   1.431 +                }
   1.432 +            }
   1.433 +            if (diff >= 0) {
   1.434 +                low = i;
   1.435 +            } else {
   1.436 +                high = i;
   1.437 +            }
   1.438 +#ifdef U_DEBUG_JCAL
   1.439 +            fprintf(stderr, ". low=%d, high=%d, i=%d, diff=%d.. %d\n", low, high, i, diff, year);
   1.440 +#endif
   1.441 +
   1.442 +        }
   1.443 +    }
   1.444 +
   1.445 +#ifdef U_DEBUG_JCAL
   1.446 +    fprintf(stderr, "  low[era]=%d,.. %d\n", low, year);
   1.447 +#endif
   1.448 +    // Now we've found the last era that starts before this date, so
   1.449 +    // adjust the year to count from the start of that era.  Note that
   1.450 +    // all dates before the first era will fall into the first era by
   1.451 +    // the algorithm.
   1.452 +
   1.453 +    internalSet(UCAL_ERA, low);
   1.454 +    internalSet(UCAL_YEAR, year - kEraInfo[low].year + 1);
   1.455 +#ifdef U_DEBUG_JCAL
   1.456 +    fprintf(stderr, "  Set ERA=%d, year=%d\n", low, year-kEraInfo[low].year+1);
   1.457 +#endif
   1.458 +
   1.459 +}
   1.460 +
   1.461 +/*
   1.462 +Disable pivoting 
   1.463 +*/
   1.464 +UBool JapaneseCalendar::haveDefaultCentury() const
   1.465 +{
   1.466 +    return FALSE;
   1.467 +}
   1.468 +
   1.469 +UDate JapaneseCalendar::defaultCenturyStart() const
   1.470 +{
   1.471 +    return 0;// WRONG
   1.472 +}
   1.473 +
   1.474 +int32_t JapaneseCalendar::defaultCenturyStartYear() const
   1.475 +{
   1.476 +    return 0;
   1.477 +}
   1.478 +
   1.479 +int32_t JapaneseCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const
   1.480 +{
   1.481 +    switch(field) {
   1.482 +    case UCAL_ERA:
   1.483 +        if (limitType == UCAL_LIMIT_MINIMUM || limitType == UCAL_LIMIT_GREATEST_MINIMUM) {
   1.484 +            return 0;
   1.485 +        }
   1.486 +        return kCurrentEra;
   1.487 +    case UCAL_YEAR:
   1.488 +        {
   1.489 +            switch (limitType) {
   1.490 +            case UCAL_LIMIT_MINIMUM:
   1.491 +            case UCAL_LIMIT_GREATEST_MINIMUM:
   1.492 +                return 1;
   1.493 +            case UCAL_LIMIT_LEAST_MAXIMUM:
   1.494 +                return 1;
   1.495 +            case  UCAL_LIMIT_COUNT: //added to avoid warning
   1.496 +            case UCAL_LIMIT_MAXIMUM:
   1.497 +                return GregorianCalendar::handleGetLimit(UCAL_YEAR, UCAL_LIMIT_MAXIMUM) - kEraInfo[kCurrentEra].year;
   1.498 +            default:
   1.499 +                return 1;    // Error condition, invalid limitType
   1.500 +            }
   1.501 +        }
   1.502 +    default:
   1.503 +        return GregorianCalendar::handleGetLimit(field,limitType);
   1.504 +    }
   1.505 +}
   1.506 +
   1.507 +int32_t JapaneseCalendar::getActualMaximum(UCalendarDateFields field, UErrorCode& status) const {
   1.508 +    if (field == UCAL_YEAR) {
   1.509 +        int32_t era = get(UCAL_ERA, status);
   1.510 +        if (U_FAILURE(status)) {
   1.511 +            return 0; // error case... any value
   1.512 +        }
   1.513 +        if (era == kCurrentEra) {
   1.514 +            // TODO: Investigate what value should be used here - revisit after 4.0.
   1.515 +            return handleGetLimit(UCAL_YEAR, UCAL_LIMIT_MAXIMUM);
   1.516 +        } else {
   1.517 +            int32_t nextEraYear = kEraInfo[era + 1].year;
   1.518 +            int32_t nextEraMonth = kEraInfo[era + 1].month;
   1.519 +            int32_t nextEraDate = kEraInfo[era + 1].day;
   1.520 +
   1.521 +            int32_t maxYear = nextEraYear - kEraInfo[era].year + 1; // 1-base
   1.522 +            if (nextEraMonth == 1 && nextEraDate == 1) {
   1.523 +                // Subtract 1, because the next era starts at Jan 1
   1.524 +                maxYear--;
   1.525 +            }
   1.526 +            return maxYear;
   1.527 +        }
   1.528 +    }
   1.529 +    return GregorianCalendar::getActualMaximum(field, status);
   1.530 +}
   1.531 +
   1.532 +U_NAMESPACE_END
   1.533 +
   1.534 +#endif

mercurial