File Coverage

lib/DateTime/Format/JP.pm
Criterion Covered Total %
statement 455 679 67.0
branch 226 500 45.2
condition 84 220 38.1
subroutine 85 107 79.4
pod 17 18 94.4
total 867 1524 56.8


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