File Coverage

lib/DateTime/Format/JP.pm
Criterion Covered Total %
statement 462 687 67.2
branch 229 502 45.6
condition 84 220 38.1
subroutine 85 106 80.1
pod 17 18 94.4
total 877 1533 57.2


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