1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************* 354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius* Copyright (C) 2003-2009,2012, International Business Machines Corporation and * 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* others. All Rights Reserved. * 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************* 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File JAPANCAL.CPP 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History: 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 05/16/2003 srl copied from buddhcal.cpp 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "japancal.h" 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/gregocal.h" 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "umutex.h" 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uassert.h" 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//#define U_DEBUG_JCAL 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h> 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUOBJECT_DEFINE_RTTI_IMPLEMENTATION(JapaneseCalendar) 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Gregorian date of each emperor's ascension 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Years are AD, months are 1-based. 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const struct { 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int16_t year; 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int8_t month; 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int8_t day; 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} kEraInfo[] = { 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Year Month Day 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 645, 6, 19 }, // Taika 0 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 650, 2, 15 }, // Hakuchi 1 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 672, 1, 1 }, // Hakuho 2 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 686, 7, 20 }, // Shucho 3 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 701, 3, 21 }, // Taiho 4 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 704, 5, 10 }, // Keiun 5 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 708, 1, 11 }, // Wado 6 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 715, 9, 2 }, // Reiki 7 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 717, 11, 17 }, // Yoro 8 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 724, 2, 4 }, // Jinki 9 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 729, 8, 5 }, // Tempyo 10 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 749, 4, 14 }, // Tempyo-kampo 11 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 749, 7, 2 }, // Tempyo-shoho 12 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 757, 8, 18 }, // Tempyo-hoji 13 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 765, 1, 7 }, // Tempho-jingo 14 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 767, 8, 16 }, // Jingo-keiun 15 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 770, 10, 1 }, // Hoki 16 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 781, 1, 1 }, // Ten-o 17 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 782, 8, 19 }, // Enryaku 18 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 806, 5, 18 }, // Daido 19 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 810, 9, 19 }, // Konin 20 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 824, 1, 5 }, // Tencho 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 834, 1, 3 }, // Showa 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 848, 6, 13 }, // Kajo 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 851, 4, 28 }, // Ninju 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 854, 11, 30 }, // Saiko 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 857, 2, 21 }, // Tennan 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 859, 4, 15 }, // Jogan 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 877, 4, 16 }, // Genkei 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 885, 2, 21 }, // Ninna 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 889, 4, 27 }, // Kampyo 30 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 898, 4, 26 }, // Shotai 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 901, 7, 15 }, // Engi 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 923, 4, 11 }, // Encho 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 931, 4, 26 }, // Shohei 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 938, 5, 22 }, // Tengyo 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 947, 4, 22 }, // Tenryaku 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 957, 10, 27 }, // Tentoku 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 961, 2, 16 }, // Owa 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 964, 7, 10 }, // Koho 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 968, 8, 13 }, // Anna 40 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 970, 3, 25 }, // Tenroku 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 973, 12, 20 }, // Ten-en 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 976, 7, 13 }, // Jogen 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 978, 11, 29 }, // Tengen 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 983, 4, 15 }, // Eikan 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 985, 4, 27 }, // Kanna 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 987, 4, 5 }, // Ei-en 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 989, 8, 8 }, // Eiso 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 990, 11, 7 }, // Shoryaku 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 995, 2, 22 }, // Chotoku 50 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 999, 1, 13 }, // Choho 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1004, 7, 20 }, // Kanko 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1012, 12, 25 }, // Chowa 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1017, 4, 23 }, // Kannin 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1021, 2, 2 }, // Jian 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1024, 7, 13 }, // Manju 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1028, 7, 25 }, // Chogen 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1037, 4, 21 }, // Choryaku 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1040, 11, 10 }, // Chokyu 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1044, 11, 24 }, // Kantoku 60 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1046, 4, 14 }, // Eisho 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1053, 1, 11 }, // Tengi 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1058, 8, 29 }, // Kohei 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1065, 8, 2 }, // Jiryaku 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1069, 4, 13 }, // Enkyu 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1074, 8, 23 }, // Shoho 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1077, 11, 17 }, // Shoryaku 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1081, 2, 10 }, // Eiho 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1084, 2, 7 }, // Otoku 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1087, 4, 7 }, // Kanji 70 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1094, 12, 15 }, // Kaho 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1096, 12, 17 }, // Eicho 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1097, 11, 21 }, // Shotoku 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1099, 8, 28 }, // Kowa 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1104, 2, 10 }, // Choji 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1106, 4, 9 }, // Kasho 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1108, 8, 3 }, // Tennin 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1110, 7, 13 }, // Ten-ei 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1113, 7, 13 }, // Eikyu 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1118, 4, 3 }, // Gen-ei 80 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1120, 4, 10 }, // Hoan 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1124, 4, 3 }, // Tenji 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1126, 1, 22 }, // Daiji 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1131, 1, 29 }, // Tensho 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1132, 8, 11 }, // Chosho 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1135, 4, 27 }, // Hoen 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1141, 7, 10 }, // Eiji 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1142, 4, 28 }, // Koji 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1144, 2, 23 }, // Tenyo 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1145, 7, 22 }, // Kyuan 90 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1151, 1, 26 }, // Ninpei 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1154, 10, 28 }, // Kyuju 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1156, 4, 27 }, // Hogen 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1159, 4, 20 }, // Heiji 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1160, 1, 10 }, // Eiryaku 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1161, 9, 4 }, // Oho 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1163, 3, 29 }, // Chokan 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1165, 6, 5 }, // Eiman 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1166, 8, 27 }, // Nin-an 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1169, 4, 8 }, // Kao 100 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1171, 4, 21 }, // Shoan 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1175, 7, 28 }, // Angen 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1177, 8, 4 }, // Jisho 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1181, 7, 14 }, // Yowa 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1182, 5, 27 }, // Juei 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1184, 4, 16 }, // Genryuku 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1185, 8, 14 }, // Bunji 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1190, 4, 11 }, // Kenkyu 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1199, 4, 27 }, // Shoji 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1201, 2, 13 }, // Kennin 110 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1204, 2, 20 }, // Genkyu 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1206, 4, 27 }, // Ken-ei 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1207, 10, 25 }, // Shogen 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1211, 3, 9 }, // Kenryaku 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1213, 12, 6 }, // Kenpo 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1219, 4, 12 }, // Shokyu 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1222, 4, 13 }, // Joo 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1224, 11, 20 }, // Gennin 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1225, 4, 20 }, // Karoku 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1227, 12, 10 }, // Antei 120 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1229, 3, 5 }, // Kanki 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1232, 4, 2 }, // Joei 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1233, 4, 15 }, // Tempuku 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1234, 11, 5 }, // Bunryaku 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1235, 9, 19 }, // Katei 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1238, 11, 23 }, // Ryakunin 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1239, 2, 7 }, // En-o 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1240, 7, 16 }, // Ninji 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1243, 2, 26 }, // Kangen 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1247, 2, 28 }, // Hoji 130 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1249, 3, 18 }, // Kencho 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1256, 10, 5 }, // Kogen 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1257, 3, 14 }, // Shoka 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1259, 3, 26 }, // Shogen 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1260, 4, 13 }, // Bun-o 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1261, 2, 20 }, // Kocho 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1264, 2, 28 }, // Bun-ei 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1275, 4, 25 }, // Kenji 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1278, 2, 29 }, // Koan 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1288, 4, 28 }, // Shoo 140 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1293, 8, 55 }, // Einin 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1299, 4, 25 }, // Shoan 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1302, 11, 21 }, // Kengen 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1303, 8, 5 }, // Kagen 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1306, 12, 14 }, // Tokuji 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1308, 10, 9 }, // Enkei 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1311, 4, 28 }, // Ocho 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1312, 3, 20 }, // Showa 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1317, 2, 3 }, // Bunpo 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1319, 4, 28 }, // Geno 150 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1321, 2, 23 }, // Genkyo 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1324, 12, 9 }, // Shochu 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1326, 4, 26 }, // Kareki 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1329, 8, 29 }, // Gentoku 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1331, 8, 9 }, // Genko 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1334, 1, 29 }, // Kemmu 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1336, 2, 29 }, // Engen 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1340, 4, 28 }, // Kokoku 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1346, 12, 8 }, // Shohei 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1370, 7, 24 }, // Kentoku 160 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1372, 4, 1 }, // Bunch\u0169 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1375, 5, 27 }, // Tenju 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1379, 3, 22 }, // Koryaku 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1381, 2, 10 }, // Kowa 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1384, 4, 28 }, // Gench\u0169 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1384, 2, 27 }, // Meitoku 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1387, 8, 23 }, // Kakei 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1389, 2, 9 }, // Koo 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1390, 3, 26 }, // Meitoku 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1394, 7, 5 }, // Oei 170 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1428, 4, 27 }, // Shocho 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1429, 9, 5 }, // Eikyo 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1441, 2, 17 }, // Kakitsu 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1444, 2, 5 }, // Bun-an 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1449, 7, 28 }, // Hotoku 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1452, 7, 25 }, // Kyotoku 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1455, 7, 25 }, // Kosho 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1457, 9, 28 }, // Choroku 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1460, 12, 21 }, // Kansho 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1466, 2, 28 }, // Bunsho 180 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1467, 3, 3 }, // Onin 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1469, 4, 28 }, // Bunmei 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1487, 7, 29 }, // Chokyo 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1489, 8, 21 }, // Entoku 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1492, 7, 19 }, // Meio 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1501, 2, 29 }, // Bunki 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1504, 2, 30 }, // Eisho 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1521, 8, 23 }, // Taiei 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1528, 8, 20 }, // Kyoroku 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1532, 7, 29 }, // Tenmon 190 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1555, 10, 23 }, // Koji 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1558, 2, 28 }, // Eiroku 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1570, 4, 23 }, // Genki 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1573, 7, 28 }, // Tensho 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1592, 12, 8 }, // Bunroku 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1596, 10, 27 }, // Keicho 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1615, 7, 13 }, // Genwa 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1624, 2, 30 }, // Kan-ei 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1644, 12, 16 }, // Shoho 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1648, 2, 15 }, // Keian 200 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1652, 9, 18 }, // Shoo 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1655, 4, 13 }, // Meiryaku 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1658, 7, 23 }, // Manji 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1661, 4, 25 }, // Kanbun 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1673, 9, 21 }, // Enpo 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1681, 9, 29 }, // Tenwa 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1684, 2, 21 }, // Jokyo 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1688, 9, 30 }, // Genroku 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1704, 3, 13 }, // Hoei 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1711, 4, 25 }, // Shotoku 210 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1716, 6, 22 }, // Kyoho 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1736, 4, 28 }, // Genbun 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1741, 2, 27 }, // Kanpo 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1744, 2, 21 }, // Enkyo 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1748, 7, 12 }, // Kan-en 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1751, 10, 27 }, // Horyaku 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1764, 6, 2 }, // Meiwa 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1772, 11, 16 }, // An-ei 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1781, 4, 2 }, // Tenmei 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1789, 1, 25 }, // Kansei 220 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1801, 2, 5 }, // Kyowa 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1804, 2, 11 }, // Bunka 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1818, 4, 22 }, // Bunsei 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1830, 12, 10 }, // Tenpo 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1844, 12, 2 }, // Koka 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1848, 2, 28 }, // Kaei 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1854, 11, 27 }, // Ansei 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1860, 3, 18 }, // Man-en 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1861, 2, 19 }, // Bunkyu 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1864, 2, 20 }, // Genji 230 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1865, 4, 7 }, // Keio 231 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1868, 9, 8 }, // Meiji 232 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1912, 7, 30 }, // Taisho 233 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1926, 12, 25 }, // Showa 234 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1989, 1, 8 } // Heisei 235 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define kEraCount (sizeof(kEraInfo)/sizeof(kEraInfo[0])) 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 28185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/** 28285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * The current era, for reference. 28385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */ 28485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic const int32_t kCurrentEra = (kEraCount-1); // int32_t to match the calendar field type 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const int32_t kGregorianEpoch = 1970; // used as the default value of EXTENDED_YEAR 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Some platforms don't like to export constants, like old Palm OS and some z/OS configurations. */ 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruuint32_t JapaneseCalendar::getCurrentEra() { 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return kCurrentEra; 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruJapaneseCalendar::JapaneseCalendar(const Locale& aLocale, UErrorCode& success) 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru: GregorianCalendar(aLocale, success) 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruJapaneseCalendar::~JapaneseCalendar() 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruJapaneseCalendar::JapaneseCalendar(const JapaneseCalendar& source) 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru: GregorianCalendar(source) 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruJapaneseCalendar& JapaneseCalendar::operator= ( const JapaneseCalendar& right) 309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GregorianCalendar::operator=(right); 311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return *this; 312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCalendar* JapaneseCalendar::clone(void) const 315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return new JapaneseCalendar(*this); 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char *JapaneseCalendar::getType() const 320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return "japanese"; 322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 32485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hoint32_t JapaneseCalendar::getDefaultMonthInYear(int32_t eyear) 325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t era = internalGetEra(); 327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // TODO do we assume we can trust 'era'? What if it is denormalized? 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 32985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t month = 0; 330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Find out if we are at the edge of an era 332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(eyear == kEraInfo[era].year) { 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Yes, we're in the first year of this era. 335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return kEraInfo[era].month-1; 336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return month; 339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 34185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hoint32_t JapaneseCalendar::getDefaultDayInMonth(int32_t eyear, int32_t month) 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t era = internalGetEra(); 34485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t day = 1; 345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 34685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(eyear == kEraInfo[era].year) { 347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(month == (kEraInfo[era].month-1)) { 348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return kEraInfo[era].day; 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return day; 353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t JapaneseCalendar::internalGetEra() const 357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return internalGet(UCAL_ERA, kCurrentEra); 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t JapaneseCalendar::handleGetExtendedYear() 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // EXTENDED_YEAR in JapaneseCalendar is a Gregorian year 364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // The default value of EXTENDED_YEAR is 1970 (Showa 45) 365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t year; 366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR && 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru newerField(UCAL_EXTENDED_YEAR, UCAL_ERA) == UCAL_EXTENDED_YEAR) { 369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch); 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Subtract one because year starts at 1 372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru year = internalGet(UCAL_YEAR) + kEraInfo[internalGetEra()].year - 1; 373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return year; 375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid JapaneseCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status) 379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //Calendar::timeToFields(theTime, quick, status); 381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru GregorianCalendar::handleComputeFields(julianDay, status); 382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t year = internalGet(UCAL_EXTENDED_YEAR); // Gregorian year 383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t low = 0; 385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Short circuit for recent years. Most modern computations will 387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // occur in the current era and won't require the binary search. 388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Note that if the year is == the current era year, then we use 389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // the binary search to handle the month/dom comparison. 390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, "== %d \n", year); 392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (year > kEraInfo[kCurrentEra].year) { 395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru low = kCurrentEra; 396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, " low=%d (special)\n", low); 398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Binary search 401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t high = kEraCount; 402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, " high=%d\n", high); 405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (low < high - 1) { 407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = (low + high) / 2; 408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t diff = year - kEraInfo[i].year; 409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 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", 412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru diff,low, high, i, kEraInfo[i].month-1, kEraInfo[i].day, kEraInfo[i].year, internalGet(UCAL_MONTH), internalGet(UCAL_DATE),year); 413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // If years are the same, then compare the months, and if those 416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // are the same, compare days of month. In the ERAS array 417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // months are 1-based for easier maintenance. 418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (diff == 0) { 419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru diff = internalGet(UCAL_MONTH) - (kEraInfo[i].month - 1); 420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, "diff now %d (M) = %d - %d - 1\n", diff, internalGet(UCAL_MONTH), kEraInfo[i].month); 422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (diff == 0) { 424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru diff = internalGet(UCAL_DATE) - kEraInfo[i].day; 425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, "diff now %d (D)\n", diff); 427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (diff >= 0) { 431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru low = i; 432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru high = i; 434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, ". low=%d, high=%d, i=%d, diff=%d.. %d\n", low, high, i, diff, year); 437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, " low[era]=%d,.. %d\n", low, year); 444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Now we've found the last era that starts before this date, so 446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // adjust the year to count from the start of that era. Note that 447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // all dates before the first era will fall into the first era by 448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // the algorithm. 449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru internalSet(UCAL_ERA, low); 451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru internalSet(UCAL_YEAR, year - kEraInfo[low].year + 1); 452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifdef U_DEBUG_JCAL 453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, " Set ERA=%d, year=%d\n", low, year-kEraInfo[low].year+1); 454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruDisable pivoting 460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUBool JapaneseCalendar::haveDefaultCentury() const 462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return FALSE; 464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUDate JapaneseCalendar::defaultCenturyStart() const 467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 0;// WRONG 469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t JapaneseCalendar::defaultCenturyStartYear() const 472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 0; 474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t JapaneseCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const 477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru switch(field) { 47985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case UCAL_ERA: 48085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (limitType == UCAL_LIMIT_MINIMUM || limitType == UCAL_LIMIT_GREATEST_MINIMUM) { 48154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return 0; 48285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 48385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return kCurrentEra; 484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case UCAL_YEAR: 485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 48685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho switch (limitType) { 48785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case UCAL_LIMIT_MINIMUM: 48885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case UCAL_LIMIT_GREATEST_MINIMUM: 48985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return 1; 49085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case UCAL_LIMIT_LEAST_MAXIMUM: 49185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return 1; 49285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case UCAL_LIMIT_COUNT: //added to avoid warning 49385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho case UCAL_LIMIT_MAXIMUM: 49485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return GregorianCalendar::handleGetLimit(UCAL_YEAR, UCAL_LIMIT_MAXIMUM) - kEraInfo[kCurrentEra].year; 49585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho default: 49685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return 1; // Error condition, invalid limitType 497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru default: 500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return GregorianCalendar::handleGetLimit(field,limitType); 501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 50485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hoint32_t JapaneseCalendar::getActualMaximum(UCalendarDateFields field, UErrorCode& status) const { 50585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (field == UCAL_YEAR) { 50685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t era = get(UCAL_ERA, status); 50785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (U_FAILURE(status)) { 50885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return 0; // error case... any value 50985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 51085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (era == kCurrentEra) { 51185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho // TODO: Investigate what value should be used here - revisit after 4.0. 51285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return handleGetLimit(UCAL_YEAR, UCAL_LIMIT_MAXIMUM); 51385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 51485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t nextEraYear = kEraInfo[era + 1].year; 51585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t nextEraMonth = kEraInfo[era + 1].month; 51685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t nextEraDate = kEraInfo[era + 1].day; 51785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 51885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t maxYear = nextEraYear - kEraInfo[era].year + 1; // 1-base 51985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (nextEraMonth == 1 && nextEraDate == 1) { 52085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho // Subtract 1, because the next era starts at Jan 1 52185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho maxYear--; 52285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 52385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return maxYear; 52485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 52585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 52685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return GregorianCalendar::getActualMaximum(field, status); 52785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 532