File Coverage

lib/DateTime/Format/JP.pm
Criterion Covered Total %
statement 456 681 66.9
branch 228 500 45.6
condition 80 208 38.4
subroutine 79 101 78.2
pod 17 18 94.4
total 860 1508 57.0


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Japanese DateTime Parser/Formatter - ~/lib/DateTime/Format/JP.pm
3             ## Version v0.1.1
4             ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2021/07/18
7             ## Modified 2021/07/22
8             ## All rights reserved
9             ##
10             ## This program is free software; you can redistribute it and/or modify it
11             ## under the same terms as Perl itself.
12             ##----------------------------------------------------------------------------
13             package DateTime::Format::JP;
14             BEGIN
15             {
16 2     2   189078 use strict;
  2         12  
  2         51  
17 2     2   7 use warnings;
  2         2  
  2         49  
18 2     2   8 use warnings::register;
  2         3  
  2         198  
19 2     2   818 use parent qw( Exporter );
  2         496  
  2         8  
20 2     2   1325 use Nice::Try;
  2         207811  
  2         11  
21 2     2   7747015 our $VERSION = 'v0.1.1';
22 2         6 our $DICT = [];
23 2         4 our $ZENKAKU_NUMBERS = [];
24 2         3 our $KANJI_NUMBERS = [];
25 2         3 our $ZENKAKU_TO_ROMAN= {};
26 2         4 our $KANJI_TO_ROMAN = {};
27 2         3 our $WEEKDAYS = [];
28 2         3 our $WEEKDAYS_RE;
29 2         2 our $TIME_RE;
30 2         74 our( $DATETIME_PATTERN_1_RE, $DATETIME_PATTERN_2_RE, $DATETIME_PATTERN_3_RE )
31             };
32              
33             INIT
34             {
35 2     2   1616 use utf8;
  2         31  
  2         17  
36 2     2   238 $ZENKAKU_NUMBERS = [qw(0 1 2 3 4 5 6 7 8 9)];
37 2         21 $KANJI_NUMBERS = [qw(〇 一 二 三 四 五 六 七 八 九 十 十一 十二 十三 十四 十五 十六 十七 十八 十九)];
38 2         9 $WEEKDAYS = [qw( 月 火 水 木 金 土 日 )];
39 2         9 for( 0..9 )
40             {
41 20         35 $ZENKAKU_TO_ROMAN->{ $ZENKAKU_NUMBERS->[$_] } = $_;
42 20         35 $KANJI_TO_ROMAN->{ $KANJI_NUMBERS->[$_] } = $_;
43             }
44 2         9 $WEEKDAYS_RE = qr/(?:月|火|水|木|金|土|日)/;
45 2         8 $TIME_RE = qr/
46             (?<ampm>午前|午後)?
47             (?<hour>\d{1,2})時
48             (?:
49             (?<minute>\d{1,2})分?
50             (?:
51             (?<=分)
52             (?<second>\d{1,2})秒
53             )?
54             )?
55             /x;
56 2         6 $TIME_ZENKAKU_RE = qr/
57             (?<ampm>午前|午後)?
58             (?<hour>[0123456789]{1,2})時
59             (?:
60             (?<minute>[0123456789]{1,2})分?
61             (?:
62             (?<=分)
63             (?<second>[0123456789]{1,2})秒
64             )?
65             )?
66             /x;
67 2         7 $TIME_KANJI_RE = qr/
68             (?<ampm>午前|午後)?
69             (?<hour>[〇一二三四五六七八九十]{1,3})時
70             (?:
71             (?<minute>[〇一二三四五六七八九十]{1,3})分?
72             (?:
73             (?<=分)
74             (?<second>[〇一二三四五六七八九十]{1,3})秒
75             )?
76             )?
77             /x;
78            
79             # 令和3年7月12日(月)
80             # 令和3年7月12日(月)14時
81             # 令和3年7月12日(月)14時7
82             # 令和3年7月12日(月)14時7分
83             # 令和3年7月12日(月)14時7分30秒
84             # 令和3年7月12日
85             # 令和3年7月12日14時
86             # 令和3年7月12日14時7
87             # 令和3年7月12日14時7分
88             # 令和3年7月12日14時7分30秒
89             # or
90             # 2020年7月12日(月)
91             # 2020年7月12日(月)14時
92             # 2020年7月12日(月)14時7
93             # 2020年7月12日(月)14時7分
94             # 2020年7月12日(月)14時7分30秒
95             # 2020年7月12日
96             # 2020年7月12日14時
97             # 2020年7月12日14時7
98             # 2020年7月12日14時7分
99             # 2020年7月12日14時7分30秒
100 2         123 $DATETIME_PATTERN_1_RE = qr/
101             ^[[:blank:]\h]*
102             (?:
103             (?:
104             (?<era>[\p{Han}]+)
105             (?<year>\d{1,2})
106             )
107             |
108             (?<gregorian_year>\d{1,4})
109             )年
110             (?<month>\d{1,2})月
111             (?<day>\d{1,2})日
112             (?:[\((]?(?<dow>$WEEKDAYS_RE)[\))]?)?
113             (?:
114             $TIME_RE
115             )?
116             [[:blank:]\h]*$
117             /x;
118             # Same as pattern No 1, but using double bytes (Japanese) numbers
119 2         1495 $DATETIME_PATTERN_2_RE = qr/
120             ^[[:blank:]\h]*
121             (?:
122             (?:
123             (?<era>[\p{Han}]+)
124             (?<year>[0123456789]{1,2})
125             )
126             |
127             (?<gregorian_year>\d{1,4})
128             )年
129             (?<month>[0123456789]{1,2})月
130             (?<day>[0123456789]{1,2})日
131             (?:[\((]?(?<dow>$WEEKDAYS_RE)[\))]?)?
132             (?:
133             $TIME_ZENKAKU_RE
134             )?
135             [[:blank:]\h]*$
136             /x;
137             # Same as pattern No 1, but using Kanji numbers
138 2         448 $DATETIME_PATTERN_3_RE = qr/
139             ^[[:blank:]\h]*
140             (?:
141             (?:
142             (?=[\p{Han}]+)
143             (?<era>[^〇一二三四五六七八九十百千]+)
144             # 三, 三十二
145             (?<year>[〇一二三四五六七八九十]{1,3})
146             )
147             |
148             # 二千三百四十八
149             (?<gregorian_year>[〇一二三四五六七八九十百千]{1,7})
150             )年
151             (?<month>[〇一二三四五六七八九十]{1,2})月
152             (?<day>[〇一二三四五六七八九十]{1,2})日
153             (?:[\((]?(?<dow>$WEEKDAYS_RE)[\))]?)?
154             (?:
155             $TIME_KANJI_RE
156             )?
157             [[:blank:]\h]*$
158             /x;
159            
160 2         2418 $DICT =
161             [
162             { name => '大化', period => '飛鳥時代', reading => ['たいか'], start => [645,7,17], end => [650,3,22] }, # 6年 from 645/7/17 until 650/3/22
163             { name => '白雉', period => '飛鳥時代', reading => ['はくち','びゃくち','しらきぎす'], start => [650,3,22], end => [654,11,24] }, # 5年 from 650/3/22 until 654/11/24
164             { name => '', period => '飛鳥時代', reading => [''], start => [654,11,24], end => [686,8,14] }, # 32年 from 654/11/24 until 686/8/14
165             { name => '朱鳥', period => '飛鳥時代', reading => ['しゅちょう','すちょう','あかみとり'], start => [686,8,14], end => [686,10,1] }, # 1年 from 686/8/14 until 686/10/1
166             { name => '', period => '飛鳥時代', reading => [''], start => [686,10,1], end => [701,5,3] }, # 15年 from 686/10/1 until 701/5/3
167             { name => '大宝', period => '飛鳥時代', reading => ['たいほう','だいほう'], start => [701,5,3], end => [704,6,16] }, # 4年 from 701/5/3 until 704/6/16
168             { name => '慶雲', period => '飛鳥時代', reading => ['けいうん','きょううん'], start => [704,6,16], end => [708,2,7] }, # 5年 from 704/6/16 until 708/2/7
169             { name => '和銅', period => '飛鳥時代', reading => ['わどう'], start => [708,2,7], end => [715,10,3] }, # 8年 from 708/2/7 until 715/10/3
170             { name => '霊亀', period => '奈良時代', reading => ['れいき'], start => [715,10,3], end => [717,12,24] }, # 3年 from 715/10/3 until 717/12/24
171             { name => '養老', period => '奈良時代', reading => ['ようろう'], start => [717,12,24], end => [724,3,3] }, # 8年 from 717/12/24 until 724/3/3
172             { name => '神亀', period => '奈良時代', reading => ['じんき'], start => [724,3,3], end => [729,9,2] }, # 6年 from 724/3/3 until 729/9/2
173             { name => '天平', period => '奈良時代', reading => ['てんぴょう'], start => [729,9,2], end => [749,5,4] }, # 21年 from 729/9/2 until 749/5/4
174             { name => '天平感宝', period => '奈良時代', reading => ['てんぴょうかんぽう'], start => [749,5,4], end => [749,8,19] }, # 1年 from 749/5/4 until 749/8/19
175             { name => '天平勝宝', period => '奈良時代', reading => ['てんぴょうしょうほう'], start => [749,8,19], end => [757,9,6] }, # 9年 from 749/8/19 until 757/9/6
176             { name => '天平宝字', period => '奈良時代', reading => ['てんぴょうほうじ'], start => [757,9,6], end => [765,2,1] }, # 9年 from 757/9/6 until 765/2/1
177             { name => '天平神護', period => '奈良時代', reading => ['てんぴょうじんご'], start => [765,2,1], end => [767,9,13] }, # 3年 from 765/2/1 until 767/9/13
178             { name => '神護景雲', period => '奈良時代', reading => ['じんごけいうん'], start => [767,9,13], end => [770,10,23] }, # 4年 from 767/9/13 until 770/10/23
179             { name => '宝亀', period => '奈良時代', reading => ['ほうき'], start => [770,10,23], end => [781,1,30] }, # 12年 from 770/10/23 until 781/1/30
180             { name => '天応', period => '奈良時代', reading => ['てんおう','てんのう'], start => [781,1,30], end => [782,9,30] }, # 2年 from 781/1/30 until 782/9/30
181             { name => '延暦', period => '奈良時代', reading => ['えんりゃく'], start => [782,9,30], end => [806,6,8] }, # 25年 from 782/9/30 until 806/6/8
182             { name => '大同', period => '平安時代', reading => ['だいどう'], start => [806,6,8], end => [810,10,20] }, # 5年 from 806/6/8 until 810/10/20
183             { name => '弘仁', period => '平安時代', reading => ['こうにん'], start => [810,10,20], end => [824,2,8] }, # 15年 from 810/10/20 until 824/2/8
184             { name => '天長', period => '平安時代', reading => ['てんちょう'], start => [824,2,8], end => [834,2,14] }, # 11年 from 824/2/8 until 834/2/14
185             { name => '承和', period => '平安時代', reading => ['じょうわ','しょうわ'], start => [834,2,14], end => [848,7,16] }, # 15年 from 834/2/14 until 848/7/16
186             { name => '嘉祥', period => '平安時代', reading => ['かしょう','かじょう'], start => [848,7,16], end => [851,6,1] }, # 4年 from 848/7/16 until 851/6/1
187             { name => '仁寿', period => '平安時代', reading => ['にんじゅ'], start => [851,6,1], end => [854,12,23] }, # 4年 from 851/6/1 until 854/12/23
188             { name => '斉衡', period => '平安時代', reading => ['さいこう'], start => [854,12,23], end => [857,3,20] }, # 4年 from 854/12/23 until 857/3/20
189             { name => '天安', period => '平安時代', reading => ['てんあん','てんなん'], start => [857,3,20], end => [859,5,20] }, # 3年 from 857/3/20 until 859/5/20
190             { name => '貞観', period => '平安時代', reading => ['じょうがん'], start => [859,5,20], end => [877,6,1] }, # 19年 from 859/5/20 until 877/6/1
191             { name => '元慶', period => '平安時代', reading => ['がんぎょう'], start => [877,6,1], end => [885,3,11] }, # 9年 from 877/6/1 until 885/3/11
192             { name => '仁和', period => '平安時代', reading => ['にんな','にんわ'], start => [885,3,11], end => [889,5,30] }, # 5年 from 885/3/11 until 889/5/30
193             { name => '寛平', period => '平安時代', reading => ['かんぴょう','かんぺい','かんへい'], start => [889,5,30], end => [898,5,20] }, # 10年 from 889/5/30 until 898/5/20
194             { name => '昌泰', period => '平安時代', reading => ['しょうたい'], start => [898,5,20], end => [901,8,31] }, # 4年 from 898/5/20 until 901/8/31
195             { name => '延喜', period => '平安時代', reading => ['えんぎ'], start => [901,8,31], end => [923,5,29] }, # 23年 from 901/8/31 until 923/5/29
196             { name => '延長', period => '平安時代', reading => ['えんちょう'], start => [923,5,29], end => [931,5,16] }, # 9年 from 923/5/29 until 931/5/16
197             { name => '承平', period => '平安時代', reading => ['じょうへい','しょうへい'], start => [931,5,16], end => [938,6,22] }, # 8年 from 931/5/16 until 938/6/22
198             { name => '天慶', period => '平安時代', reading => ['てんぎょう','てんきょう'], start => [938,6,22], end => [947,5,15] }, # 10年 from 938/6/22 until 947/5/15
199             { name => '天暦', period => '平安時代', reading => ['てんりゃく'], start => [947,5,15], end => [957,11,21] }, # 11年 from 947/5/15 until 957/11/21
200             { name => '天徳', period => '平安時代', reading => ['てんとく'], start => [957,11,21], end => [961,3,5] }, # 5年 from 957/11/21 until 961/3/5
201             { name => '応和', period => '平安時代', reading => ['おうわ'], start => [961,3,5], end => [964,8,19] }, # 4年 from 961/3/5 until 964/8/19
202             { name => '康保', period => '平安時代', reading => ['こうほう'], start => [964,8,19], end => [968,9,8] }, # 5年 from 964/8/19 until 968/9/8
203             { name => '安和', period => '平安時代', reading => ['あんな','あんわ'], start => [968,9,8], end => [970,5,3] }, # 3年 from 968/9/8 until 970/5/3
204             { name => '天禄', period => '平安時代', reading => ['てんろく'], start => [970,5,3], end => [974,1,16] }, # 4年 from 970/5/3 until 974/1/16
205             { name => '天延', period => '平安時代', reading => ['てんえん'], start => [974,1,16], end => [976,8,11] }, # 4年 from 974/1/16 until 976/8/11
206             { name => '貞元', period => '平安時代', reading => ['じょうげん'], start => [976,8,11], end => [978,12,31] }, # 3年 from 976/8/11 until 978/12/31
207             { name => '天元', period => '平安時代', reading => ['てんげん'], start => [978,12,31], end => [983,5,29] }, # 6年 from 978/12/31 until 983/5/29
208             { name => '永観', period => '平安時代', reading => ['えいかん'], start => [983,5,29], end => [985,5,19] }, # 3年 from 983/5/29 until 985/5/19
209             { name => '寛和', period => '平安時代', reading => ['かんな','かんわ'], start => [985,5,19], end => [987,5,5] }, # 3年 from 985/5/19 until 987/5/5
210             { name => '永延', period => '平安時代', reading => ['えいえん'], start => [987,5,5], end => [989,9,10] }, # 3年 from 987/5/5 until 989/9/10
211             { name => '永祚', period => '平安時代', reading => ['えいそ'], start => [989,9,10], end => [990,11,26] }, # 2年 from 989/9/10 until 990/11/26
212             { name => '正暦', period => '平安時代', reading => ['しょうりゃく'], start => [990,11,26], end => [995,3,25] }, # 6年 from 990/11/26 until 995/3/25
213             { name => '長徳', period => '平安時代', reading => ['ちょうとく'], start => [995,3,25], end => [999,2,1] }, # 5年 from 995/3/25 until 999/2/1
214             { name => '長保', period => '平安時代', reading => ['ちょうほう'], start => [999,2,1], end => [1004,8,8] }, # 6年 from 999/2/1 until 1004/8/8
215             { name => '寛弘', period => '平安時代', reading => ['かんこう'], start => [1004,8,8], end => [1013,2,8] }, # 9年 from 1004/8/8 until 1013/2/8
216             { name => '長和', period => '平安時代', reading => ['ちょうわ'], start => [1013,2,8], end => [1017,5,21] }, # 6年 from 1013/2/8 until 1017/5/21
217             { name => '寛仁', period => '平安時代', reading => ['かんにん'], start => [1017,5,21], end => [1021,3,17] }, # 5年 from 1017/5/21 until 1021/3/17
218             { name => '治安', period => '平安時代', reading => ['じあん'], start => [1021,3,17], end => [1024,8,19] }, # 4年 from 1021/3/17 until 1024/8/19
219             { name => '万寿', period => '平安時代', reading => ['まんじゅ'], start => [1024,8,19], end => [1028,8,18] }, # 5年 from 1024/8/19 until 1028/8/18
220             { name => '長元', period => '平安時代', reading => ['ちょうげん'], start => [1028,8,18], end => [1037,5,9] }, # 10年 from 1028/8/18 until 1037/5/9
221             { name => '長暦', period => '平安時代', reading => ['ちょうりゃく'], start => [1037,5,9], end => [1040,12,16] }, # 4年 from 1037/5/9 until 1040/12/16
222             { name => '長久', period => '平安時代', reading => ['ちょうきゅう'], start => [1040,12,16], end => [1044,12,16] }, # 5年 from 1040/12/16 until 1044/12/16
223             { name => '寛徳', period => '平安時代', reading => ['かんとく'], start => [1044,12,16], end => [1046,5,22] }, # 3年 from 1044/12/16 until 1046/5/22
224             { name => '永承', period => '平安時代', reading => ['えいしょう','えいじょう'], start => [1046,5,22], end => [1053,2,2] }, # 8年 from 1046/5/22 until 1053/2/2
225             { name => '天喜', period => '平安時代', reading => ['てんぎ','てんき'], start => [1053,2,2], end => [1058,9,19] }, # 6年 from 1053/2/2 until 1058/9/19
226             { name => '康平', period => '平安時代', reading => ['こうへい'], start => [1058,9,19], end => [1065,9,4] }, # 8年 from 1058/9/19 until 1065/9/4
227             { name => '治暦', period => '平安時代', reading => ['じりゃく'], start => [1065,9,4], end => [1069,5,6] }, # 5年 from 1065/9/4 until 1069/5/6
228             { name => '延久', period => '平安時代', reading => ['えんきゅう'], start => [1069,5,6], end => [1074,9,16] }, # 6年 from 1069/5/6 until 1074/9/16
229             { name => '承保', period => '平安時代', reading => ['じょうほう','しょうほう'], start => [1074,9,16], end => [1077,12,5] }, # 4年 from 1074/9/16 until 1077/12/5
230             { name => '承暦', period => '平安時代', reading => ['じょうりゃく','しょうりゃく'], start => [1077,12,5], end => [1081,3,22] }, # 5年 from 1077/12/5 until 1081/3/22
231             { name => '永保', period => '平安時代', reading => ['えいほう'], start => [1081,3,22], end => [1084,3,15] }, # 4年 from 1081/3/22 until 1084/3/15
232             { name => '応徳', period => '平安時代', reading => ['おうとく'], start => [1084,3,15], end => [1087,5,11] }, # 4年 from 1084/3/15 until 1087/5/11
233             { name => '寛治', period => '平安時代', reading => ['かんじ'], start => [1087,5,11], end => [1095,1,23] }, # 8年 from 1087/5/11 until 1095/1/23
234             { name => '嘉保', period => '平安時代', reading => ['かほう'], start => [1095,1,23], end => [1097,1,3] }, # 3年 from 1095/1/23 until 1097/1/3
235             { name => '永長', period => '平安時代', reading => ['えいちょう'], start => [1097,1,3], end => [1097,12,27] }, # 2年 from 1097/1/3 until 1097/12/27
236             { name => '承徳', period => '平安時代', reading => ['じょうとく','しょうとく'], start => [1097,12,27], end => [1099,9,15] }, # 3年 from 1097/12/27 until 1099/9/15
237             { name => '康和', period => '平安時代', reading => ['こうわ'], start => [1099,9,15], end => [1104,3,8] }, # 6年 from 1099/9/15 until 1104/3/8
238             { name => '長治', period => '平安時代', reading => ['ちょうじ'], start => [1104,3,8], end => [1106,5,13] }, # 3年 from 1104/3/8 until 1106/5/13
239             { name => '嘉承', period => '平安時代', reading => ['かしょう','かじょう'], start => [1106,5,13], end => [1108,9,9] }, # 3年 from 1106/5/13 until 1108/9/9
240             { name => '天仁', period => '平安時代', reading => ['てんにん'], start => [1108,9,9], end => [1110,7,31] }, # 3年 from 1108/9/9 until 1110/7/31
241             { name => '天永', period => '平安時代', reading => ['てんえい'], start => [1110,7,31], end => [1113,8,25] }, # 4年 from 1110/7/31 until 1113/8/25
242             { name => '永久', period => '平安時代', reading => ['えいきゅう'], start => [1113,8,25], end => [1118,4,25] }, # 6年 from 1113/8/25 until 1118/4/25
243             { name => '元永', period => '平安時代', reading => ['げんえい'], start => [1118,4,25], end => [1120,5,9] }, # 3年 from 1118/4/25 until 1120/5/9
244             { name => '保安', period => '平安時代', reading => ['ほうあん'], start => [1120,5,9], end => [1124,5,18] }, # 5年 from 1120/5/9 until 1124/5/18
245             { name => '天治', period => '平安時代', reading => ['てんじ'], start => [1124,5,18], end => [1126,2,15] }, # 3年 from 1124/5/18 until 1126/2/15
246             { name => '大治', period => '平安時代', reading => ['だいじ'], start => [1126,2,15], end => [1131,2,28] }, # 6年 from 1126/2/15 until 1131/2/28
247             { name => '天承', period => '平安時代', reading => ['てんしょう','てんじょう'], start => [1131,2,28], end => [1132,9,21] }, # 2年 from 1131/2/28 until 1132/9/21
248             { name => '長承', period => '平安時代', reading => ['ちょうしょう'], start => [1132,9,21], end => [1135,6,10] }, # 4年 from 1132/9/21 until 1135/6/10
249             { name => '保延', period => '平安時代', reading => ['ほうえん'], start => [1135,6,10], end => [1141,8,13] }, # 7年 from 1135/6/10 until 1141/8/13
250             { name => '永治', period => '平安時代', reading => ['えいじ'], start => [1141,8,13], end => [1142,5,25] }, # 2年 from 1141/8/13 until 1142/5/25
251             { name => '康治', period => '平安時代', reading => ['こうじ'], start => [1142,5,25], end => [1144,3,28] }, # 3年 from 1142/5/25 until 1144/3/28
252             { name => '天養', period => '平安時代', reading => ['てんよう'], start => [1144,3,28], end => [1145,8,12] }, # 2年 from 1144/3/28 until 1145/8/12
253             { name => '久安', period => '平安時代', reading => ['きゅうあん'], start => [1145,8,12], end => [1151,2,14] }, # 7年 from 1145/8/12 until 1151/2/14
254             { name => '仁平', period => '平安時代', reading => ['にんぺい','にんぴょう'], start => [1151,2,14], end => [1154,12,4] }, # 4年 from 1151/2/14 until 1154/12/4
255             { name => '久寿', period => '平安時代', reading => ['きゅうじゅ'], start => [1154,12,4], end => [1156,5,18] }, # 3年 from 1154/12/4 until 1156/5/18
256             { name => '保元', period => '平安時代', reading => ['ほうげん'], start => [1156,5,18], end => [1159,5,9] }, # 4年 from 1156/5/18 until 1159/5/9
257             { name => '平治', period => '平安時代', reading => ['へいじ'], start => [1159,5,9], end => [1160,2,18] }, # 2年 from 1159/5/9 until 1160/2/18
258             { name => '永暦', period => '平安時代', reading => ['えいりゃく'], start => [1160,2,18], end => [1161,9,24] }, # 2年 from 1160/2/18 until 1161/9/24
259             { name => '応保', period => '平安時代', reading => ['おうほう','おうほ'], start => [1161,9,24], end => [1163,5,4] }, # 3年 from 1161/9/24 until 1163/5/4
260             { name => '長寛', period => '平安時代', reading => ['ちょうかん'], start => [1163,5,4], end => [1165,7,14] }, # 3年 from 1163/5/4 until 1165/7/14
261             { name => '永万', period => '平安時代', reading => ['えいまん'], start => [1165,7,14], end => [1166,9,23] }, # 2年 from 1165/7/14 until 1166/9/23
262             { name => '仁安', period => '平安時代', reading => ['にんあん'], start => [1166,9,23], end => [1169,5,6] }, # 4年 from 1166/9/23 until 1169/5/6
263             { name => '嘉応', period => '平安時代', reading => ['かおう'], start => [1169,5,6], end => [1171,5,27] }, # 3年 from 1169/5/6 until 1171/5/27
264             { name => '承安', period => '平安時代', reading => ['じょうあん'], start => [1171,5,27], end => [1175,8,16] }, # 5年 from 1171/5/27 until 1175/8/16
265             { name => '安元', period => '平安時代', reading => ['あんげん'], start => [1175,8,16], end => [1177,8,29] }, # 3年 from 1175/8/16 until 1177/8/29
266             { name => '治承', period => '平安時代', reading => ['じしょう'], start => [1177,8,29], end => [1181,8,25] }, # 5年 from 1177/8/29 until 1181/8/25
267             { name => '養和', period => '平安時代', reading => ['ようわ'], start => [1181,8,25], end => [1182,6,29] }, # 2年 from 1181/8/25 until 1182/6/29
268             { name => '寿永', period => '平安時代', reading => ['じゅえい'], start => [1182,6,29], end => [1184,5,27] }, # 3年 from 1182/6/29 until 1184/5/27
269             { name => '元暦', period => '平安時代', reading => ['げんりゃく'], start => [1184,5,27], end => [1185,9,9] }, # 2年 from 1184/5/27 until 1185/9/9
270             { name => '文治', period => '鎌倉時代', reading => ['ぶんじ'], start => [1185,9,9], end => [1190,5,16] }, # 6年 from 1185/9/9 until 1190/5/16
271             { name => '建久', period => '鎌倉時代', reading => ['けんきゅう'], start => [1190,5,16], end => [1199,5,23] }, # 10年 from 1190/5/16 until 1199/5/23
272             { name => '正治', period => '鎌倉時代', reading => ['しょうじ'], start => [1199,5,23], end => [1201,3,19] }, # 3年 from 1199/5/23 until 1201/3/19
273             { name => '建仁', period => '鎌倉時代', reading => ['けんにん'], start => [1201,3,19], end => [1204,3,23] }, # 4年 from 1201/3/19 until 1204/3/23
274             { name => '元久', period => '鎌倉時代', reading => ['げんきゅう'], start => [1204,3,23], end => [1206,6,5] }, # 3年 from 1204/3/23 until 1206/6/5
275             { name => '建永', period => '鎌倉時代', reading => ['けんえい'], start => [1206,6,5], end => [1207,11,16] }, # 2年 from 1206/6/5 until 1207/11/16
276             { name => '承元', period => '鎌倉時代', reading => ['じょうげん'], start => [1207,11,16], end => [1211,4,23] }, # 5年 from 1207/11/16 until 1211/4/23
277             { name => '建暦', period => '鎌倉時代', reading => ['けんりゃく'], start => [1211,4,23], end => [1214,1,18] }, # 3年 from 1211/4/23 until 1214/1/18
278             { name => '建保', period => '鎌倉時代', reading => ['けんぽう'], start => [1214,1,18], end => [1219,5,27] }, # 7年 from 1214/1/18 until 1219/5/27
279             { name => '承久', period => '鎌倉時代', reading => ['じょうきゅう'], start => [1219,5,27], end => [1222,5,25] }, # 4年 from 1219/5/27 until 1222/5/25
280             { name => '貞応', period => '鎌倉時代', reading => ['じょうおう'], start => [1222,5,25], end => [1224,12,31] }, # 3年 from 1222/5/25 until 1224/12/31
281             { name => '元仁', period => '鎌倉時代', reading => ['げんにん'], start => [1224,12,31], end => [1225,5,28] }, # 2年 from 1224/12/31 until 1225/5/28
282             { name => '嘉禄', period => '鎌倉時代', reading => ['かろく'], start => [1225,5,28], end => [1228,1,18] }, # 3年 from 1225/5/28 until 1228/1/18
283             { name => '安貞', period => '鎌倉時代', reading => ['あんてい'], start => [1228,1,18], end => [1229,3,31] }, # 3年 from 1228/1/18 until 1229/3/31
284             { name => '寛喜', period => '鎌倉時代', reading => ['かんぎ'], start => [1229,3,31], end => [1232,4,23] }, # 4年 from 1229/3/31 until 1232/4/23
285             { name => '貞永', period => '鎌倉時代', reading => ['じょうえい'], start => [1232,4,23], end => [1233,5,25] }, # 2年 from 1232/4/23 until 1233/5/25
286             { name => '天福', period => '鎌倉時代', reading => ['てんぷく'], start => [1233,5,25], end => [1234,11,27] }, # 2年 from 1233/5/25 until 1234/11/27
287             { name => '文暦', period => '鎌倉時代', reading => ['ぶんりゃく'], start => [1234,11,27], end => [1235,11,1] }, # 2年 from 1234/11/27 until 1235/11/1
288             { name => '嘉禎', period => '鎌倉時代', reading => ['かてい'], start => [1235,11,1], end => [1238,12,30] }, # 4年 from 1235/11/1 until 1238/12/30
289             { name => '暦仁', period => '鎌倉時代', reading => ['りゃくにん'], start => [1238,12,30], end => [1239,3,13] }, # 2年 from 1238/12/30 until 1239/3/13
290             { name => '延応', period => '鎌倉時代', reading => ['えんおう'], start => [1239,3,13], end => [1240,8,5] }, # 2年 from 1239/3/13 until 1240/8/5
291             { name => '仁治', period => '鎌倉時代', reading => ['にんじ'], start => [1240,8,5], end => [1243,3,18] }, # 4年 from 1240/8/5 until 1243/3/18
292             { name => '寛元', period => '鎌倉時代', reading => ['かんげん'], start => [1243,3,18], end => [1247,4,5] }, # 5年 from 1243/3/18 until 1247/4/5
293             { name => '宝治', period => '鎌倉時代', reading => ['ほうじ'], start => [1247,4,5], end => [1249,5,2] }, # 3年 from 1247/4/5 until 1249/5/2
294             { name => '建長', period => '鎌倉時代', reading => ['けんちょう'], start => [1249,5,2], end => [1256,10,24] }, # 8年 from 1249/5/2 until 1256/10/24
295             { name => '康元', period => '鎌倉時代', reading => ['こうげん'], start => [1256,10,24], end => [1257,3,31] }, # 2年 from 1256/10/24 until 1257/3/31
296             { name => '正嘉', period => '鎌倉時代', reading => ['しょうか'], start => [1257,3,31], end => [1259,4,20] }, # 3年 from 1257/3/31 until 1259/4/20
297             { name => '正元', period => '鎌倉時代', reading => ['しょうげん'], start => [1259,4,20], end => [1260,5,24] }, # 2年 from 1259/4/20 until 1260/5/24
298             { name => '文応', period => '鎌倉時代', reading => ['ぶんおう'], start => [1260,5,24], end => [1261,3,22] }, # 2年 from 1260/5/24 until 1261/3/22
299             { name => '弘長', period => '鎌倉時代', reading => ['こうちょう'], start => [1261,3,22], end => [1264,3,27] }, # 4年 from 1261/3/22 until 1264/3/27
300             { name => '文永', period => '鎌倉時代', reading => ['ぶんえい'], start => [1264,3,27], end => [1275,5,22] }, # 12年 from 1264/3/27 until 1275/5/22
301             { name => '建治', period => '鎌倉時代', reading => ['けんじ'], start => [1275,5,22], end => [1278,3,23] }, # 4年 from 1275/5/22 until 1278/3/23
302             { name => '弘安', period => '鎌倉時代', reading => ['こうあん'], start => [1278,3,23], end => [1288,5,29] }, # 11年 from 1278/3/23 until 1288/5/29
303             { name => '正応', period => '鎌倉時代', reading => ['しょうおう'], start => [1288,5,29], end => [1293,9,6] }, # 6年 from 1288/5/29 until 1293/9/6
304             { name => '永仁', period => '鎌倉時代', reading => ['えいにん'], start => [1293,9,6], end => [1299,5,25] }, # 7年 from 1293/9/6 until 1299/5/25
305             { name => '正安', period => '鎌倉時代', reading => ['しょうあん'], start => [1299,5,25], end => [1302,12,10] }, # 4年 from 1299/5/25 until 1302/12/10
306             { name => '乾元', period => '鎌倉時代', reading => ['けんげん'], start => [1302,12,10], end => [1303,9,16] }, # 2年 from 1302/12/10 until 1303/9/16
307             { name => '嘉元', period => '鎌倉時代', reading => ['かげん'], start => [1303,9,16], end => [1307,1,18] }, # 4年 from 1303/9/16 until 1307/1/18
308             { name => '徳治', period => '鎌倉時代', reading => ['とくじ'], start => [1307,1,18], end => [1308,11,22] }, # 3年 from 1307/1/18 until 1308/11/22
309             { name => '延慶', period => '鎌倉時代', reading => ['えんきょう'], start => [1308,11,22], end => [1311,5,17] }, # 4年 from 1308/11/22 until 1311/5/17
310             { name => '応長', period => '鎌倉時代', reading => ['おうちょう'], start => [1311,5,17], end => [1312,4,27] }, # 2年 from 1311/5/17 until 1312/4/27
311             { name => '正和', period => '鎌倉時代', reading => ['しょうわ'], start => [1312,4,27], end => [1317,3,16] }, # 6年 from 1312/4/27 until 1317/3/16
312             { name => '文保', period => '鎌倉時代', reading => ['ぶんぽう'], start => [1317,3,16], end => [1319,5,18] }, # 3年 from 1317/3/16 until 1319/5/18
313             { name => '元応', period => '鎌倉時代', reading => ['げんおう'], start => [1319,5,18], end => [1321,3,22] }, # 3年 from 1319/5/18 until 1321/3/22
314             { name => '元亨', period => '鎌倉時代', reading => ['げんこう'], start => [1321,3,22], end => [1324,12,25] }, # 4年 from 1321/3/22 until 1324/12/25
315             { name => '正中', period => '鎌倉時代', reading => ['しょうちゅう'], start => [1324,12,25], end => [1326,5,28] }, # 3年 from 1324/12/25 until 1326/5/28
316             { name => '嘉暦', period => '鎌倉時代', reading => ['かりゃく'], start => [1326,5,28], end => [1329,9,22] }, # 4年 from 1326/5/28 until 1329/9/22
317             { name => '元徳', period => '鎌倉時代', reading => ['げんとく'], start => [1329,9,22], end => [1331,9,11] }, # 3年 from 1329/9/22 until 1331/9/11
318             { name => '元弘', period => '大覚寺統', reading => ['げんこう'], start => [1331,9,11], end => [1334,3,5] }, # 4年 from 1331/9/11 until 1334/3/5
319             { name => '正慶', period => '持明院統', reading => ['しょうけい','しょうきょう'], start => [1332,5,23], end => [1333,7,7] }, # 2年 from 1332/5/23 until 1333/7/7
320             { name => '建武', period => '南北朝時代・室町時代', reading => [''], start => [1334,3,5], end => [1338,10,11] }, # 3年 from 1334/3/5 until 1338/10/11
321             { name => '暦応', period => '北朝(持明院統)', reading => ['りゃくおう','れきおう'], start => [1338,10,11], end => [1342,6,1] }, # 5年 from 1338/10/11 until 1342/6/1
322             { name => '康永', period => '北朝(持明院統)', reading => ['こうえい'], start => [1342,6,1], end => [1345,11,15] }, # 4年 from 1342/6/1 until 1345/11/15
323             { name => '貞和', period => '北朝(持明院統)', reading => ['じょうわ','ていわ'], start => [1345,11,15], end => [1350,4,4] }, # 6年 from 1345/11/15 until 1350/4/4
324             { name => '観応', period => '北朝(持明院統)', reading => ['かんのう','かんおう'], start => [1350,4,4], end => [1352,11,4] }, # 3年 from 1350/4/4 until 1352/11/4
325             { name => '文和', period => '北朝(持明院統)', reading => ['ぶんな','ぶんわ'], start => [1352,11,4], end => [1356,4,29] }, # 5年 from 1352/11/4 until 1356/4/29
326             { name => '延文', period => '北朝(持明院統)', reading => ['えんぶん'], start => [1356,4,29], end => [1361,5,4] }, # 6年 from 1356/4/29 until 1361/5/4
327             { name => '康安', period => '北朝(持明院統)', reading => ['こうあん'], start => [1361,5,4], end => [1362,10,11] }, # 2年 from 1361/5/4 until 1362/10/11
328             { name => '貞治', period => '北朝(持明院統)', reading => ['じょうじ','ていじ'], start => [1362,10,11], end => [1368,3,7] }, # 7年 from 1362/10/11 until 1368/3/7
329             { name => '応安', period => '北朝(持明院統)', reading => ['おうあん'], start => [1368,3,7], end => [1375,3,29] }, # 8年 from 1368/3/7 until 1375/3/29
330             { name => '永和', period => '北朝(持明院統)', reading => ['えいわ'], start => [1375,3,29], end => [1379,4,9] }, # 5年 from 1375/3/29 until 1379/4/9
331             { name => '康暦', period => '北朝(持明院統)', reading => ['こうりゃく'], start => [1379,4,9], end => [1381,3,20] }, # 3年 from 1379/4/9 until 1381/3/20
332             { name => '永徳', period => '北朝(持明院統)', reading => ['えいとく'], start => [1381,3,20], end => [1384,3,19] }, # 4年 from 1381/3/20 until 1384/3/19
333             { name => '至徳', period => '北朝(持明院統)', reading => ['しとく'], start => [1384,3,19], end => [1387,10,5] }, # 4年 from 1384/3/19 until 1387/10/5
334             { name => '嘉慶', period => '北朝(持明院統)', reading => ['かけい','かきょう'], start => [1387,10,5], end => [1389,3,7] }, # 3年 from 1387/10/5 until 1389/3/7
335             { name => '康応', period => '北朝(持明院統)', reading => ['こうおう'], start => [1389,3,7], end => [1390,4,12] }, # 2年 from 1389/3/7 until 1390/4/12
336             { name => '明徳', period => '北朝(持明院統)', reading => ['めいとく'], start => [1390,4,12], end => [1394,8,2] }, # 5年 from 1390/4/12 until 1394/8/2
337             { name => '応永', period => '南北朝合一後', reading => ['おうえい'], start => [1394,8,2], end => [1428,6,10] }, # 35年 from 1394/8/2 until 1428/6/10
338             { name => '正長', period => '南北朝合一後', reading => ['しょうちょう'], start => [1428,6,10], end => [1429,10,3] }, # 2年 from 1428/6/10 until 1429/10/3
339             { name => '永享', period => '南北朝合一後', reading => ['えいきょう'], start => [1429,10,3], end => [1441,3,10] }, # 13年 from 1429/10/3 until 1441/3/10
340             { name => '嘉吉', period => '南北朝合一後', reading => ['かきつ'], start => [1441,3,10], end => [1444,2,23] }, # 4年 from 1441/3/10 until 1444/2/23
341             { name => '文安', period => '南北朝合一後', reading => ['ぶんあん'], start => [1444,2,23], end => [1449,8,16] }, # 6年 from 1444/2/23 until 1449/8/16
342             { name => '宝徳', period => '南北朝合一後', reading => ['ほうとく'], start => [1449,8,16], end => [1452,8,10] }, # 4年 from 1449/8/16 until 1452/8/10
343             { name => '享徳', period => '南北朝合一後', reading => ['きょうとく'], start => [1452,8,10], end => [1455,9,6] }, # 4年 from 1452/8/10 until 1455/9/6
344             { name => '康正', period => '南北朝合一後', reading => ['こうしょう'], start => [1455,9,6], end => [1457,10,16] }, # 3年 from 1455/9/6 until 1457/10/16
345             { name => '長禄', period => '南北朝合一後', reading => ['ちょうろく'], start => [1457,10,16], end => [1461,2,1] }, # 4年 from 1457/10/16 until 1461/2/1
346             { name => '寛正', period => '南北朝合一後', reading => ['かんしょう'], start => [1461,2,1], end => [1466,3,14] }, # 7年 from 1461/2/1 until 1466/3/14
347             { name => '文正', period => '南北朝合一後', reading => ['ぶんしょう'], start => [1466,3,14], end => [1467,4,9] }, # 2年 from 1466/3/14 until 1467/4/9
348             { name => '応仁', period => '戦国時代', reading => ['おうにん'], start => [1467,4,9], end => [1469,6,8] }, # 3年 from 1467/4/9 until 1469/6/8
349             { name => '文明', period => '戦国時代', reading => ['ぶんめい'], start => [1469,6,8], end => [1487,8,9] }, # 19年 from 1469/6/8 until 1487/8/9
350             { name => '長享', period => '戦国時代', reading => ['ちょうきょう'], start => [1487,8,9], end => [1489,9,16] }, # 3年 from 1487/8/9 until 1489/9/16
351             { name => '延徳', period => '戦国時代', reading => ['えんとく'], start => [1489,9,16], end => [1492,8,12] }, # 4年 from 1489/9/16 until 1492/8/12
352             { name => '明応', period => '戦国時代', reading => ['めいおう'], start => [1492,8,12], end => [1501,3,18] }, # 10年 from 1492/8/12 until 1501/3/18
353             { name => '文亀', period => '戦国時代', reading => ['ぶんき'], start => [1501,3,18], end => [1504,3,16] }, # 4年 from 1501/3/18 until 1504/3/16
354             { name => '永正', period => '戦国時代', reading => ['えいしょう'], start => [1504,3,16], end => [1521,9,23] }, # 18年 from 1504/3/16 until 1521/9/23
355             { name => '大永', period => '戦国時代', reading => ['たいえい'], start => [1521,9,23], end => [1528,9,3] }, # 8年 from 1521/9/23 until 1528/9/3
356             { name => '享禄', period => '戦国時代', reading => ['きょうろく'], start => [1528,9,3], end => [1532,8,29] }, # 5年 from 1528/9/3 until 1532/8/29
357             { name => '天文', period => '戦国時代', reading => ['てんぶん'], start => [1532,8,29], end => [1555,11,7] }, # 24年 from 1532/8/29 until 1555/11/7
358             { name => '弘治', period => '戦国時代', reading => ['こうじ'], start => [1555,11,7], end => [1558,3,18] }, # 4年 from 1555/11/7 until 1558/3/18
359             { name => '永禄', period => '戦国時代', reading => ['えいろく'], start => [1558,3,18], end => [1570,5,27] }, # 13年 from 1558/3/18 until 1570/5/27
360             { name => '元亀', period => '戦国時代', reading => ['げんき'], start => [1570,5,27], end => [1573,8,25] }, # 4年 from 1570/5/27 until 1573/8/25
361             { name => '天正', period => '安土桃山時代', reading => ['てんしょう'], start => [1573,8,25], end => [1593,1,10] }, # 20年 from 1573/8/25 until 1593/1/10
362             { name => '文禄', period => '安土桃山時代', reading => ['ぶんろく'], start => [1593,1,10], end => [1596,12,16] }, # 5年 from 1593/1/10 until 1596/12/16
363             { name => '慶長', period => '安土桃山時代', reading => ['けいちょう'], start => [1596,12,16], end => [1615,9,5] }, # 20年 from 1596/12/16 until 1615/9/5
364             { name => '元和', period => '江戸時代', reading => ['げんな'], start => [1615,9,5], end => [1624,4,17] }, # 10年 from 1615/9/5 until 1624/4/17
365             { name => '寛永', period => '江戸時代', reading => ['かんえい'], start => [1624,4,17], end => [1645,1,13] }, # 21年 from 1624/4/17 until 1645/1/13
366             { name => '正保', period => '江戸時代', reading => ['しょうほう'], start => [1645,1,13], end => [1648,4,7] }, # 5年 from 1645/1/13 until 1648/4/7
367             { name => '慶安', period => '江戸時代', reading => ['けいあん'], start => [1648,4,7], end => [1652,10,20] }, # 5年 from 1648/4/7 until 1652/10/20
368             { name => '承応', period => '江戸時代', reading => ['じょうおう'], start => [1652,10,20], end => [1655,5,18] }, # 4年 from 1652/10/20 until 1655/5/18
369             { name => '明暦', period => '江戸時代', reading => ['めいれき'], start => [1655,5,18], end => [1658,8,21] }, # 4年 from 1655/5/18 until 1658/8/21
370             { name => '万治', period => '江戸時代', reading => ['まんじ'], start => [1658,8,21], end => [1661,5,23] }, # 4年 from 1658/8/21 until 1661/5/23
371             { name => '寛文', period => '江戸時代', reading => ['かんぶん'], start => [1661,5,23], end => [1673,10,30] }, # 13年 from 1661/5/23 until 1673/10/30
372             { name => '延宝', period => '江戸時代', reading => ['えんぽう'], start => [1673,10,30], end => [1681,11,9] }, # 9年 from 1673/10/30 until 1681/11/9
373             { name => '天和', period => '江戸時代', reading => ['てんな'], start => [1681,11,9], end => [1684,4,5] }, # 4年 from 1681/11/9 until 1684/4/5
374             { name => '貞享', period => '江戸時代', reading => ['じょうきょう'], start => [1684,4,5], end => [1688,10,23] }, # 5年 from 1684/4/5 until 1688/10/23
375             { name => '元禄', period => '江戸時代', reading => ['げんろく'], start => [1688,10,23], end => [1704,4,16] }, # 17年 from 1688/10/23 until 1704/4/16
376             { name => '宝永', period => '江戸時代', reading => ['ほうえい'], start => [1704,4,16], end => [1711,6,11] }, # 8年 from 1704/4/16 until 1711/6/11
377             { name => '正徳', period => '江戸時代', reading => ['しょうとく'], start => [1711,6,11], end => [1716,8,9] }, # 6年 from 1711/6/11 until 1716/8/9
378             { name => '享保', period => '江戸時代', reading => ['きょうほう'], start => [1716,8,9], end => [1736,6,7] }, # 21年 from 1716/8/9 until 1736/6/7
379             { name => '元文', period => '江戸時代', reading => ['げんぶん'], start => [1736,6,7], end => [1741,4,12] }, # 6年 from 1736/6/7 until 1741/4/12
380             { name => '寛保', period => '江戸時代', reading => ['かんぽう'], start => [1741,4,12], end => [1744,4,3] }, # 4年 from 1741/4/12 until 1744/4/3
381             { name => '延享', period => '江戸時代', reading => ['えんきょう'], start => [1744,4,3], end => [1748,8,5] }, # 5年 from 1744/4/3 until 1748/8/5
382             { name => '寛延', period => '江戸時代', reading => ['かんえん'], start => [1748,8,5], end => [1751,12,14] }, # 4年 from 1748/8/5 until 1751/12/14
383             { name => '宝暦', period => '江戸時代', reading => ['ほうれき'], start => [1751,12,14], end => [1764,6,30] }, # 14年 from 1751/12/14 until 1764/6/30
384             { name => '明和', period => '江戸時代', reading => ['めいわ'], start => [1764,6,30], end => [1772,12,10] }, # 9年 from 1764/6/30 until 1772/12/10
385             { name => '安永', period => '江戸時代', reading => ['あんえい'], start => [1772,12,10], end => [1781,4,25] }, # 10年 from 1772/12/10 until 1781/4/25
386             { name => '天明', period => '江戸時代', reading => ['てんめい'], start => [1781,4,25], end => [1789,2,19] }, # 9年 from 1781/4/25 until 1789/2/19
387             { name => '寛政', period => '江戸時代', reading => ['かんせい'], start => [1789,2,19], end => [1801,3,19] }, # 13年 from 1789/2/19 until 1801/3/19
388             { name => '享和', period => '江戸時代', reading => ['きょうわ'], start => [1801,3,19], end => [1804,3,22] }, # 4年 from 1801/3/19 until 1804/3/22
389             { name => '文化', period => '江戸時代', reading => ['ぶんか'], start => [1804,3,22], end => [1818,5,26] }, # 15年 from 1804/3/22 until 1818/5/26
390             { name => '文政', period => '江戸時代', reading => ['ぶんせい'], start => [1818,5,26], end => [1831,1,23] }, # 13年 from 1818/5/26 until 1831/1/23
391             { name => '天保', period => '江戸時代', reading => ['てんぽう'], start => [1831,1,23], end => [1845,1,9] }, # 15年 from 1831/1/23 until 1845/1/9
392             { name => '弘化', period => '江戸時代', reading => ['こうか'], start => [1845,1,9], end => [1848,4,1] }, # 5年 from 1845/1/9 until 1848/4/1
393             { name => '嘉永', period => '江戸時代', reading => ['かえい'], start => [1848,4,1], end => [1855,1,15] }, # 7年 from 1848/4/1 until 1855/1/15
394             { name => '安政', period => '江戸時代', reading => ['あんせい'], start => [1855,1,15], end => [1860,4,8] }, # 7年 from 1855/1/15 until 1860/4/8
395             { name => '万延', period => '江戸時代', reading => ['まんえん'], start => [1860,4,8], end => [1861,3,29] }, # 2年 from 1860/4/8 until 1861/3/29
396             { name => '文久', period => '江戸時代', reading => ['ぶんきゅう'], start => [1861,3,29], end => [1864,3,27] }, # 4年 from 1861/3/29 until 1864/3/27
397             { name => '元治', period => '江戸時代', reading => ['げんじ'], start => [1864,3,27], end => [1865,5,1] }, # 2年 from 1864/3/27 until 1865/5/1
398             { name => '慶応', period => '江戸時代', reading => ['けいおう'], start => [1865,5,1], end => [1868,10,23] }, # 4年 from 1865/5/1 until 1868/10/23
399             { name => '明治', period => '明治以降', reading => ['めいじ'], start => [1868,10,23], end => [1912,7,30] }, # 45年 from 1868/10/23 until 1912/7/30
400             { name => '大正', period => '登極令下', reading => ['たいしょう'], start => [1912,7,30], end => [1926,12,25] }, # 15年 from 1912/7/30 until 1926/12/25
401             { name => '昭和', period => '登極令下', reading => ['しょうわ'], start => [1926,12,25], end => [1989,1,7] }, # 64年 from 1926/12/25 until 1989/1/7
402             { name => '平成', period => '元号法下', reading => ['へいせい'], start => [1989,1,8], end => [2019,4,30] }, # 31年 from 1989/1/8 until 2019/4/30
403             { name => '令和', period => '元号法下', reading => ['れいわ'], start => [2019,5,1], end => [] }, # from 2019/5/1 until
404             ];
405             };
406              
407             sub new
408             {
409 85     85 1 83782 my $this = shift( @_ );
410 85 50       262 return( $this->error( "Incorrect parameters provided. You need to provide an hash of values." ) ) if( @_ % 2 );
411 85         230 my $p = { @_ };
412             # kanji_number
413             # pattern
414             # time_zone
415             # traditional
416             # zenkaku / hankaku
417 85 50 33     237 if( exists( $p->{hankaku} ) && !exists( $p->{zenkaku} ) )
418             {
419 0         0 $p->{zenkaku} = !$p->{hankaku};
420             }
421 85   33     387 return( bless( $p => ( ref( $this ) || $this ) ) );
422             }
423              
424             sub error
425             {
426 0     0 1 0 my $self = shift( @_ );
427 0 0       0 if( @_ )
428             {
429 0 0       0 $self->{error} = $ERROR = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
430 0 0       0 warnings::warn( $ERROR, "\n" ) if( warnings::enabled() );
431 0         0 return;
432             }
433 0 0       0 return( ref( $self ) ? $self->{error} : $ERROR );
434             }
435              
436             sub format_datetime
437             {
438 83     83 1 374 my $self = shift( @_ );
439 83         109 my $dt = shift( @_ );
440 83         468 require overload;
441 83 50 33     583 return( $self->error( "Value provided (", overload::StrVal( $dt ), ") is not a DateTime object or one inheriting from it." ) ) if( !ref( $dt ) || ( ref( $dt ) && !$dt->isa( 'DateTime' ) ) );
      33        
442 83 50       240 my $pat = length( $self->{pattern} ) ? $self->{pattern} : '%c';
443 2     2   6208 use utf8;
  2         4  
  2         8  
444            
445             local $japanised_value_for = sub
446             {
447 48     48   98 my $method_name = shift( @_ );
448 48         68 my $opts = {};
449 48 100       124 $opts = shift( @_ ) if( ref( $_[0] ) eq 'HASH' );
450 48 100       120 $opts->{simple_kanji} = 0 if( !exists( $opts->{simple_kanji} ) );
451 48         191 my $ref = $dt->can( $method_name );
452 48         142 my $n = $ref->( $dt );
453 48 100       329 if( $self->{zenkaku} )
    100          
454             {
455 20         41 $n = $self->romaji_to_zenkaku( $n );
456             }
457             elsif( $self->{kanji_number} )
458             {
459 8 100       16 if( $opts->{simple_kanji} )
460             {
461 1         4 $n = $self->romaji_to_kanji_simple( $n );
462             }
463             else
464             {
465 7         16 $n = $self->romaji_to_kanji( $n );
466             }
467             }
468 48         281 return( $n );
469 83         431 };
470             local $japanised_strftime = sub
471             {
472 9     9   14 my $token = shift( @_ );
473 9         14 my $opts = {};
474 9 100       25 $opts = shift( @_ ) if( ref( $_[0] ) eq 'HASH' );
475 9 100       26 $opts->{simple_kanji} = 0 if( !exists( $opts->{simple_kanji} ) );
476 9         35 my $n = $dt->strftime( $token );
477 2     2   393 no warnings 'DateTime::Format::JP';
  2         3  
  2         4068  
478 9 100       882 if( $self->{zenkaku} )
    100          
479             {
480 4         12 $n = $self->romaji_to_zenkaku( $n );
481             }
482             elsif( $self->{kanji_number} )
483             {
484 1 50       5 if( $opts->{simple_kanji} )
485             {
486 1         11 $n = $self->romaji_to_kanji_simple( $n );
487             }
488             else
489             {
490 0         0 $n = $self->romaji_to_kanji( $n );
491             }
492             }
493 9         26 return( $n );
494 83         326 };
495            
496             my $map =
497             {
498 0 0 0 0   0 '%' => sub{ return( ( $self->{traditional} || $self->{zenkaku} || $self->{kanji_number} ) ? '%' : '%' ); },
499             # weekday name in abbreviated form
500             'a' => sub
501             {
502 1     1   5 my $n = $dt->day_of_week - 1;
503 1         8 return( $WEEKDAYS->[ $n ] );
504             },
505             # weekday name in its long form
506             'A' => sub
507             {
508 1     1   4 my $n = $dt->day_of_week - 1;
509 1         8 return( $WEEKDAYS->[ $n ] . '曜日' );
510             },
511             # month name
512 1     1   9 'b' => sub{ return( sprintf( '%d月', $dt->month ) ); },
513             # month name using full width (全角) digits
514 1     1   5 'B' => sub{ return( sprintf( '%s月', $self->romaji_to_zenkaku( $dt->month ) ) ); },
515             # month name using kanjis for numbers
516 1     1   4 'h' => sub{ return( sprintf( '%s月', $self->romaji_to_kanji( $dt->month ) ) ); },
517             # datetime format in the standard most usual form
518             # 令和3年7月12日午後2:17:30
519             # 令和3年7月12日午後2時17分30秒
520             # 令和3年7月12日午後2時17分30秒
521             # 令和3年七月十二日午後二時十七分三十秒
522             'c' => sub
523             {
524 5   50 5   17 my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
525 5         25 my $def =
526             {
527             year => $era->year( $dt ),
528             month => $dt->month,
529             day => $dt->day,
530             hour => $dt->hour_12,
531             minute => $dt->minute,
532             second => $dt->second,
533             };
534 5         177 foreach( keys( %$def ) )
535             {
536 30 100       61 if( $self->{zenkaku} )
    100          
537             {
538 12         22 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
539             }
540             elsif( $self->{kanji_number} )
541             {
542 6         14 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
543             }
544             }
545 5 100 100     23 if( $self->{traditional} || $self->{kanji_number} )
546             {
547 3         6 $def->{suff_hour} = '時';
548 3         8 $def->{suff_minute} = '分';
549 3         20 $def->{suff_second} = '秒';
550 3 50       8 return( sprintf( '%s%s年%s月%s日%s%s%s%s%s%s%s', $era->name, @$def{qw( year month day )}, ( $dt->hour > 12 ? '午後' : '午前' ), @$def{qw( hour suff_hour minute suff_minute second suff_second )} ) );
551             }
552             else
553             {
554 2 100       40 $def->{sep} = $self->{zenkaku} ? ':' : ':';
555 2 50       8 return( sprintf( '%s%s年%s月%s日%s%s%s%s%s%s', $era->name, @$def{qw( year month day )}, ( $dt->hour > 12 ? '午後' : '午前' ), @$def{qw( hour sep minute sep second )} ) );
556             }
557             },
558             # century number (0-99)
559 1     1   10 'C' => sub{ return( $dt->strftime( '%C' ) ); },
560             # day of month
561 6     6   13 'd' => sub{ return( $japanised_value_for->( 'day' ) ); },
562             # Japanese style date including with the leading era name
563             'D' => sub
564             {
565 3   50 3   9 my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
566 3         8 my $def =
567             {
568             year => $era->year( $dt ),
569             month => $dt->month,
570             day => $dt->day,
571             };
572 3         52 foreach( keys( %$def ) )
573             {
574 9 100       22 if( $self->{zenkaku} )
    100          
575             {
576 3         8 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
577             }
578             elsif( $self->{kanji_number} )
579             {
580 3         6 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
581             }
582             }
583 3         8 return( sprintf( '%s%s年%s月%s日', $era->name, @$def{qw( year month day )} ) );
584             },
585             # Japanese era name
586             'E' => sub
587             {
588 1   50 1   4 my $e = $self->lookup_era_by_date( $dt ) || return;
589 1         4 return( $e->name );
590             },
591             # Equivalent to "%Y年%m月%d日"
592             'F' => sub
593             {
594 3     3   12 my $def =
595             {
596             year => $dt->year,
597             month => $dt->month,
598             day => $dt->day,
599             };
600 3         44 foreach( qw( month day ) )
601             {
602 6 100       19 if( $self->{zenkaku} )
    100          
603             {
604 2         6 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
605             }
606             elsif( $self->{kanji_number} )
607             {
608 2         6 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
609             }
610             }
611            
612 3 100       8 if( $self->{zenkaku} )
    100          
613             {
614 1         5 $def->{year} = $self->romaji_to_zenkaku( $def->{year} );
615             }
616             elsif( $self->{kanji_number} )
617             {
618 1         5 $def->{year} = $self->romaji_to_kanji_simple( $def->{year} );
619             }
620            
621 3         25 return( sprintf( '%s年%s月%s日', @$def{qw( year month day )} ) );
622             },
623             # year without century
624 1     1   5 'g' => sub{ return( $dt->strftime( '%g' ) ); },
625             # week number 4-digit year
626 1     1   4 'G' => sub{ return( $dt->strftime( '%G' ) ); },,
627             # hour
628 5 100 100 5   9 'H' => sub{ return( $japanised_value_for->( 'hour' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '時' : '' ) ); },
629             # hour with clock of 12
630 3     3   6 'I' => sub{ return( $japanised_value_for->( 'hour_12' ) ); },
631             # day number in the year
632 1     1   4 'j' => sub{ return( $dt->strftime( '%j' ) ); },
633             # month number
634 3     3   7 'm' => sub{ return( $japanised_value_for->( 'month' ) ); },
635             # minute
636 5 100 100 5   11 'M' => sub{ return( $japanised_value_for->( 'minute' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '分' : '' ) ); },
637             # space
638 0     0   0 'n' => sub{ return( $dt->strftime( '%n' ) ); },
639             # AM/PM
640 2 50   2   7 'p' => sub{ return( $dt->hour > 12 ? '午後' : '午前' ); },
641             # Equivalent to "%p%I:%M:%S"
642 2 50   2   8 'r' => sub{ return( sprintf( '%s%s%s%s%s%s', ( $dt->hour > 12 ? '午後' : '午前' ), $japanised_value_for->( 'hour_12' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'minute' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'second' ) ) ); },
    100          
    100          
643             # Equivalent to "%H:%M"
644 2 100   2   5 'R' => sub{ return( sprintf( '%s%s%s', $japanised_value_for->( 'hour' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'minute' ) ) ); },
645             # seconds since the Epoch
646 2 100   2   11 's' => sub{ return( $self->{zenkaku} ? $self->romaji_to_zenkaku( $dt->strftime( '%s' ) ) : $dt->strftime( '%s' ) ); },
647             # seconds
648 5 100 100 5   12 'S' => sub{ return( $japanised_value_for->( 'second' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '秒' : '' ) ); },
649             # space
650 0     0   0 't' => sub{ return( $dt->strftime( '%t' ) ); },
651             # Equivalent to "%H:%M:%S"
652 2 100   2   8 'T' => sub{ return( sprintf( '%s%s%s%s%s', $japanised_value_for->( 'hour' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'minute' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'second' ) ) ); },
    100          
653             # week number with Sunday first
654 2     2   4 'U' => sub{ return( $japanised_strftime->( '%U' ) ); },
655             # weekday number 1-7
656 2     2   5 'u' => sub{ return( $japanised_value_for->( 'day_of_week' ) ); },
657             # weekday number 0-7 with Sunday first
658 2     2   6 'w' => sub{ return( $japanised_strftime->( '%w' ) ); },
659             # week number with Monday first
660 2     2   5 'W' => sub{ return( $japanised_strftime->( '%W' ) ); },
661             # date format in the standard most usual form
662             # 令和3年7月12日
663             # 令和3年7月12日
664             # 令和3年七月十二日
665             'x' => sub
666             {
667 3   50 3   10 my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
668 3         9 my $def =
669             {
670             year => $era->year( $dt ),
671             month => $dt->month,
672             day => $dt->day,
673             };
674 3         57 foreach( keys( %$def ) )
675             {
676 9 100       23 if( $self->{zenkaku} )
    100          
677             {
678 3         6 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
679             }
680             elsif( $self->{kanji_number} )
681             {
682 3         17 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
683             }
684             }
685 3         10 return( sprintf( '%s%s年%s月%s日', $era->name, @$def{qw( year month day )} ) );
686             },
687             # time format in the standard most usual form
688             # 午後2:17:30
689             # 午後2時17分30秒
690             # 午後二時十七分三十秒
691             'X' => sub
692             {
693 4     4   16 my $def =
694             {
695             hour => $dt->hour_12,
696             minute => $dt->minute,
697             second => $dt->second,
698             };
699 4 50       77 $def->{ampm} = $dt->hour > 12 ? '午後' : '午前';
700 4         27 $def->{sep1} = $def->{sep2} = ':';
701 4 100 100     23 if( $self->{traditional} || $self->{kanji_number} )
    100          
702             {
703 2         4 $def->{suff_hour} = '時';
704 2         5 $def->{suff_minute} = '分';
705 2         4 $def->{suff_second} = '秒';
706 2         5 delete( @$def{qw( sep1 sep2 )} );
707             }
708             elsif( $self->{zenkaku} )
709             {
710 1         2 $def->{sep1} = $def->{sep2} = ':';
711             }
712            
713 4         9 foreach( qw( hour minute second ) )
714             {
715 12 100       27 if( $self->{zenkaku} )
    100          
716             {
717 3         6 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
718             }
719             elsif( $self->{kanji_number} )
720             {
721 3         6 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
722             }
723             }
724            
725 4 100 100     15 if( $self->{traditional} || $self->{kanji_number} )
726             {
727 2         19 return( sprintf( '%s%s%s%s%s%s%s', @$def{qw( ampm hour suff_hour minute suff_minute second suff_second )} ) );
728             }
729             else
730             {
731 2         34 return( sprintf( '%s%s%s%s%s%s', @$def{qw( ampm hour sep1 minute sep2 second )} ) );
732             }
733             },
734             # year of the era, relative to the start of the era
735             'y' => sub
736             {
737 3   50 3   9 my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
738 3         9 my $y = $era->year( $dt );
739 3 100       27 if( $self->{zenkaku} )
    100          
740             {
741 1         4 $y = $self->romaji_to_zenkaku( $y );
742             }
743             elsif( $self->{kanji_number} )
744             {
745 1         4 $y = $self->romaji_to_kanji( $y );
746             }
747 3         12 return( $y );
748             },
749             # 4-digit year
750 3     3   10 'Y' => sub{ return( $japanised_value_for->( 'year', { simple_kanji => 1 }) ); },
751             # standard time zone specification, such as +0900
752             'z' => sub
753             {
754 3     3   10 my $rv = $japanised_strftime->( '%z', { simple_kanji => 1 });
755 3 100 66     18 if( $self->{zenkaku} || $self->{traditional} || $self->{kanji_number} )
      66        
756             {
757 2 50       12 if( substr( $rv, 0, 1 ) eq '+' )
    0          
758             {
759 2         7 substr( $rv, 0, 1, '+' );
760             }
761             elsif( substr( $rv, 0, 1 ) eq '-' )
762             {
763 0         0 substr( $rv, 0, 1, 'ー' );
764             }
765             }
766 3         9 return( $rv );
767             },
768             # timezone name
769 1     1   5 'Z' => sub{ return( $dt->strftime( '%Z' ) ); },
770 83         4400 };
771             # Aliases
772 83         262 $map->{e} = $map->{d};
773 83         126 $map->{P} = $map->{p};
774 83         550 $pat =~ s
775             {
776             \%([\%aAbBhcCdeDEFgGHIjmMnNpPrRRsStTUuwWxXyYzZ])
777             }
778 83         221 {
779 83 50       184 my $token = $1;
780 83         164 die( "Missing definition for '$token'\n" ) if( !exists( $map->{ $token } ) );
781             $map->{ $token }->();
782             }gexs;
783 83 50       720
784             if( index( $pat, '%' ) != -1 )
785 0         0 {
786             $pat = $dt->strftime( $pat );
787 83         5731 }
788             return( $pat );
789             }
790 0     0 1 0  
791             sub hankaku { return( shift->_set_get_zenkaku( 'hankaku', @_ ) ); }
792 0     0 1 0  
793             sub kanji_number { return( shift->_set_get( 'kanji_number', @_ ) ); }
794              
795             sub kanji_to_romaji
796 116     116 1 136 {
797 116         130 my $self = shift( @_ );
798 116 50 33     340 my $num = shift( @_ );
799 2     2   15 return( $self->error( "No value provided to transcode from kanji number to roman numerals." ) ) if( !defined( $num ) || !length( $num ) );
  2         4  
  2         8  
800 116         136 use utf8;
801 116 100       306 my $rv = 0;
802             if( $num =~ s/^[[:blank:]\h]*([〇一二三四五六七八九])千// )
803 10         24 {
804 10         16 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
805             $rv = $n * 1000;
806 116 50 33     312 }
807             if( length( $num ) && $num =~ s/^([〇一二三四五六七八九])百// )
808 0         0 {
809 0         0 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
810             $rv += ( $n * 100 );
811 116 100 66     362 }
812             if( length( $num ) && $num =~ s/^([〇一二三四五六七八九])十// )
813 15         32 {
814 15         24 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
815             $rv += ( $n * 10 );
816 116 100       167 }
817             if( length( $num ) )
818 101         148 {
819 101         117 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $num );
820             $rv += $n;
821 116         240 }
822 116         184 $self->message( 3, "Returning '$rv'." );
823             return( $rv );
824             }
825              
826             sub lookup_era
827 44     44 1 69 {
828 44   50     128 my $self = shift( @_ );
829             my $name = shift( @_ ) ||
830 44         108 return( $self->error( "No era name was provided to lookup." ) );
831             foreach my $ref ( @$DICT )
832 10648 100       16191 {
833             if( $ref->{name} eq $name )
834 44         359 {
835             return( DateTime::Format::JP::Era->new( $ref ) );
836             }
837             }
838 0         0 # Nothing found
839             return;
840             }
841              
842             sub lookup_era_by_date
843 15     15 1 24 {
844 15         18 my $self = shift( @_ );
845 15         65 my $dt = shift( @_ );
846 15 50 33     110 require overload;
      33        
847 15         56 return( $self->error( "Value provided (", overload::StrVal( $dt ), ") is not a DateTime object or one inheriting from it." ) ) if( !ref( $dt ) || ( ref( $dt ) && !$dt->isa( 'DateTime' ) ) );
848 15         295 my( $y, $m, $d ) = unpack( 'A4A2A2', $dt->ymd( '' ) );
849 15         40 my $era;
850             foreach my $def ( @$DICT )
851             {
852 3630 100 66     3271 # No need to bother if the current entry has an end and it is lower than our current year
  3630         9448  
853 15 50 50     20 next if( scalar( @{$def->{end}} ) && $y > $def->{end}->[0] );
  15 50 33     34  
      33        
      0        
      0        
      0        
      0        
      33        
      33        
      33        
      33        
854 15         62 if( scalar( @{$def->{start}} ) &&
855             scalar( @{$def->{end}} ) &&
856             $y >= $def->{start}->[0] &&
857             $y <= $def->{end}->[0] &&
858             $m >= $def->{start}->[1] &&
859             $m <= $def->{end}->[1] &&
860             $d >= $def->{start}->[2] &&
861             $d < $def->{end}->[2] )
862 0         0 {
863 0         0 $era = DateTime::Format::JP::Era->new( $def );
864             last;
865             }
866 15         31 # Obviously the current era, i.e. it has no end date
867 15         111 elsif( scalar( @{$def->{start}} ) &&
868             !scalar( @{$def->{end}} ) &&
869             $y >= $def->{start}->[0] &&
870             $m >= $def->{start}->[1] &&
871             $d >= $def->{start}->[2] )
872 15         57 {
873 15         32 $era = DateTime::Format::JP::Era->new( $def );
874             last;
875             }
876 15         57 }
877             return( $era );
878             }
879              
880             sub make_datetime
881 78     78 1 103 {
882 78         99 my $self = shift( @_ );
883 2     2   1163 my $opts = shift( @_ );
  2         4  
  2         8  
884 78 50       169 use utf8;
885 78         133 return( $self->error( "Parameter provided is not an hash reference." ) ) if( ref( $opts ) ne 'HASH' );
886             for( qw( year month day ) )
887 234 50       432 {
888             return( $self->error( "Missing the $_ parameter." ) ) if( !length( $opts->{ $_ } ) );
889 78 100 100     224 }
890             if( length( $opts->{ampm} ) && $opts->{ampm} eq '午後' )
891 15         37 {
892             $opts->{hour} += 12;
893             }
894 78 50 33     149
  78         87  
  78         81  
  78         172  
  0         0  
  78         84  
  78         139  
  78         143  
895 78     78   93 try
896 78         68 {
897 78 100 66     293 my $dt;
898             if( $opts->{era} && ref( $opts->{era} ) )
899 44         86 {
900 44         143 my $era = $opts->{era};
901 44 50       287 $dt = $era->start_datetime;
902 44         37614 $dt->add( years => ( $opts->{year} - 1 ) ) if( $opts->{year} > 1 );
903 44         17406 $dt->set_month( $opts->{month} );
904             $dt->set_day( $opts->{day} );
905             }
906             else
907             {
908             my $p =
909             {
910             year => $opts->{year},
911             month => $opts->{month},
912 34         127 day => $opts->{day},
913 34 50       109 };
    50          
914             if( length( $opts->{time_zone} ) )
915 0         0 {
916             $p->{time_zone} = $opts->{time_zone};
917             }
918             elsif( length( $self->{time_zone} ) )
919 0         0 {
920             $p->{time_zone} = $self->{time_zone};
921             }
922 34         171
923             $dt = DateTime->new( %$p );
924 78 100       26185 }
925 78 100       25394 $dt->set_hour( $opts->{hour} ) if( $opts->{hour} );
926 78 100       17537 $dt->set_minute( $opts->{minute} ) if( $opts->{minute} );
927 78         5832 $dt->set_second( $opts->{second} ) if( $opts->{second} );
928             return( $dt );
929 78 0 0 0   366 }
  0 50 33     0  
  0 50 33     0  
  78 0       111  
  78 0       192  
  0 50       0  
  0 50       0  
  0 50       0  
  78 50       293  
  78 50       9765  
  78 50       37642  
  78 50       108  
  78 50       112  
  78 50       97  
  78 50       312  
  78 0       594  
  0 0       0  
  0 0       0  
  0 50       0  
  0 50       0  
  0 50       0  
  0 0       0  
  0 50       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  78         123  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  78         184  
  78         214  
  78         157  
  78         119  
  0         0  
  0         0  
  0         0  
  0         0  
930 0     0   0 catch( $e )
931 0         0 {
932 2 0 0 2   2770 return( $e );
  2 0 0     4  
  2 0 33     502  
  0 0 33     0  
  0 0 33     0  
  0 0 0     0  
  0 0 0     0  
  0 0 0     0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 50       0  
  0 50       0  
  0 50       0  
  0 50       0  
  0 50       0  
  0 0       0  
  0 0       0  
  0 0       0  
  78 0       794  
  78 0       153  
  78 0       218  
  78 50       316  
  0 50       0  
  0 50       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  78         1239  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
933             }
934             }
935              
936             sub message
937 768     768 0 790 {
938 768         667 my $self = shift( @_ );
939 768 50       1351 my $level = shift( @_ );
940 0 0       0 return(1) if( $self->{debug} < int( $level ) );
941 0         0 my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
942 0         0 chomp( $msg );
943 0         0 print( STDERR "# ", join( "\n# ", split( /\n/, $msg ) ), "\n" );
944             return(1);
945             }
946              
947             sub parse_datetime
948 78     78 1 500396 {
949 78         152 my $self = shift( @_ );
950 2     2   12 my $str = shift( @_ );
  2         4  
  2         7  
951 78         385 use utf8;
952 78 100       1848 $self->message( 3, "Checking datetime '$str'." );
    50          
    50          
953             if( $str =~ /$DATETIME_PATTERN_1_RE/ )
954 53         1167 {
955 53         323 my $re = { %+ };
956 53 100       146 $self->message( 3, "Pattern type 1 matched for '$str'." );
957             if( $re->{era} )
958 29   50     93 {
959             my $era = $self->lookup_era( $re->{era} ) ||
960 29         83 return( $self->error( "No era \"$re->{era}\" could be found." ) );
961             $re->{era} = $era;
962             }
963             else
964 24         54 {
965             $re->{year} = delete( $re->{gregorian_year} );
966 53         101 }
967             for( qw( year month day ) )
968 159 100       506 {
969 50         96 next if( $re->{ $_ } =~ /^[0-9]+$/ );
970             my $rv = $self->zenkaku_to_romaji( $re->{ $_ } );
971 50 50       75 # Pass on the error, if any
972 50         96 return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
973             $re->{ $_ } = $rv;
974 53         71 }
975             for( qw( hour minute second ) )
976 159 100 100     561 {
977 32         47 next if( !length( $re->{ $_ } ) || $re->{ $_ } =~ /^[0-9]+$/ );
978             my $rv = $self->zenkaku_to_romaji( $re->{ $_ } );
979 32 50       55 # Pass on the error, if any
980 32         57 return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
981             $re->{ $_ } = $rv;
982 53         130 }
983 53         114 $self->_dump( $re );
984             return( $self->make_datetime( $re ) );
985             }
986             # With full width roman number
987             elsif( $str =~ /$DATETIME_PATTERN_2_RE/ )
988 0         0 {
989 0         0 my $re = { %+ };
990 0 0       0 $self->message( 3, "Pattern type 2 matched for '$str'." );
991             if( $re->{era} )
992 0   0     0 {
993             my $era = $self->lookup_era( $re->{era} ) ||
994 0         0 return( $self->error( "No era \"$re->{era}\" could be found." ) );
995             $re->{era} = $era;
996             }
997             else
998 0         0 {
999             $re->{year} = delete( $re->{gregorian_year} );
1000 0         0 }
1001 0         0 $self->message( 3, "Got here." );
1002 0         0 $self->_dump( $re );
1003             return( $self->make_datetime( $re ) );
1004             }
1005             # With numbers in Kanji
1006             elsif( $str =~ /$DATETIME_PATTERN_3_RE/ )
1007 25         592 {
1008 25         168 my $re = { %+ };
1009 25 100       69 $self->message( 3, "Pattern type 3 matched for '$str'." );
1010             if( $re->{era} )
1011 15   50     65 {
1012             my $era = $self->lookup_era( $re->{era} ) ||
1013 15         52 return( $self->error( "No era \"$re->{era}\" could be found." ) );
1014             $re->{era} = $era;
1015             }
1016             else
1017 10         26 {
1018             $re->{year} = delete( $re->{gregorian_year} );
1019 25         57 }
1020             for( qw( year month day ) )
1021 75         171 {
1022             my $rv = $self->kanji_to_romaji( $re->{ $_ } );
1023 75 50       112 # Pass on the error, if any
1024 75         132 return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
1025             $re->{ $_ } = $rv;
1026 25         53 }
1027             for( qw( hour minute second ) )
1028 75 100       150 {
1029 41         68 next if( !length( $re->{ $_ } ) );
1030             my $rv = $self->kanji_to_romaji( $re->{ $_ } );
1031 41 50       69 # Pass on the error, if any
1032 41         81 return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
1033             $re->{ $_ } = $rv;
1034 25         60 }
1035             return( $self->make_datetime( $re ) );
1036             }
1037             else
1038 0         0 {
1039 0         0 $self->message( 3, "Nothing matched for '$str'." );
1040             return( $self->error( "Unknown datetime pattern \"$str\"" ) );
1041             }
1042             }
1043              
1044             sub romaji_to_kanji
1045 40     40 1 12241 {
1046 40         53 my $self = shift( @_ );
1047 40 50 33     158 my $num = shift( @_ );
1048             return( $num ) if( !defined( $num ) || !length( $num ) );
1049 2     2   1383 # $self->message( 3, "Converting '$num'." );
  2         3  
  2         9  
1050 40         56 use utf8;
1051 40         99 my $buff = [];
1052 40 100       104 $num =~ s/[^0-9]+//g;
1053             if( $num =~ s/^(\d)(\d{3})$/$2/ )
1054             {
1055 6 100       30 # $self->message( 3, "Adding '", $KANJI_NUMBERS->[ $1 ], "千'. String is now '$num'" );
1056             push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '千' );
1057 40         62 }
1058             $num =~ s/^0+([1-9][0-9]*)$/$1/;
1059 40 100 66     136
1060             unless( !length( $num ) || $num =~ /^0+$/ )
1061 39 100       91 {
1062             if( $num =~ s/^(\d)(\d{2})$/$2/ )
1063             {
1064 7 100       27 # $self->message( 3, "Adding '", $KANJI_NUMBERS->[ $1 ], "百'. String is now '$num'" );
1065             push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '百' );
1066 39         52 }
1067             $num =~ s/^0+([1-9][0-9]*)$/$1/;
1068 39 100 66     111
1069             unless( !length( $num ) || $num =~ /^0+$/ )
1070 38 100       124 {
1071             if( $num =~ s/^(\d)(\d)$/$2/ )
1072             {
1073 22 100       79 # $self->message( 3, "Adding '", $KANJI_NUMBERS->[ $1 ], "十'. String is now '$num'" );
1074             push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '十' );
1075 38 100       80 }
1076             $num = '' if( $num == 0 );
1077             # $self->message( 3, "Remains '$num'" );
1078 38 100 66     114  
1079             unless( !length( $num ) || $num =~ /^0+$/ )
1080 31         59 {
1081             push( @$buff, $KANJI_NUMBERS->[ $num ] );
1082             }
1083             }
1084 40         182 }
1085             return( join( '', @$buff ) );
1086             }
1087              
1088             sub romaji_to_kanji_simple
1089 3     3 1 32 {
1090 3         5 my $self = shift( @_ );
1091 3 50 33     17 my $num = shift( @_ );
1092 3         8 return( $num ) if( !defined( $num ) || !length( $num ) );
1093 3         12 my $buff = [];
1094             foreach( split( //, $num ) )
1095 13 100       35 {
1096             if( $_ !~ /^[0-9]$/ )
1097 1         4 {
1098 1         2 push( @$buff, $_ );
1099             next;
1100 12         31 }
1101             push( @$buff, $KANJI_NUMBERS->[ $_ ] );
1102 3         16 }
1103             return( join( '', @$buff ) );
1104             }
1105              
1106             sub romaji_to_zenkaku
1107 63     63 1 12649 {
1108 63         93 my $self = shift( @_ );
1109 2     2   839 my $num = shift( @_ );
  2         4  
  2         7  
1110             use utf8;
1111 63 50       191 # Already done
1112 63         100 return( $num ) if( $num =~ /^[0123456789]+$/ );
1113 63         157 my $buff = [];
1114             for( split( //, $num ) )
1115 135 50       441 {
    100          
1116             if( /^[0123456789]$/ )
1117 0         0 {
1118             push( @$buff, $_ );
1119             }
1120             elsif( /^[0-9]$/ )
1121 134         306 {
1122             push( @$buff, $ZENKAKU_NUMBERS->[ $_ ] );
1123             }
1124             else
1125 1 50       167 {
1126 1         7 warnings::warn( "Unknown character \"$_\" in number \"$num\" to be cnverted into full width.\n" ) if( warnings::enabled() );
1127             push( @$buff, $_ );
1128             }
1129 63         258 }
1130             return( join( '', @$buff ) );
1131             }
1132 0     0 1 0  
1133             sub time_zone { return( shift->_set_get( 'time_zone', @_ ) ); }
1134 0     0 1 0  
1135             sub traditional { return( shift->_set_get( 'traditional', @_ ) ); }
1136 0     0 1 0  
1137             sub zenkaku { return( shift->_set_get_zenkaku( 'zenkaku', @_ ) ); }
1138 82     82 1 128  
1139             sub zenkaku_to_romaji { return( shift->_get_pos_in_array( $ZENKAKU_NUMBERS, @_ ) ); }
1140              
1141             sub _dump
1142 53     53   83 {
1143 53         71 my $self = shift( @_ );
1144 53 50       132 my $ref = shift( @_ );
1145 0         0 return(1) if( !$self->{debug} );
1146             foreach my $k ( sort( keys( %$ref ) ) )
1147 0         0 {
1148             printf( STDERR "%-12s: %s\n", $k, $ref->{ $k } );
1149 0         0 }
1150 0         0 print( STDERR "-" x 20, "\n" );
1151             return(1);
1152             }
1153              
1154             sub _get_pos_in_array
1155 208     208   225 {
1156 208         219 my $self = shift( @_ );
1157 208         270 my $array = shift( @_ );
1158 208         844 my $num = shift( @_ );
1159 208 50       400 $self->message( 3, "Checking '$num' among '", join( "', '", @$array ), "'." );
1160 208 50       309 return( $self->error( "I was expecting an array reference, but I got \"$array\"." ) ) if( ref( $array ) ne 'ARRAY' );
1161 208 50 33     560 return( $self->error( "Array provided is empty!" ) ) if( !scalar( @$array ) );
1162 208         244 return( $self->error( "No value provided to transcode!" ) ) if( !defined( $num ) || !length( $num ) );
1163 208         387 my $buff = [];
  3340         3578  
1164 208 100       689 my( $index1 ) = grep{ $num eq $array->[$_] } 0..$#$array;
1165 208 100       451 $self->message( 3, " Searching for '$num' resulted in offset '$index1'." ) if( length( $index1 ) );
1166             return( $index1 ) if( length( $index1 ) );
1167 40         80
1168             for my $c ( split( //, $num ) )
1169 80 50       165 {
1170             if( $c =~ /^[0-9]$/ )
1171 0         0 {
1172 0         0 push( @$buff, $c );
1173             next;
1174 80         106 }
  800         846  
1175 80         237 my( $index ) = grep{ $c eq $array->[$_] } 0..$#$array;
1176 80 50       119 $self->message( 3, " Searching for '$c' resulted in offset '$index'." );
1177 80         125 return( $self->error( "Failed to find the corresponding entry for \"$c\"." ) ) if( !length( $index ) );
1178             push( @$buff, $index );
1179 40         97 }
1180 40         94 $self->message( 3, "Returning '", join( '', @$buff ), "'." );
1181             return( join( '', @$buff ) );
1182             }
1183              
1184             sub _set_get
1185 0     0   0 {
1186 0         0 my $self = shift( @_ );
1187 0 0       0 my $field = shift( @_ );
1188             if( @_ )
1189 0         0 {
1190             $self->{ $field } = shift( @_ );
1191 0         0 }
1192             return( $self->{ $field } );
1193             }
1194              
1195             sub _set_get_zenkaku
1196 0     0   0 {
1197 0         0 my $self = shift( @_ );
1198 0 0       0 my $field = shift( @_ );
1199             if( @_ )
1200 0         0 {
1201 0         0 my $v = shift( @_ );
1202 0 0       0 $self->{ $field } = $v;
    0          
1203             if( $field eq 'zenkaku' )
1204 0         0 {
1205             $self->{hankaku} = !$v;
1206             }
1207             elsif( $field eq 'hankaku' )
1208 0         0 {
1209             $self->{zenkaku} = !$v;
1210             }
1211 0         0 }
1212             return( $self->{ $field } );
1213             }
1214              
1215             # XXX DateTime::Format::JP::Era class
1216             {
1217             package
1218             DateTime::Format::JP::Era;
1219 0         0 BEGIN
1220 2     2   1498 {
  2         3  
  2         55  
1221 2     2   8 use strict;
  2         4  
  2         59  
1222 2     2   8 use warnings;
  2         4  
  2         14  
1223 2     2   1979 use parent qw( Exporter );
  2         905812  
  2         108  
1224 2     2   18 use DateTime;
  2     0   20  
  2         21  
1225             use Nice::Try;
1226             };
1227            
1228 59   33 59   365 # my $era = DateTime::Format::JP::Era->new( $era_dictionary_hash_ref );
1229             sub new { return( bless( $_[1] => ( ref( $_[0] ) || $_[0] ) ) ); }
1230            
1231             sub error
1232 0     0   0 {
1233 0 0       0 my $self = shift( @_ );
1234             if( @_ )
1235 0 0       0 {
1236 0 0       0 $self->{error} = $ERROR = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
1237 0         0 warnings::warn( $ERROR, "\n" ) if( warnings::enabled() );
1238             return;
1239 0 0       0 }
1240             return( ref( $self ) ? $self->{error} : $ERROR );
1241             }
1242 0     0   0  
  0         0  
1243             sub end { return( [@{shift->{end}}] ); }
1244 0     0   0  
1245             sub end_datetime { return( shift->_get_datetime( 'end' ) ); }
1246 12     12   80
1247             sub name { return( shift->{name} ); }
1248 0     0   0
1249             sub period { return( shift->{period} ); }
1250 0     0   0
  0         0  
1251             sub reading { return( [@{shift->{reading}}] ); }
1252 0     0   0  
  0         0  
1253             sub start { return( [@{shift->{start}}] ); }
1254 44     44   123
1255             sub start_datetime { return( shift->_get_datetime( 'start' ) ); }
1256            
1257             sub year
1258 14     14   30 {
1259             my( $self, $dt ) = @_;
1260 14         56 # First year is Year 1 of an era no matter when it starts in that year
1261             return( ( $dt->year + 1 ) - $self->{start}->[0] );
1262             }
1263            
1264             sub _get_datetime
1265 44     44   107 {
1266 44         70 my $self = shift( @_ );
1267 44         84 my $field = shift( @_ );
1268 44 50 33     76 my $ref = $self->{ $field };
  44         45  
  44         57  
  44         122  
  0         0  
  44         45  
  44         79  
  44         61  
1269 44     44   56 try
1270 44 50 33     199 {
1271             if( ref( $ref ) eq 'ARRAY' && scalar( @$ref ) == 3 )
1272 44         65 {
1273 44         143 my $opts = {};
1274 44         99 @$opts{qw( year month day )} = @$ref;
1275 44         74 @$opts{qw( hour minute second )} = (0,0,0);
1276 44         248 $opts->{time_zone} = 'local';
1277             return( DateTime->new( %$opts ) );
1278             }
1279             else
1280 0         0 {
1281             return( DateTime->now( time_zone => 'local' ) );
1282             }
1283 44 0 0 0   195 }
  0 50 33     0  
  0 50 33     0  
  44 0       63  
  44 0       109  
  0 50       0  
  0 50       0  
  0 50       0  
  44 50       219  
  44 50       3444  
  44 50       20323  
  44 50       74  
  44 50       56  
  44 50       109  
  44 50       187  
  44 0       388  
  0 0       0  
  0 0       0  
  0 50       0  
  0 50       0  
  0 50       0  
  0 0       0  
  0 50       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  44         88  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  44         42986  
  44         174  
  44         96  
  44         106  
  0         0  
  0         0  
  0         0  
  0         0  
1284 0     0   0 catch( $e )
1285 0         0 {
1286 2 0 0 2   1010670 return( $self->error( $e ) );
  2 0 0     6  
  2 0 33     393  
  0 0 33     0  
  0 0 33     0  
  0 0 0     0  
  0 0 0     0  
  0 0 0     0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 50       0  
  0 50       0  
  0 50       0  
  0 50       0  
  0 50       0  
  0 0       0  
  0 0       0  
  0 0       0  
  44 0       766  
  44 0       109  
  44 0       148  
  44 50       227  
  0 50       0  
  0 50       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  44         481  
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
1287             }
1288             }
1289             }
1290              
1291             1;
1292              
1293             __END__
1294              
1295             =encoding utf-8
1296              
1297             =head1 NAME
1298              
1299             DateTime::Format::JP - Japanese DateTime Parser and Formatter
1300              
1301             =head1 SYNOPSIS
1302              
1303             use DateTime::Format::JP;
1304             my $fmt = DateTime::Format::JP->new(
1305             hankaku => 1,
1306             pattern => '%c', # default
1307             traditional => 0,
1308             kanji_number => 0,
1309             zenkaku => 0,
1310             time_zone => 'local',
1311             );
1312             my $dt = DateTime->now;
1313             $dt->set_formatter( $fmt );
1314             # set the encoding in and out to utf8
1315             use open ':std' => ':utf8';
1316             print "$dt\n"; # will print something like 令和3年7月12日午後2:30:20
1317              
1318             my $dt = $fmt->parse_datetime( "令和3年7月12日午後2時30分" );
1319            
1320             my $str = $fmt->format_datetime( $dt );
1321             print "$str\n";
1322              
1323             =head1 VERSION
1324              
1325             v0.1.1
1326              
1327             =head1 DESCRIPTION
1328              
1329             This module is used to parse and format Japanese date and time. It is lightweight and yet versatile.
1330              
1331             It implements 2 main methods: L</parse_datetime> and L</format_datetime> both expect and return decoded utf8 string.
1332              
1333             You can use L<Encode> to decode and encode from perl internal utf8 representation to real utf8 and vice versa.
1334              
1335             =head1 METHODS
1336              
1337             =head2 new
1338              
1339             The constructor accepts the following parameters:
1340              
1341             =over 4
1342              
1343             =item I<hankaku> boolean
1344              
1345             If true, the digits used will be "half-size" (半角), or roman numbers like 1, 2, 3, etc.
1346              
1347             The opposite is I<zenkaku> (全角) or full-width. This will enable the use of double-byte Japanese numbers that still look like roman numbers, such as: 1, 2, 3, etc.
1348              
1349             Defaults to true.
1350              
1351             =item I<pattern> string
1352              
1353             The pattern to use to format the date and time. See below the available L</"PATTERN TOKENS"> and their meanings.
1354              
1355             Defaults to C<%c>
1356              
1357             =item I<traditional> boolean
1358              
1359             If true, then it will use a more traditional date/time representation. The effect of this parameter on the formatting is documented in L</"PATTERN TOKENS">
1360              
1361             =item I<kanji_number> boolean
1362              
1363             If true, this will have L</format_datetime> use numbers in kanji, such as: 一, 二, 三, 四, etc.
1364              
1365             =item I<zenkaku> boolean
1366              
1367             If true, this will use full-width, ie double-byte Japanese numbers that still look like roman numbers, such as: 1, 2, 3, etc.
1368              
1369             =item I<time_zone> string
1370              
1371             The time zone to use when creating a L<DateTime> object. Defaults to C<local>
1372              
1373             =back
1374              
1375             =head2 error
1376              
1377             Returns the latest error set, if any.
1378              
1379             All method in this module return C<undef> upon error and set an error that can be retrieved with this method.
1380              
1381             =head2 format_datetime
1382              
1383             Takes a L<DateTime> object and returns a formatted date and time based on the pattern specified, which defaults to C<%c>.
1384              
1385             You can call this method directly, or you can set this formatter object in L<DateTime/set_formatter> so that ie will be used for stringification of the L<DateTime> object.
1386              
1387             See below L</"PATTERN TOKENS"> for the available tokens and their meanings.
1388              
1389             =head2 hankaku
1390              
1391             Sets or gets the boolean value for I<hankaku>.
1392              
1393             =head2 kanji_number
1394              
1395             Sets or gets the boolean value for I<kanji_number>.
1396              
1397             =head2 parse_datetime
1398              
1399             Takes a string representing a Japanese date, parse it and return a new L<DateTime>. If an error occurred, it will return C<undef> and you can get the error using L</error>
1400              
1401             =head2 time_zone
1402              
1403             Sets or gets the string representing the time zone to use when creating L<DateTime> object. This is used by L</parse_datetime>
1404              
1405             =head2 traditional
1406              
1407             Sets or gets the boolean value for I<traditional>.
1408              
1409             =head2 zenkaku
1410              
1411             Sets or gets the boolean value for I<zenkaku>.
1412              
1413             =head1 SUPPORT METHODS
1414              
1415             =head2 kanji_to_romaji
1416              
1417             Takes a number in kanji and returns its equivalent value in roman (regular) numbers.
1418              
1419             =head2 lookup_era
1420              
1421             Takes an Japanese era in kanji and returns an C<DateTime::Format::JP::Era> object
1422              
1423             =head2 lookup_era_by_date
1424              
1425             Takes a L<DateTime> object and returns a C<DateTime::Format::JP::Era> object
1426              
1427             =head2 make_datetime
1428              
1429             Returns a L<DateTime> based on parameters provided.
1430              
1431             =head2 romaji_to_kanji
1432              
1433             Takes a number and returns its equivalent representation in Japanese kanji. Thus, for example, C<1234> would be returned as C<千二百三十四>
1434              
1435             Please note that, since this is intended to be used only for dates, it does not format number over 9 thousand. If you think there is such need, please contact the author.
1436              
1437             =head2 romaji_to_kanji_simple
1438              
1439             Replaces numbers with their Japanese kanji equivalent. It does not use numerals.
1440              
1441             =head2 romaji_to_zenkaku
1442              
1443             Takes a number and returns its equivalent representation in double-byte Japanese numbers. Thus, for example, C<1234> would be returned as C<1234>
1444              
1445             =head2 zenkaku_to_romaji
1446              
1447             Takes a string representing a number in full width (全角), i.e. double-byte and returns a regular equivalent number. Thus, for example, C<1234> would be returned as C<1234>
1448              
1449             =head1 PATTERN TOKENS
1450              
1451             Here are below the available tokens for formatting and the value they represent.
1452              
1453             In all respect, they are closely aligned with L<DateTime/strftime> (see L<DateTime/"strftime Patterns">), except that the formatter object parameters provided upon instantiation alter the values used.
1454              
1455             =over 4
1456              
1457             =item * %%
1458              
1459             The % character.
1460              
1461             =item * %a
1462              
1463             The weekday name in abbreviated form such as: 月, 火, 水, 木, 金, 土, 日
1464              
1465             =item * %A
1466              
1467             The weekday name in its long form such as: 月曜日, 火曜日, 水曜日, 木曜日, 金曜日, 土曜日, 日曜日
1468              
1469             =item * %b
1470              
1471             The month name, such as 1月, 2月, etc... 12月 using regular digits.
1472              
1473             =item * %B
1474              
1475             The month name using full width (全角) digits, such as 1月, 2月, etc... 12月
1476              
1477             =item * %h
1478              
1479             The month name using kanjis for numbers, such as 一月, 二月, etc... 十二月
1480              
1481             =item * %c
1482              
1483             The datetime format in the Japanese standard most usual form. For example for C<12th July 2021 14:17:30> this would be:
1484              
1485             令和3年7月12日午後2:17:30
1486              
1487             However, if I<traditional> is true, then it would rather be:
1488              
1489             令和3年7月12日午後2時17分30秒
1490              
1491             And if I<zenkaku> is true, it will use double-byte numbers instead:
1492              
1493             令和3年7月12日午後2時17分30秒
1494              
1495             And if I<kanji_number> is true, it will then be:
1496              
1497             令和三年七月十二日午後二時十七分三十秒
1498              
1499             =item * %C
1500              
1501             The century number (year/100) as a 2-digit integer. This is the same as L<DateTime/strftime>
1502              
1503             =item * %d or %e
1504              
1505             The day of month (1-31).
1506              
1507             However, if I<zenkaku> is true, then it would rather be with full width (全角) numbers: 1-31
1508              
1509             And if I<kanji_number> is true, it will then be with numbers in kanji: 一, 二, etc.. 十, 十一, etc..
1510              
1511             =item * %D
1512              
1513             Equivalent to C<%E%y年%m月%d日>
1514              
1515             This is the Japanese style date including with the leading era name.
1516              
1517             If I<zenkaku> is true, "full-width" (double byte) digits will be used and if I<kanji_number> is true, numbers in kanji will be used instead.
1518              
1519             See %F for an equivalent date using the Gregorian years rather than the Japanese era.
1520              
1521             =item * %E
1522              
1523             This extension is the Japanese era, such as C<令和> (i.e. "reiwa": the current era)
1524              
1525             =item * %F
1526              
1527             Equivalent to C<%Y年%m月%d日>
1528              
1529             If I<zenkaku> is true, "full-width" (double byte) digits will be used and if I<kanji_number> is true, numbers in kanji will be used instead.
1530              
1531             For the year only the conversion from regular digits to Japanese kanjis will be done simply by interpolating the digits and not using numerals. For example C<2021> would become C<二〇二一> and not C<二千二十一>
1532              
1533             =item * %g
1534              
1535             The year corresponding to the ISO week number, but without the century (0-99). This uses regular digits and is the same as L<DateTime/strftime>
1536              
1537             =item * %G
1538              
1539             The ISO 8601 year with century as a decimal number. The 4-digit year corresponding to the ISO week number. This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead. Also this returns regular digits.
1540              
1541             This uses regular digits and is the same as L<DateTime/strftime>
1542              
1543             =item * %H
1544              
1545             The hour: 0-23
1546              
1547             If I<traditional> is enabled, this would rather be C<0-23時>
1548              
1549             However, if I<zenkaku> is true, then it would rather use full width (全角) numbers: C<0-23時>
1550              
1551             And if I<kanji_number> is true, it will then be something like C<十時>
1552              
1553             =item * %I
1554              
1555             The hour on a 12-hour clock (1-12).
1556              
1557             If I<zenkaku> is true, it will use full width numbers and if I<kanji_number> is true, it will use numbers in kanji instead.
1558              
1559             =item * %j
1560              
1561             The day number in the year (1-366). This uses regular digits and is the same as L<DateTime/strftime>
1562              
1563             =item * %m
1564              
1565             The month number (1-12).
1566              
1567             If I<zenkaku> is true, it will use full width numbers and if I<kanji_number> is true, it will use numbers in kanji instead.
1568              
1569             =item * %M
1570              
1571             The minute: 0-59
1572              
1573             If I<traditional> is enabled, this would rather be C<0-59分>
1574              
1575             However, if I<zenkaku> is true, then it would rather use full width (全角) numbers: C<0-59分>
1576              
1577             And if I<kanji_number> is true, it will then be something like C<十分>
1578              
1579             =item * %n
1580              
1581             Arbitrary whitespace. Same as in L<DateTime/strftime>
1582              
1583             =item * %N
1584              
1585             Nanoseconds. For other sub-second values use C<%[number]N>.
1586              
1587             This is a pass-through directly to L<DateTime/strftime>
1588              
1589             =item * %p or %P
1590              
1591             Either produces the same result.
1592              
1593             Either AM (午前) or PM (午後) according to the given time value. Noon is treated as pm "午後" and midnight as am "午前".
1594              
1595             =item * %r
1596              
1597             Equivalent to C<%p%I:%M:%S>
1598              
1599             Note that if I<zenkaku> is true, the semi-colon used will be double-byte: C<:>
1600              
1601             Also if you use this, do not enable I<kanji_number>, because the result would be weird, something like:
1602              
1603             午後二:十四:三十 # 2:14:30 in this example
1604              
1605             =item * %R
1606              
1607             Equivalent to C<%H:%M>
1608              
1609             Note that if I<zenkaku> is true, the semi-colon used will be double-byte: C<:>
1610              
1611             Juste like for C<%r>, avoid enabling I<kanji_number> if you use this token.
1612              
1613             =item * %s
1614              
1615             Number of seconds since the Epoch.
1616              
1617             If I<zenkaku> is enabled, this will return the value as double-byte number.
1618              
1619             =item * %S
1620              
1621             The second: C<0-60>
1622              
1623             If I<traditional> is enabled, this would rather be C<0-60秒>
1624              
1625             However, if I<zenkaku> is true, then it would rather use full width (全角) numbers: C<0-60秒>
1626              
1627             And if I<kanji_number> is true, it will then be something like C<六十秒>
1628              
1629             (60 may occur for leap seconds. See L<DateTime::LeapSecond>).
1630              
1631             =item * %t
1632              
1633             Arbitrary whitespace. Same as in L<DateTime/strftime>
1634              
1635             =item * %T
1636              
1637             Equivalent to C<%H:%M:%S>
1638              
1639             However, if I<zenkaku> option is enabled, the numbers will be double-byte roman numbers and the separator will also be double-byte. For example:
1640              
1641             14:20:30
1642              
1643             =item * %U
1644              
1645             The week number with Sunday (日曜日) the first day of the week (0-53). The first Sunday of January is the first day of week 1.
1646              
1647             If I<zenkaku> is enabled, it will return a double-byte number instead.
1648              
1649             =item * %u
1650              
1651             The weekday number (1-7) with Monday (月曜日) = 1, 火曜日 = 2, 水曜日 = 3, 木曜日 = 4, 金曜日 = 5, 土曜日 = 6, 日曜日 = 7
1652              
1653             If I<zenkaku> is enabled, it will return a double-byte number instead.
1654              
1655             This is the C<DateTime> standard.
1656              
1657             =item * %w
1658              
1659             The weekday number (0-6) with Sunday = 0.
1660              
1661             If I<zenkaku> is enabled, it will return a double-byte number instead.
1662              
1663             =item * %W
1664              
1665             The week number with Monday (月曜日) the first day of the week (0-53). The first Monday of January is the first day of week 1.
1666              
1667             If I<zenkaku> is enabled, it will return a double-byte number instead.
1668              
1669             =item * %x
1670              
1671             The date format in the standard most usual form. For example for 12th July 2021 this would be:
1672              
1673             令和3年7月12日
1674              
1675             However, if I<zenkaku> is true, then it would rather be:
1676              
1677             令和3年7月12日
1678              
1679             And if I<kanji_number> is true, it will then be:
1680              
1681             令和三年七月十二日
1682              
1683             =item * %X
1684              
1685             The time format in the standard most usual form. For example for C<14:17:30> this would be:
1686              
1687             午後2:17:30
1688              
1689             And if I<zenkaku> is enabled, it would rather use a double-byte numbers and separator:
1690              
1691             午後2:17:30
1692              
1693             However, if I<traditional> is true, then it would rather be:
1694              
1695             午後2時17分30秒
1696              
1697             And if I<kanji_number> is true, it will then be:
1698              
1699             午後二時十七分三十秒
1700              
1701             =item * %y
1702              
1703             The year of the era. For example C<2021-07-12> would be C<令和3年7月12日> and thus the year value would be C<3>
1704              
1705             If I<zenkaku> is true, it will use full width numbers and if I<kanji_number> is true, it will use numbers in kanji instead.
1706              
1707             =item * %Y
1708              
1709             A 4-digit year, including century (for example, 1991).
1710              
1711             If I<zenkaku> is true, "full-width" (double byte) digits will be used and if I<kanji_number> is true, numbers in kanji will be used instead.
1712              
1713             Same as in C<%F>, the conversion from regular digits to Japanese kanjis will be done simply by interpolating the digits and not using numerals. For example C<2021> would become C<二〇二一> and not C<二千二十一>
1714              
1715             =item * %z
1716              
1717             An RFC-822/ISO 8601 standard time zone specification. (For example
1718             +1100)
1719              
1720             If I<zenkaku> is true, "full-width" (double byte) digits and C<+/-> signs will be used and if I<kanji_number> is true, numbers in kanji will be used instead. However, no numeral will be used. Thus a time zone offset such as C<+0900> would be returned as C<+〇九〇〇>
1721              
1722             =item * %Z
1723              
1724             The timezone name. (For example EST -- which is ambiguous). This is the same as L<DateTime/strftime>
1725              
1726             =back
1727              
1728             =head1 HISTORICAL NOTE
1729              
1730             Japanese eras, also known as 元号 (gengo) or 年号 (nengo) form one of the two parts of a Japanese year in any given date.
1731              
1732             It was instituted by and under first Emperor Kōtoku in 645 AD. So be warned that requiring an era-based Japanese date before will not yield good results.
1733              
1734             Era name were adopted for various reasons such as a to commemorate an auspicious or ward off a malign event, and it is only recently that era name changes are tied to a new Emperor.
1735              
1736             More on this L<here|https://en.wikipedia.org/wiki/Japanese_era_name>
1737              
1738             From 1334 until 1392, there were 2 competing regimes in Japan; the North and South. This period was called "Nanboku-chō" (南北朝). This module uses the official Northern branch.
1739              
1740             Also there has been two times during the period "Asuka" (飛鳥時代) with no era names, from 654/11/24 until 686/8/14 after Emperor Kōtoku death and from 686/10/1 until 701/5/3 after Emperor Tenmu's death just 2 months after his enthronement.
1741              
1742             Thus if you want a Japanese date using era during those two periods, you will get and empty era.
1743              
1744             More on this L<here|https://ja.wikipedia.org/wiki/%E5%85%83%E5%8F%B7%E4%B8%80%E8%A6%A7_(%E6%97%A5%E6%9C%AC)>
1745              
1746             =head1 AUTHOR
1747              
1748             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
1749              
1750             =head1 SEE ALSO
1751              
1752             L<DateTime>
1753              
1754             =head1 COPYRIGHT & LICENSE
1755              
1756             Copyright(c) 2021 DEGUEST Pte. Ltd. DEGUEST Pte. Ltd.
1757              
1758             You can use, copy, modify and redistribute this package and associated
1759             files under the same terms as Perl itself.
1760              
1761             =cut