File Coverage

lib/DateTime/Format/JP.pm
Criterion Covered Total %
statement 395 479 82.4
branch 178 260 68.4
condition 69 144 47.9
subroutine 79 97 81.4
pod 17 18 94.4
total 738 998 73.9


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Japanese DateTime Parser/Formatter - ~/lib/DateTime/Format/JP.pm
3             ## Version v0.1.6
4             ## Copyright(c) 2024 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2021/07/18
7             ## Modified 2024/09/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             package DateTime::Format::JP;
14             BEGIN
15             {
16 2     2   291623 use strict;
  2         4  
  2         91  
17 2     2   13 use warnings;
  2         3  
  2         165  
18 2     2   44 use warnings::register;
  2         3  
  2         198  
19 2     2   1131 use parent qw( Exporter );
  2         797  
  2         14  
20 2         518 use vars qw(
21             $VERSION $DATETIME_PATTERN_1_RE $DATETIME_PATTERN_2_RE $DATETIME_PATTERN_3_RE $DICT
22             $ZENKAKU_NUMBERS $KANJI_NUMBERS $ZENKAKU_TO_ROMAN $KANJI_TO_ROMAN $WEEKDAYS
23             $WEEKDAYS_RE $TIME_RE $TIME_ZENKAKU_RE $TIME_KANJI_RE $ERROR
24 2     2   222 );
  2         24  
25 2     2   8 our $VERSION = 'v0.1.6';
26 2         4 our $DICT = [];
27 2         4 our $ZENKAKU_NUMBERS = [];
28 2         4 our $KANJI_NUMBERS = [];
29 2         6 our $ZENKAKU_TO_ROMAN= {};
30 2         4 our $KANJI_TO_ROMAN = {};
31 2         21 our $WEEKDAYS = [];
32 2         5 our $WEEKDAYS_RE;
33 2         3 our $TIME_RE;
34 2         61 our( $DATETIME_PATTERN_1_RE, $DATETIME_PATTERN_2_RE, $DATETIME_PATTERN_3_RE )
35             };
36              
37 2     2   16 use strict;
  2         17  
  2         68  
38 2     2   12 use warnings;
  2         17  
  2         117  
39              
40             {
41 2     2   1369 use utf8;
  2         749  
  2         16  
42             $ZENKAKU_NUMBERS = [qw(0 1 2 3 4 5 6 7 8 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             sub new
414             {
415 85     85 1 634825 my $this = shift( @_ );
416 85 50       261 return( $this->error( "Incorrect parameters provided. You need to provide an hash of values." ) ) if( @_ % 2 );
417 85         230 my $p = { @_ };
418 85   50     204 $p->{debug} //= 0;
419             # kanji_number
420             # pattern
421             # time_zone
422             # traditional
423             # zenkaku / hankaku
424 85 50 33     163 if( exists( $p->{hankaku} ) && !exists( $p->{zenkaku} ) )
425             {
426 0         0 $p->{zenkaku} = !$p->{hankaku};
427             }
428 85   33     314 return( bless( $p => ( ref( $this ) || $this ) ) );
429             }
430              
431             sub error
432             {
433 0     0 1 0 my $self = shift( @_ );
434 0 0       0 if( @_ )
435             {
436 0 0       0 $self->{error} = $ERROR = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
437 0 0       0 warnings::warn( $ERROR, "\n" ) if( warnings::enabled() );
438 0         0 return;
439             }
440 0 0       0 return( ref( $self ) ? $self->{error} : $ERROR );
441             }
442              
443             sub format_datetime
444             {
445 83     83 1 240 my $self = shift( @_ );
446 83         115 my $dt = shift( @_ );
447 83         468 require overload;
448 83 50 33     514 return( $self->error( "Value provided (", overload::StrVal( $dt ), ") is not a DateTime object or one inheriting from it." ) ) if( !ref( $dt ) || ( ref( $dt ) && !$dt->isa( 'DateTime' ) ) );
      33        
449 83 50       180 my $pat = length( $self->{pattern} ) ? $self->{pattern} : '%c';
450 2     2   12500 use utf8;
  2         4  
  2         9  
451            
452             my $japanised_value_for = sub
453             {
454 48     48   71 my $method_name = shift( @_ );
455 48         58 my $opts = {};
456 48 100       89 $opts = shift( @_ ) if( ref( $_[0] ) eq 'HASH' );
457 48 100       94 $opts->{simple_kanji} = 0 if( !exists( $opts->{simple_kanji} ) );
458 48         164 my $ref = $dt->can( $method_name );
459 48         132 my $n = $ref->( $dt );
460 48 100       262 if( $self->{zenkaku} )
    100          
461             {
462 20         39 $n = $self->romaji_to_zenkaku( $n );
463             }
464             elsif( $self->{kanji_number} )
465             {
466 8 100       12 if( $opts->{simple_kanji} )
467             {
468 1         4 $n = $self->romaji_to_kanji_simple( $n );
469             }
470             else
471             {
472 7         38 $n = $self->romaji_to_kanji( $n );
473             }
474             }
475 48         246 return( $n );
476 83         351 };
477             my $japanised_strftime = sub
478             {
479 9     9   14 my $token = shift( @_ );
480 9         11 my $opts = {};
481 9 100       18 $opts = shift( @_ ) if( ref( $_[0] ) eq 'HASH' );
482 9 100       20 $opts->{simple_kanji} = 0 if( !exists( $opts->{simple_kanji} ) );
483 9         33 my $n = $dt->strftime( $token );
484 2     2   833 no warnings 'DateTime::Format::JP';
  2         4  
  2         8266  
485 9 100       849 if( $self->{zenkaku} )
    100          
486             {
487 4         18 $n = $self->romaji_to_zenkaku( $n );
488             }
489             elsif( $self->{kanji_number} )
490             {
491 1 50       5 if( $opts->{simple_kanji} )
492             {
493 1         4 $n = $self->romaji_to_kanji_simple( $n );
494             }
495             else
496             {
497 0         0 $n = $self->romaji_to_kanji( $n );
498             }
499             }
500 9         24 return( $n );
501 83         201 };
502            
503             my $map =
504             {
505 0 0 0 0   0 '%' => sub{ return( ( $self->{traditional} || $self->{zenkaku} || $self->{kanji_number} ) ? '%' : '%' ); },
506             # weekday name in abbreviated form
507             'a' => sub
508             {
509 1     1   9 my $n = $dt->day_of_week - 1;
510 1         8 return( $WEEKDAYS->[ $n ] );
511             },
512             # weekday name in its long form
513             'A' => sub
514             {
515 1     1   3 my $n = $dt->day_of_week - 1;
516 1         7 return( $WEEKDAYS->[ $n ] . '曜日' );
517             },
518             # month name
519 1     1   6 'b' => sub{ return( sprintf( '%d月', $dt->month ) ); },
520             # month name using full width (全角) digits
521 1     1   5 'B' => sub{ return( sprintf( '%s月', $self->romaji_to_zenkaku( $dt->month ) ) ); },
522             # month name using kanjis for numbers
523 1     1   4 'h' => sub{ return( sprintf( '%s月', $self->romaji_to_kanji( $dt->month ) ) ); },
524             # datetime format in the standard most usual form
525             # 令和3年7月12日午後2:17:30
526             # 令和3年7月12日午後2時17分30秒
527             # 令和3年7月12日午後2時17分30秒
528             # 令和3年七月十二日午後二時十七分三十秒
529             'c' => sub
530             {
531 5   50 5   16 my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
532 5         13 my $def =
533             {
534             year => $era->year( $dt ),
535             month => $dt->month,
536             day => $dt->day,
537             hour => $dt->hour_12,
538             minute => $dt->minute,
539             second => $dt->second,
540             };
541 5         157 foreach( keys( %$def ) )
542             {
543 30 100       43 if( $self->{zenkaku} )
    100          
544             {
545 12         20 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
546             }
547             elsif( $self->{kanji_number} )
548             {
549 6         11 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
550             }
551             }
552 5 100 100     17 if( $self->{traditional} || $self->{kanji_number} )
553             {
554 3         7 $def->{suff_hour} = '時';
555 3         4 $def->{suff_minute} = '分';
556 3         4 $def->{suff_second} = '秒';
557 3 50       8 return( sprintf( '%s%s年%s月%s日%s%s%s%s%s%s%s', $era->name, @$def{qw( year month day )}, ( $dt->hour > 12 ? '午後' : '午前' ), @$def{qw( hour suff_hour minute suff_minute second suff_second )} ) );
558             }
559             else
560             {
561 2 100       5 $def->{sep} = $self->{zenkaku} ? ':' : ':';
562 2 50       29 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 )} ) );
563             }
564             },
565             # century number (0-99)
566 1     1   8 'C' => sub{ return( $dt->strftime( '%C' ) ); },
567             # day of month
568 6     6   12 'd' => sub{ return( $japanised_value_for->( 'day' ) ); },
569             # Japanese style date including with the leading era name
570             'D' => sub
571             {
572 3   50 3   10 my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
573 3         10 my $def =
574             {
575             year => $era->year( $dt ),
576             month => $dt->month,
577             day => $dt->day,
578             };
579 3         45 foreach( keys( %$def ) )
580             {
581 9 100       19 if( $self->{zenkaku} )
    100          
582             {
583 3         7 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
584             }
585             elsif( $self->{kanji_number} )
586             {
587 3         7 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
588             }
589             }
590 3         12 return( sprintf( '%s%s年%s月%s日', $era->name, @$def{qw( year month day )} ) );
591             },
592             # Japanese era name
593             'E' => sub
594             {
595 1   50 1   5 my $e = $self->lookup_era_by_date( $dt ) || return;
596 1         4 return( $e->name );
597             },
598             # Equivalent to "%Y年%m月%d日"
599             'F' => sub
600             {
601 3     3   10 my $def =
602             {
603             year => $dt->year,
604             month => $dt->month,
605             day => $dt->day,
606             };
607 3         37 foreach( qw( month day ) )
608             {
609 6 100       13 if( $self->{zenkaku} )
    100          
610             {
611 2         5 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
612             }
613             elsif( $self->{kanji_number} )
614             {
615 2         5 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
616             }
617             }
618            
619 3 100       6 if( $self->{zenkaku} )
    100          
620             {
621 1         14 $def->{year} = $self->romaji_to_zenkaku( $def->{year} );
622             }
623             elsif( $self->{kanji_number} )
624             {
625 1         4 $def->{year} = $self->romaji_to_kanji_simple( $def->{year} );
626             }
627            
628 3         21 return( sprintf( '%s年%s月%s日', @$def{qw( year month day )} ) );
629             },
630             # year without century
631 1     1   7 'g' => sub{ return( $dt->strftime( '%g' ) ); },
632             # week number 4-digit year
633 1     1   3 'G' => sub{ return( $dt->strftime( '%G' ) ); },,
634             # hour
635 5 100 100 5   8 'H' => sub{ return( $japanised_value_for->( 'hour' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '時' : '' ) ); },
636             # hour with clock of 12
637 3     3   7 'I' => sub{ return( $japanised_value_for->( 'hour_12' ) ); },
638             # day number in the year
639 1     1   6 'j' => sub{ return( $dt->strftime( '%j' ) ); },
640             # month number
641 3     3   7 'm' => sub{ return( $japanised_value_for->( 'month' ) ); },
642             # minute
643 5 100 100 5   12 'M' => sub{ return( $japanised_value_for->( 'minute' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '分' : '' ) ); },
644             # space
645 0     0   0 'n' => sub{ return( $dt->strftime( '%n' ) ); },
646             # AM/PM
647 2 50   2   8 'p' => sub{ return( $dt->hour > 12 ? '午後' : '午前' ); },
648             # Equivalent to "%p%I:%M:%S"
649 2 50   2   8 'r' => sub{ return( sprintf( '%s%s%s%s%s%s', ( $dt->hour > 12 ? '午後' : '午前' ), $japanised_value_for->( 'hour_12' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'minute' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'second' ) ) ); },
    100          
    100          
650             # Equivalent to "%H:%M"
651 2 100   2   4 'R' => sub{ return( sprintf( '%s%s%s', $japanised_value_for->( 'hour' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'minute' ) ) ); },
652             # seconds since the Epoch
653 2 100   2   11 's' => sub{ return( $self->{zenkaku} ? $self->romaji_to_zenkaku( $dt->strftime( '%s' ) ) : $dt->strftime( '%s' ) ); },
654             # seconds
655 5 100 100 5   9 'S' => sub{ return( $japanised_value_for->( 'second' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '秒' : '' ) ); },
656             # space
657 0     0   0 't' => sub{ return( $dt->strftime( '%t' ) ); },
658             # Equivalent to "%H:%M:%S"
659 2 100   2   7 'T' => sub{ return( sprintf( '%s%s%s%s%s', $japanised_value_for->( 'hour' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'minute' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'second' ) ) ); },
    100          
660             # week number with Sunday first
661 2     2   5 'U' => sub{ return( $japanised_strftime->( '%U' ) ); },
662             # weekday number 1-7
663 2     2   4 'u' => sub{ return( $japanised_value_for->( 'day_of_week' ) ); },
664             # weekday number 0-7 with Sunday first
665 2     2   5 'w' => sub{ return( $japanised_strftime->( '%w' ) ); },
666             # week number with Monday first
667 2     2   5 'W' => sub{ return( $japanised_strftime->( '%W' ) ); },
668             # date format in the standard most usual form
669             # 令和3年7月12日
670             # 令和3年7月12日
671             # 令和3年七月十二日
672             'x' => sub
673             {
674 3   50 3   10 my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
675 3         11 my $def =
676             {
677             year => $era->year( $dt ),
678             month => $dt->month,
679             day => $dt->day,
680             };
681 3         66 foreach( keys( %$def ) )
682             {
683 9 100       20 if( $self->{zenkaku} )
    100          
684             {
685 3         7 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
686             }
687             elsif( $self->{kanji_number} )
688             {
689 3         8 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
690             }
691             }
692 3         14 return( sprintf( '%s%s年%s月%s日', $era->name, @$def{qw( year month day )} ) );
693             },
694             # time format in the standard most usual form
695             # 午後2:17:30
696             # 午後2時17分30秒
697             # 午後二時十七分三十秒
698             'X' => sub
699             {
700 4     4   18 my $def =
701             {
702             hour => $dt->hour_12,
703             minute => $dt->minute,
704             second => $dt->second,
705             };
706 4 50       69 $def->{ampm} = $dt->hour > 12 ? '午後' : '午前';
707 4         75 $def->{sep1} = $def->{sep2} = ':';
708 4 100 100     56 if( $self->{traditional} || $self->{kanji_number} )
    100          
709             {
710 2         4 $def->{suff_hour} = '時';
711 2         4 $def->{suff_minute} = '分';
712 2         3 $def->{suff_second} = '秒';
713 2         4 delete( @$def{qw( sep1 sep2 )} );
714             }
715             elsif( $self->{zenkaku} )
716             {
717 1         2 $def->{sep1} = $def->{sep2} = ':';
718             }
719            
720 4         9 foreach( qw( hour minute second ) )
721             {
722 12 100       24 if( $self->{zenkaku} )
    100          
723             {
724 3         7 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
725             }
726             elsif( $self->{kanji_number} )
727             {
728 3         8 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
729             }
730             }
731            
732 4 100 100     15 if( $self->{traditional} || $self->{kanji_number} )
733             {
734 2         16 return( sprintf( '%s%s%s%s%s%s%s', @$def{qw( ampm hour suff_hour minute suff_minute second suff_second )} ) );
735             }
736             else
737             {
738 2         24 return( sprintf( '%s%s%s%s%s%s', @$def{qw( ampm hour sep1 minute sep2 second )} ) );
739             }
740             },
741             # year of the era, relative to the start of the era
742             'y' => sub
743             {
744 3   50 3   10 my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
745 3         9 my $y = $era->year( $dt );
746 3 100       24 if( $self->{zenkaku} )
    100          
747             {
748 1         5 $y = $self->romaji_to_zenkaku( $y );
749             }
750             elsif( $self->{kanji_number} )
751             {
752 1         4 $y = $self->romaji_to_kanji( $y );
753             }
754 3         10 return( $y );
755             },
756             # 4-digit year
757 3     3   11 'Y' => sub{ return( $japanised_value_for->( 'year', { simple_kanji => 1 }) ); },
758             # standard time zone specification, such as +0900
759             'z' => sub
760             {
761 3     3   8 my $rv = $japanised_strftime->( '%z', { simple_kanji => 1 });
762 3 100 66     21 if( $self->{zenkaku} || $self->{traditional} || $self->{kanji_number} )
      66        
763             {
764 2 50       8 if( substr( $rv, 0, 1 ) eq '+' )
    0          
765             {
766 2         5 substr( $rv, 0, 1, '+' );
767             }
768             elsif( substr( $rv, 0, 1 ) eq '-' )
769             {
770 0         0 substr( $rv, 0, 1, 'ー' );
771             }
772             }
773 3         10 return( $rv );
774             },
775             # timezone name
776 1     1   4 'Z' => sub{ return( $dt->strftime( '%Z' ) ); },
777 83         4179 };
778             # Aliases
779 83         238 $map->{e} = $map->{d};
780 83         114 $map->{P} = $map->{p};
781 83         492 $pat =~ s
782             {
783             \%([\%aAbBhcCdeDEFgGHIjmMnNpPrRRsStTUuwWxXyYzZ])
784             }
785             {
786 83         178 my $token = $1;
787 83 50       161 die( "Missing definition for '$token'\n" ) if( !exists( $map->{ $token } ) );
788 83         112 $map->{ $token }->();
789             }gexs;
790              
791 83         590 $pat =~ s
792             {
793             \%\{(\w+)\}
794             }
795             {
796 0         0 my $meth = $1;
797 0         0 my $code = $dt->can( $meth );
798 0 0       0 if( $code )
799             {
800 0         0 $code->( $dt );
801             }
802             else
803             {
804 0 0       0 warnings::warn( "Unsupported DateTime method \"${meth}\" found in pattern.\n" ) if( warnings::enabled() );
805 0         0 '%{' . $meth . '}';
806             }
807             }gexs;
808            
809 83 50       210 if( index( $pat, '%' ) != -1 )
810             {
811 0         0 $pat = $dt->strftime( $pat );
812             }
813 83         5596 return( $pat );
814             }
815              
816 0     0 1 0 sub hankaku { return( shift->_set_get_zenkaku( 'hankaku', @_ ) ); }
817              
818 0     0 1 0 sub kanji_number { return( shift->_set_get( 'kanji_number', @_ ) ); }
819              
820             sub kanji_to_romaji
821             {
822 116     116 1 152 my $self = shift( @_ );
823 116         223 my $num = shift( @_ );
824 116 50 33     399 return( $self->error( "No value provided to transcode from kanji number to roman numerals." ) ) if( !defined( $num ) || !length( $num ) );
825 2     2   18 use utf8;
  2         3  
  2         19  
826 116         138 my $rv = 0;
827 116 100       333 if( $num =~ s/^[[:blank:]\h]*([〇一二三四五六七八九])千// )
828             {
829 10         37 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
830 10         13 $rv = $n * 1000;
831             }
832 116 50 33     373 if( length( $num ) && $num =~ s/^([〇一二三四五六七八九])百// )
833             {
834 0         0 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
835 0         0 $rv += ( $n * 100 );
836             }
837 116 100 66     415 if( length( $num ) && $num =~ s/^([〇一二三四五六七八九])十// )
838             {
839 15         39 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
840 15         30 $rv += ( $n * 10 );
841             }
842 116 100       183 if( length( $num ) )
843             {
844 101         182 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $num );
845 101         148 $rv += $n;
846             }
847 116         150 return( $rv );
848             }
849              
850             sub lookup_era
851             {
852 44     44 1 79 my $self = shift( @_ );
853 44   50     152 my $name = shift( @_ ) ||
854             return( $self->error( "No era name was provided to lookup." ) );
855 44         181 foreach my $ref ( @$DICT )
856             {
857 10648 100       22695 if( $ref->{name} eq $name )
858             {
859 44         229 return( DateTime::Format::JP::Era->new( $ref ) );
860             }
861             }
862             # Nothing found
863 0         0 return;
864             }
865              
866             sub lookup_era_by_date
867             {
868 15     15 1 20 my $self = shift( @_ );
869 15         24 my $dt = shift( @_ );
870 15         58 require overload;
871 15 50 33     93 return( $self->error( "Value provided (", overload::StrVal( $dt ), ") is not a DateTime object or one inheriting from it." ) ) if( !ref( $dt ) || ( ref( $dt ) && !$dt->isa( 'DateTime' ) ) );
      33        
872 15         58 my( $y, $m, $d ) = unpack( 'A4A2A2', $dt->ymd( '' ) );
873 15         281 my $era;
874 15         32 foreach my $def ( @$DICT )
875             {
876             # No need to bother if the current entry has an end and it is lower than our current year
877 3630 100 66     2540 next if( scalar( @{$def->{end}} ) && $y > $def->{end}->[0] );
  3630         7670  
878 15 50 50     19 if( scalar( @{$def->{start}} ) &&
  15 50 33     37  
      33        
      0        
      0        
      0        
      0        
      33        
      33        
      33        
      33        
879 15         49 scalar( @{$def->{end}} ) &&
880             $y >= $def->{start}->[0] &&
881             $y <= $def->{end}->[0] &&
882             $m >= $def->{start}->[1] &&
883             $m <= $def->{end}->[1] &&
884             $d >= $def->{start}->[2] &&
885             $d < $def->{end}->[2] )
886             {
887 0         0 $era = DateTime::Format::JP::Era->new( $def );
888 0         0 last;
889             }
890             # Obviously the current era, i.e. it has no end date
891 15         31 elsif( scalar( @{$def->{start}} ) &&
892 15         119 !scalar( @{$def->{end}} ) &&
893             $y >= $def->{start}->[0] &&
894             $m >= $def->{start}->[1] &&
895             $d >= $def->{start}->[2] )
896             {
897 15         77 $era = DateTime::Format::JP::Era->new( $def );
898 15         24 last;
899             }
900             }
901 15         55 return( $era );
902             }
903              
904             sub make_datetime
905             {
906 78     78 1 191 my $self = shift( @_ );
907 78         155 my $opts = shift( @_ );
908 2     2   2096 use utf8;
  2         5  
  2         20  
909 78 50       222 return( $self->error( "Parameter provided is not an hash reference." ) ) if( ref( $opts ) ne 'HASH' );
910 78         145 for( qw( year month day ) )
911             {
912 234 50       491 return( $self->error( "Missing the $_ parameter." ) ) if( !length( $opts->{ $_ } ) );
913             }
914 78 100 100     258 if( length( $opts->{ampm} ) && $opts->{ampm} eq '午後' )
915             {
916 15         61 $opts->{hour} += 12;
917             }
918            
919 78         183 local $@;
920             # try-catch
921             my $rv = eval
922 78         172 {
923 78         95 my $dt;
924 78 100 66     264 if( $opts->{era} && ref( $opts->{era} ) )
925             {
926 44         72 my $era = $opts->{era};
927 44         129 $dt = $era->start_datetime;
928 44 50       287 $dt->add( years => ( $opts->{year} - 1 ) ) if( $opts->{year} > 1 );
929 44         44682 $dt->set_month( $opts->{month} );
930 44         26836 $dt->set_day( $opts->{day} );
931             }
932             else
933             {
934             my $p =
935             {
936             year => $opts->{year},
937             month => $opts->{month},
938             day => $opts->{day},
939 34         177 };
940 34 50       158 if( length( $opts->{time_zone} ) )
    50          
941             {
942 0         0 $p->{time_zone} = $opts->{time_zone};
943             }
944             elsif( length( $self->{time_zone} ) )
945             {
946 0         0 $p->{time_zone} = $self->{time_zone};
947             }
948            
949 34         279 $dt = DateTime->new( %$p );
950             };
951 78 100       32871 $dt->set_hour( $opts->{hour} ) if( $opts->{hour} );
952 78 100       31841 $dt->set_minute( $opts->{minute} ) if( $opts->{minute} );
953 78 100       26152 $dt->set_second( $opts->{second} ) if( $opts->{second} );
954 78         7245 return( $dt );
955             };
956 78 50       204 if( $@ )
957             {
958 0         0 return( $@ );
959             }
960 78         472 return( $rv );
961             }
962              
963             sub message
964             {
965 0     0 0 0 my $self = shift( @_ );
966 0         0 my $level = shift( @_ );
967 0 0 0     0 return(1) if( $self->{debug} < int( $level // 0 ) );
968 0 0       0 my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
969 0         0 chomp( $msg );
970 0         0 print( STDERR "# ", join( "\n# ", split( /\n/, $msg ) ), "\n" );
971 0         0 return(1);
972             }
973              
974             sub parse_datetime
975             {
976 78     78 1 814552 my $self = shift( @_ );
977 78         204 my $str = shift( @_ );
978 2     2   1699 use utf8;
  2         4  
  2         9  
979 78 100       3222 if( $str =~ /$DATETIME_PATTERN_1_RE/ )
    50          
    50          
980             {
981 53         1812 my $re = { %+ };
982 53 100       342 if( $re->{era} )
983             {
984 29   50     127 my $era = $self->lookup_era( $re->{era} ) ||
985             return( $self->error( "No era \"$re->{era}\" could be found." ) );
986 29         103 $re->{era} = $era;
987             }
988             else
989             {
990 24         78 $re->{year} = delete( $re->{gregorian_year} );
991             }
992 53         123 for( qw( year month day ) )
993             {
994 159 100       653 next if( $re->{ $_ } =~ /^[0-9]+$/ );
995 50         133 my $rv = $self->zenkaku_to_romaji( $re->{ $_ } );
996             # Pass on the error, if any
997 50 50       95 return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
998 50         120 $re->{ $_ } = $rv;
999             }
1000 53         97 for( qw( hour minute second ) )
1001             {
1002 159 100 100     696 next if( !length( $re->{ $_ } ) || $re->{ $_ } =~ /^[0-9]+$/ );
1003 32         85 my $rv = $self->zenkaku_to_romaji( $re->{ $_ } );
1004             # Pass on the error, if any
1005 32 50       65 return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
1006 32         64 $re->{ $_ } = $rv;
1007             }
1008 53         217 $self->_dump( $re );
1009 53         159 return( $self->make_datetime( $re ) );
1010             }
1011             # With full width roman number
1012             elsif( $str =~ /$DATETIME_PATTERN_2_RE/ )
1013             {
1014 0         0 my $re = { %+ };
1015 0 0       0 if( $re->{era} )
1016             {
1017 0   0     0 my $era = $self->lookup_era( $re->{era} ) ||
1018             return( $self->error( "No era \"$re->{era}\" could be found." ) );
1019 0         0 $re->{era} = $era;
1020             }
1021             else
1022             {
1023 0         0 $re->{year} = delete( $re->{gregorian_year} );
1024             }
1025 0         0 $self->_dump( $re );
1026 0         0 return( $self->make_datetime( $re ) );
1027             }
1028             # With numbers in Kanji
1029             elsif( $str =~ /$DATETIME_PATTERN_3_RE/ )
1030             {
1031 25         944 my $re = { %+ };
1032 25 100       182 if( $re->{era} )
1033             {
1034 15   50     72 my $era = $self->lookup_era( $re->{era} ) ||
1035             return( $self->error( "No era \"$re->{era}\" could be found." ) );
1036 15         70 $re->{era} = $era;
1037             }
1038             else
1039             {
1040 10         34 $re->{year} = delete( $re->{gregorian_year} );
1041             }
1042 25         69 for( qw( year month day ) )
1043             {
1044 75         209 my $rv = $self->kanji_to_romaji( $re->{ $_ } );
1045             # Pass on the error, if any
1046 75 50       124 return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
1047 75         156 $re->{ $_ } = $rv;
1048             }
1049 25         78 for( qw( hour minute second ) )
1050             {
1051 75 100       158 next if( !length( $re->{ $_ } ) );
1052 41         78 my $rv = $self->kanji_to_romaji( $re->{ $_ } );
1053             # Pass on the error, if any
1054 41 50       79 return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
1055 41         85 $re->{ $_ } = $rv;
1056             }
1057 25         80 return( $self->make_datetime( $re ) );
1058             }
1059             else
1060             {
1061 0         0 return( $self->error( "Unknown datetime pattern \"$str\"" ) );
1062             }
1063             }
1064              
1065             sub romaji_to_kanji
1066             {
1067 40     40 1 11804 my $self = shift( @_ );
1068 40         49 my $num = shift( @_ );
1069 40 50 33     142 return( $num ) if( !defined( $num ) || !length( $num ) );
1070 2     2   2239 use utf8;
  2         6  
  2         9  
1071 40         50 my $buff = [];
1072 40         73 $num =~ s/[^0-9]+//g;
1073 40 100       80 if( $num =~ s/^(\d)(\d{3})$/$2/ )
1074             {
1075 6 100       29 push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '千' );
1076             }
1077 40         71 $num =~ s/^0+([1-9][0-9]*)$/$1/;
1078            
1079 40 100 66     140 unless( !length( $num ) || $num =~ /^0+$/ )
1080             {
1081 39 100       98 if( $num =~ s/^(\d)(\d{2})$/$2/ )
1082             {
1083 7 100       27 push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '百' );
1084             }
1085 39         40 $num =~ s/^0+([1-9][0-9]*)$/$1/;
1086            
1087 39 100 66     117 unless( !length( $num ) || $num =~ /^0+$/ )
1088             {
1089 38 100       88 if( $num =~ s/^(\d)(\d)$/$2/ )
1090             {
1091 22 100       97 push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '十' );
1092             }
1093 38 100       71 $num = '' if( $num == 0 );
1094              
1095 38 100 66     97 unless( !length( $num ) || $num =~ /^0+$/ )
1096             {
1097 31         71 push( @$buff, $KANJI_NUMBERS->[ $num ] );
1098             }
1099             }
1100             }
1101 40         203 return( join( '', @$buff ) );
1102             }
1103              
1104             sub romaji_to_kanji_simple
1105             {
1106 3     3 1 6 my $self = shift( @_ );
1107 3         6 my $num = shift( @_ );
1108 3 50 33     21 return( $num ) if( !defined( $num ) || !length( $num ) );
1109 3         4 my $buff = [];
1110 3         12 foreach( split( //, $num ) )
1111             {
1112 13 100       27 if( $_ !~ /^[0-9]$/ )
1113             {
1114 1         2 push( @$buff, $_ );
1115 1         2 next;
1116             }
1117 12         42 push( @$buff, $KANJI_NUMBERS->[ $_ ] );
1118             }
1119 3         11 return( join( '', @$buff ) );
1120             }
1121              
1122             sub romaji_to_zenkaku
1123             {
1124 63     63 1 11277 my $self = shift( @_ );
1125 63         104 my $num = shift( @_ );
1126 2     2   1970 use utf8;
  2         6  
  2         8  
1127             # Already done
1128 63 50       244 return( $num ) if( $num =~ /^[0123456789]+$/ );
1129 63         74 my $buff = [];
1130 63         145 for( split( //, $num ) )
1131             {
1132 135 50       370 if( /^[0123456789]$/ )
    100          
1133             {
1134 0         0 push( @$buff, $_ );
1135             }
1136             elsif( /^[0-9]$/ )
1137             {
1138 134         288 push( @$buff, $ZENKAKU_NUMBERS->[ $_ ] );
1139             }
1140             else
1141             {
1142 1 50       154 warnings::warn( "Unknown character \"$_\" in number \"$num\" to be cnverted into full width.\n" ) if( warnings::enabled() );
1143 1         4 push( @$buff, $_ );
1144             }
1145             }
1146 63         297 return( join( '', @$buff ) );
1147             }
1148              
1149 0     0 1 0 sub time_zone { return( shift->_set_get( 'time_zone', @_ ) ); }
1150              
1151 0     0 1 0 sub traditional { return( shift->_set_get( 'traditional', @_ ) ); }
1152              
1153 0     0 1 0 sub zenkaku { return( shift->_set_get_zenkaku( 'zenkaku', @_ ) ); }
1154              
1155 82     82 1 164 sub zenkaku_to_romaji { return( shift->_get_pos_in_array( $ZENKAKU_NUMBERS, @_ ) ); }
1156              
1157             sub _dump
1158             {
1159 53     53   84 my $self = shift( @_ );
1160 53         95 my $ref = shift( @_ );
1161 53 50       158 return(1) if( !$self->{debug} );
1162 0         0 foreach my $k ( sort( keys( %$ref ) ) )
1163             {
1164 0         0 printf( STDERR "%-12s: %s\n", $k, $ref->{ $k } );
1165             }
1166 0         0 print( STDERR "-" x 20, "\n" );
1167 0         0 return(1);
1168             }
1169              
1170             sub _get_pos_in_array
1171             {
1172 208     208   299 my $self = shift( @_ );
1173 208         345 my $array = shift( @_ );
1174 208         268 my $num = shift( @_ );
1175 208 50       476 return( $self->error( "I was expecting an array reference, but I got \"$array\"." ) ) if( ref( $array ) ne 'ARRAY' );
1176 208 50       412 return( $self->error( "Array provided is empty!" ) ) if( !scalar( @$array ) );
1177 208 50 33     638 return( $self->error( "No value provided to transcode!" ) ) if( !defined( $num ) || !length( $num ) );
1178 208         231 my $buff = [];
1179 208         427 my( $index1 ) = grep{ $num eq $array->[$_] } 0..$#$array;
  3340         4415  
1180 208 100       682 return( $index1 ) if( length( $index1 ) );
1181            
1182 40         115 for my $c ( split( //, $num ) )
1183             {
1184 80 50       187 if( $c =~ /^[0-9]$/ )
1185             {
1186 0         0 push( @$buff, $c );
1187 0         0 next;
1188             }
1189 80         123 my( $index ) = grep{ $c eq $array->[$_] } 0..$#$array;
  800         1066  
1190 80 50       157 return( $self->error( "Failed to find the corresponding entry for \"$c\"." ) ) if( !length( $index ) );
1191 80         153 push( @$buff, $index );
1192             }
1193 40         136 return( join( '', @$buff ) );
1194             }
1195              
1196             sub _set_get
1197             {
1198 0     0   0 my $self = shift( @_ );
1199 0         0 my $field = shift( @_ );
1200 0 0       0 if( @_ )
1201             {
1202 0         0 $self->{ $field } = shift( @_ );
1203             }
1204 0         0 return( $self->{ $field } );
1205             }
1206              
1207             sub _set_get_zenkaku
1208             {
1209 0     0   0 my $self = shift( @_ );
1210 0         0 my $field = shift( @_ );
1211 0 0       0 if( @_ )
1212             {
1213 0         0 my $v = shift( @_ );
1214 0         0 $self->{ $field } = $v;
1215 0 0       0 if( $field eq 'zenkaku' )
    0          
1216             {
1217 0         0 $self->{hankaku} = !$v;
1218             }
1219             elsif( $field eq 'hankaku' )
1220             {
1221 0         0 $self->{zenkaku} = !$v;
1222             }
1223             }
1224 0         0 return( $self->{ $field } );
1225             }
1226              
1227             # NOTE: DateTime::Format::JP::Era class
1228             {
1229             package
1230             DateTime::Format::JP::Era;
1231             BEGIN
1232             {
1233 2     2   2732 use strict;
  2         4  
  2         76  
1234 2     2   10 use warnings;
  2         5  
  2         219  
1235 2     2   17 use parent qw( Exporter );
  2         4  
  2         14  
1236 2     2   187 use vars qw( $ERROR );
  2         4  
  2         129  
1237 2     2   2841 use DateTime;
  2         1480065  
  2         136  
1238 2     2   25 use DateTime::TimeZone;
  2         5  
  2         129  
1239 2 50   2   15 use constant HAS_LOCAL_TZ => ( eval( qq{DateTime::TimeZone->new( name => 'local' );} ) ? 1 : 0 );
  2         4  
  2         151  
1240             };
1241              
1242 2     2   12412 use strict;
  2         6  
  2         61  
1243 2     2   27 use warnings;
  2         16  
  2         2319  
1244            
1245             # my $era = DateTime::Format::JP::Era->new( $era_dictionary_hash_ref );
1246 59   33 59   542 sub new { return( bless( $_[1] => ( ref( $_[0] ) || $_[0] ) ) ); }
1247            
1248             sub error
1249             {
1250 0     0   0 my $self = shift( @_ );
1251 0 0       0 if( @_ )
1252             {
1253 0 0       0 $self->{error} = $ERROR = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
1254 0 0       0 warnings::warn( $ERROR, "\n" ) if( warnings::enabled( 'DateTime::Format::JP' ) );
1255 0         0 return;
1256             }
1257 0 0       0 return( ref( $self ) ? $self->{error} : $ERROR );
1258             }
1259              
1260 0     0   0 sub end { return( [@{shift->{end}}] ); }
  0         0  
1261              
1262 0     0   0 sub end_datetime { return( shift->_get_datetime( 'end' ) ); }
1263            
1264 12     12   82 sub name { return( shift->{name} ); }
1265            
1266 0     0   0 sub period { return( shift->{period} ); }
1267            
1268 0     0   0 sub reading { return( [@{shift->{reading}}] ); }
  0         0  
1269              
1270 0     0   0 sub start { return( [@{shift->{start}}] ); }
  0         0  
1271            
1272 44     44   142 sub start_datetime { return( shift->_get_datetime( 'start' ) ); }
1273            
1274             sub year
1275             {
1276 14     14   30 my( $self, $dt ) = @_;
1277             # First year is Year 1 of an era no matter when it starts in that year
1278 14         111 return( ( $dt->year + 1 ) - $self->{start}->[0] );
1279             }
1280            
1281             sub _get_datetime
1282             {
1283 44     44   87 my $self = shift( @_ );
1284 44         77 my $field = shift( @_ );
1285 44         77 my $ref = $self->{ $field };
1286 44         50 local $@;
1287             # try-catch
1288             my $rv = eval
1289 44         57 {
1290 44 50 33     247 if( ref( $ref ) eq 'ARRAY' && scalar( @$ref ) == 3 )
1291             {
1292 44         75 my $opts = {};
1293 44         197 @$opts{qw( year month day )} = @$ref;
1294 44         135 @$opts{qw( hour minute second )} = (0,0,0);
1295 44         95 $opts->{time_zone} = ( HAS_LOCAL_TZ ? 'local' : 'UTC' );
1296 44         254 return( DateTime->new( %$opts ) );
1297             }
1298             else
1299             {
1300 0         0 return( DateTime->now( time_zone => ( HAS_LOCAL_TZ ? 'local' : 'UTC' ) ) );
1301             }
1302             };
1303 44 50       19781 if( $@ )
1304             {
1305 0         0 return( $self->error( $@ ) );
1306             }
1307 44         122 return( $rv );
1308             }
1309             }
1310              
1311             1;
1312             # NOTE: POD
1313             __END__
1314              
1315             =encoding utf-8
1316              
1317             =head1 NAME
1318              
1319             DateTime::Format::JP - Japanese DateTime Parser and Formatter
1320              
1321             =head1 SYNOPSIS
1322              
1323             use DateTime::Format::JP;
1324             my $fmt = DateTime::Format::JP->new(
1325             hankaku => 1,
1326             pattern => '%c', # default
1327             traditional => 0,
1328             kanji_number => 0,
1329             zenkaku => 0,
1330             time_zone => 'local',
1331             );
1332             my $dt = DateTime->now;
1333             $dt->set_formatter( $fmt );
1334             # set the encoding in and out to utf8
1335             use open ':std' => ':utf8';
1336             print "$dt\n"; # will print something like 令和3年7月12日午後2:30:20
1337              
1338             my $dt = $fmt->parse_datetime( "令和3年7月12日午後2時30分" );
1339            
1340             my $str = $fmt->format_datetime( $dt );
1341             print "$str\n";
1342              
1343             =head1 VERSION
1344              
1345             v0.1.6
1346              
1347             =head1 DESCRIPTION
1348              
1349             This module is used to parse and format Japanese date and time. It is lightweight and yet versatile.
1350              
1351             It implements 2 main methods: L</parse_datetime> and L</format_datetime> both expect and return decoded utf8 string.
1352              
1353             You can use L<Encode> to decode and encode from perl internal utf8 representation to real utf8 and vice versa.
1354              
1355             =head1 METHODS
1356              
1357             =head2 new
1358              
1359             The constructor accepts the following parameters:
1360              
1361             =over 4
1362              
1363             =item I<hankaku> boolean
1364              
1365             If true, the digits used will be "half-size" (半角), or roman numbers like 1, 2, 3, etc.
1366              
1367             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.
1368              
1369             Defaults to true.
1370              
1371             =item I<pattern> string
1372              
1373             The pattern to use to format the date and time. See below the available L</"PATTERN TOKENS"> and their meanings.
1374              
1375             Defaults to C<%c>
1376              
1377             =item I<traditional> boolean
1378              
1379             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">
1380              
1381             =item I<kanji_number> boolean
1382              
1383             If true, this will have L</format_datetime> use numbers in kanji, such as: 一, 二, 三, 四, etc.
1384              
1385             =item I<zenkaku> boolean
1386              
1387             If true, this will use full-width, ie double-byte Japanese numbers that still look like roman numbers, such as: 1, 2, 3, etc.
1388              
1389             =item I<time_zone> string
1390              
1391             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>
1392              
1393             =back
1394              
1395             =head2 error
1396              
1397             Returns the latest error set, if any.
1398              
1399             All method in this module return C<undef> upon error and set an error that can be retrieved with this method.
1400              
1401             =head2 format_datetime
1402              
1403             Takes a L<DateTime> object and returns a formatted date and time based on the pattern specified, which defaults to C<%c>.
1404              
1405             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.
1406              
1407             See below L</"PATTERN TOKENS"> for the available tokens and their meanings.
1408              
1409             =head2 hankaku
1410              
1411             Sets or gets the boolean value for I<hankaku>.
1412              
1413             =head2 kanji_number
1414              
1415             Sets or gets the boolean value for I<kanji_number>.
1416              
1417             =head2 parse_datetime
1418              
1419             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>
1420              
1421             =head2 time_zone
1422              
1423             Sets or gets the string representing the time zone to use when creating L<DateTime> object. This is used by L</parse_datetime>
1424              
1425             =head2 traditional
1426              
1427             Sets or gets the boolean value for I<traditional>.
1428              
1429             =head2 zenkaku
1430              
1431             Sets or gets the boolean value for I<zenkaku>.
1432              
1433             =head1 SUPPORT METHODS
1434              
1435             =head2 kanji_to_romaji
1436              
1437             Takes a number in kanji and returns its equivalent value in roman (regular) numbers.
1438              
1439             =head2 lookup_era
1440              
1441             Takes an Japanese era in kanji and returns an C<DateTime::Format::JP::Era> object
1442              
1443             =head2 lookup_era_by_date
1444              
1445             Takes a L<DateTime> object and returns a C<DateTime::Format::JP::Era> object
1446              
1447             =head2 make_datetime
1448              
1449             Returns a L<DateTime> based on parameters provided.
1450              
1451             =head2 romaji_to_kanji
1452              
1453             Takes a number and returns its equivalent representation in Japanese kanji. Thus, for example, C<1234> would be returned as C<千二百三十四>
1454              
1455             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.
1456              
1457             =head2 romaji_to_kanji_simple
1458              
1459             Replaces numbers with their Japanese kanji equivalent. It does not use numerals.
1460              
1461             =head2 romaji_to_zenkaku
1462              
1463             Takes a number and returns its equivalent representation in double-byte Japanese numbers. Thus, for example, C<1234> would be returned as C<1234>
1464              
1465             =head2 zenkaku_to_romaji
1466              
1467             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>
1468              
1469             =head1 PATTERN TOKENS
1470              
1471             Here are below the available tokens for formatting and the value they represent.
1472              
1473             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.
1474              
1475             =over 4
1476              
1477             =item * %%
1478              
1479             The % character.
1480              
1481             =item * %a
1482              
1483             The weekday name in abbreviated form such as: 月, 火, 水, 木, 金, 土, 日
1484              
1485             =item * %A
1486              
1487             The weekday name in its long form such as: 月曜日, 火曜日, 水曜日, 木曜日, 金曜日, 土曜日, 日曜日
1488              
1489             =item * %b
1490              
1491             The month name, such as 1月, 2月, etc... 12月 using regular digits.
1492              
1493             =item * %B
1494              
1495             The month name using full width (全角) digits, such as 1月, 2月, etc... 12月
1496              
1497             =item * %h
1498              
1499             The month name using kanjis for numbers, such as 一月, 二月, etc... 十二月
1500              
1501             =item * %c
1502              
1503             The datetime format in the Japanese standard most usual form. For example for C<12th July 2021 14:17:30> this would be:
1504              
1505             令和3年7月12日午後2:17:30
1506              
1507             However, if I<traditional> is true, then it would rather be:
1508              
1509             令和3年7月12日午後2時17分30秒
1510              
1511             And if I<zenkaku> is true, it will use double-byte numbers instead:
1512              
1513             令和3年7月12日午後2時17分30秒
1514              
1515             And if I<kanji_number> is true, it will then be:
1516              
1517             令和三年七月十二日午後二時十七分三十秒
1518              
1519             =item * %C
1520              
1521             The century number (year/100) as a 2-digit integer. This is the same as L<DateTime/strftime>
1522              
1523             =item * %d or %e
1524              
1525             The day of month (1-31).
1526              
1527             However, if I<zenkaku> is true, then it would rather be with full width (全角) numbers: 1-31
1528              
1529             And if I<kanji_number> is true, it will then be with numbers in kanji: 一, 二, etc.. 十, 十一, etc..
1530              
1531             =item * %D
1532              
1533             Equivalent to C<%E%y年%m月%d日>
1534              
1535             This is the Japanese style date including with the leading era name.
1536              
1537             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.
1538              
1539             See %F for an equivalent date using the Gregorian years rather than the Japanese era.
1540              
1541             =item * %E
1542              
1543             This extension is the Japanese era, such as C<令和> (i.e. "reiwa": the current era)
1544              
1545             =item * %F
1546              
1547             Equivalent to C<%Y年%m月%d日>
1548              
1549             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.
1550              
1551             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<二千二十一>
1552              
1553             =item * %g
1554              
1555             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>
1556              
1557             =item * %G
1558              
1559             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.
1560              
1561             This uses regular digits and is the same as L<DateTime/strftime>
1562              
1563             =item * %H
1564              
1565             The hour: 0-23
1566              
1567             If I<traditional> is enabled, this would rather be C<0-23時>
1568              
1569             However, if I<zenkaku> is true, then it would rather use full width (全角) numbers: C<0-23時>
1570              
1571             And if I<kanji_number> is true, it will then be something like C<十時>
1572              
1573             =item * %I
1574              
1575             The hour on a 12-hour clock (1-12).
1576              
1577             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.
1578              
1579             =item * %j
1580              
1581             The day number in the year (1-366). This uses regular digits and is the same as L<DateTime/strftime>
1582              
1583             =item * %m
1584              
1585             The month number (1-12).
1586              
1587             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.
1588              
1589             =item * %M
1590              
1591             The minute: 0-59
1592              
1593             If I<traditional> is enabled, this would rather be C<0-59分>
1594              
1595             However, if I<zenkaku> is true, then it would rather use full width (全角) numbers: C<0-59分>
1596              
1597             And if I<kanji_number> is true, it will then be something like C<十分>
1598              
1599             =item * %n
1600              
1601             Arbitrary whitespace. Same as in L<DateTime/strftime>
1602              
1603             =item * %N
1604              
1605             Nanoseconds. For other sub-second values use C<%[number]N>.
1606              
1607             This is a pass-through directly to L<DateTime/strftime>
1608              
1609             =item * %p or %P
1610              
1611             Either produces the same result.
1612              
1613             Either AM (午前) or PM (午後) according to the given time value. Noon is treated as pm "午後" and midnight as am "午前".
1614              
1615             =item * %r
1616              
1617             Equivalent to C<%p%I:%M:%S>
1618              
1619             Note that if I<zenkaku> is true, the semi-colon used will be double-byte: C<:>
1620              
1621             Also if you use this, do not enable I<kanji_number>, because the result would be weird, something like:
1622              
1623             午後二:十四:三十 # 2:14:30 in this example
1624              
1625             =item * %R
1626              
1627             Equivalent to C<%H:%M>
1628              
1629             Note that if I<zenkaku> is true, the semi-colon used will be double-byte: C<:>
1630              
1631             Juste like for C<%r>, avoid enabling I<kanji_number> if you use this token.
1632              
1633             =item * %s
1634              
1635             Number of seconds since the Epoch.
1636              
1637             If I<zenkaku> is enabled, this will return the value as double-byte number.
1638              
1639             =item * %S
1640              
1641             The second: C<0-60>
1642              
1643             If I<traditional> is enabled, this would rather be C<0-60秒>
1644              
1645             However, if I<zenkaku> is true, then it would rather use full width (全角) numbers: C<0-60秒>
1646              
1647             And if I<kanji_number> is true, it will then be something like C<六十秒>
1648              
1649             (60 may occur for leap seconds. See L<DateTime::LeapSecond>).
1650              
1651             =item * %t
1652              
1653             Arbitrary whitespace. Same as in L<DateTime/strftime>
1654              
1655             =item * %T
1656              
1657             Equivalent to C<%H:%M:%S>
1658              
1659             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:
1660              
1661             14:20:30
1662              
1663             =item * %U
1664              
1665             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.
1666              
1667             If I<zenkaku> is enabled, it will return a double-byte number instead.
1668              
1669             =item * %u
1670              
1671             The weekday number (1-7) with Monday (月曜日) = 1, 火曜日 = 2, 水曜日 = 3, 木曜日 = 4, 金曜日 = 5, 土曜日 = 6, 日曜日 = 7
1672              
1673             If I<zenkaku> is enabled, it will return a double-byte number instead.
1674              
1675             This is the C<DateTime> standard.
1676              
1677             =item * %w
1678              
1679             The weekday number (0-6) with Sunday = 0.
1680              
1681             If I<zenkaku> is enabled, it will return a double-byte number instead.
1682              
1683             =item * %W
1684              
1685             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.
1686              
1687             If I<zenkaku> is enabled, it will return a double-byte number instead.
1688              
1689             =item * %x
1690              
1691             The date format in the standard most usual form. For example for 12th July 2021 this would be:
1692              
1693             令和3年7月12日
1694              
1695             However, if I<zenkaku> is true, then it would rather be:
1696              
1697             令和3年7月12日
1698              
1699             And if I<kanji_number> is true, it will then be:
1700              
1701             令和三年七月十二日
1702              
1703             =item * %X
1704              
1705             The time format in the standard most usual form. For example for C<14:17:30> this would be:
1706              
1707             午後2:17:30
1708              
1709             And if I<zenkaku> is enabled, it would rather use a double-byte numbers and separator:
1710              
1711             午後2:17:30
1712              
1713             However, if I<traditional> is true, then it would rather be:
1714              
1715             午後2時17分30秒
1716              
1717             And if I<kanji_number> is true, it will then be:
1718              
1719             午後二時十七分三十秒
1720              
1721             =item * %y
1722              
1723             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>
1724              
1725             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.
1726              
1727             =item * %Y
1728              
1729             A 4-digit year, including century (for example, 1991).
1730              
1731             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.
1732              
1733             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<二千二十一>
1734              
1735             =item * %z
1736              
1737             An RFC-822/ISO 8601 standard time zone specification. (For example
1738             +1100)
1739              
1740             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<+〇九〇〇>
1741              
1742             =item * %Z
1743              
1744             The timezone name. (For example EST -- which is ambiguous). This is the same as L<DateTime/strftime>
1745              
1746             =back
1747              
1748             =head1 HISTORICAL NOTE
1749              
1750             Japanese eras, also known as 元号 (gengo) or 年号 (nengo) form one of the two parts of a Japanese year in any given date.
1751              
1752             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.
1753              
1754             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.
1755              
1756             More on this L<here|https://en.wikipedia.org/wiki/Japanese_era_name>
1757              
1758             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.
1759              
1760             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.
1761              
1762             Thus if you want a Japanese date using era during those two periods, you will get and empty era.
1763              
1764             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)>
1765              
1766             =head1 AUTHOR
1767              
1768             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
1769              
1770             =head1 SEE ALSO
1771              
1772             L<DateTime>
1773              
1774             =head1 COPYRIGHT & LICENSE
1775              
1776             Copyright(c) 2021 DEGUEST Pte. Ltd. DEGUEST Pte. Ltd.
1777              
1778             You can use, copy, modify and redistribute this package and associated
1779             files under the same terms as Perl itself.
1780              
1781             =cut