lib/DateTime/Format/JP.pm

filter: Statementstmt 83.1% 413 / 497 Branchbran 68.4% 178 / 260 Conditioncond 49.6% 76 / 153 MC/DCmcdc 28.9% 24 / 83 Subroutinesub 81.4% 79 / 97 Podpod 94.4% 17 / 18 totaltotal 71.0% 787 / 1108 CC 202 SCAR 26.2
CC
202
Cov
73%
lookup_era_by_date
65.3
error
30.0
error
30.0
CRAP 13.7
↑ Summary
1 ##----------------------------------------------------------------------------
2 ## Japanese DateTime Parser/Formatter - ~/lib/DateTime/Format/JP.pm
3 ## Version v0.1.7
4 ## Copyright(c) 2024 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/07/18
7 ## Modified 2026/04/24
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package DateTime::Format::JP;
14 BEGIN
15 2 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ use parent qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 $VERSION $DATETIME_PATTERN_1_RE $DATETIME_PATTERN_2_RE $DATETIME_PATTERN_3_RE $DICT
22 $ZENKAKU_NUMBERS $KANJI_NUMBERS $ZENKAKU_TO_ROMAN $KANJI_TO_ROMAN $WEEKDAYS
23 $WEEKDAYS_RE $TIME_RE $TIME_ZENKAKU_RE $TIME_KANJI_RE $ERROR
24 2 );
25 2 our $VERSION = 'v0.1.7';
26 2 our $DICT = [];
27 2 our $ZENKAKU_NUMBERS = [];
28 2 our $KANJI_NUMBERS = [];
29 2 our $ZENKAKU_TO_ROMAN= {};
30 2 our $KANJI_TO_ROMAN = {};
31 2 our $WEEKDAYS = [];
32 2 our $WEEKDAYS_RE;
33 2 our $TIME_RE;
34 2 our( $DATETIME_PATTERN_1_RE, $DATETIME_PATTERN_2_RE, $DATETIME_PATTERN_3_RE )
35 };
36  
37 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 {
41 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 $ZENKAKU_NUMBERS = [qw(0 1 2 3 4 5 6 7 8 9)];
43 2 $KANJI_NUMBERS = [qw(〇 一 二 三 四 五 六 七 八 九 十 十一 十二 十三 十四 十五 十六 十七 十八 十九)];
44 2 $WEEKDAYS = [qw( 月 火 水 木 金 土 日 )];
45 2 for( 0..9 )
46 {
47 20 $ZENKAKU_TO_ROMAN->{ $ZENKAKU_NUMBERS->[$_] } = $_;
48 20 $KANJI_TO_ROMAN->{ $KANJI_NUMBERS->[$_] } = $_;
49 }
50 2 $WEEKDAYS_RE = qr/(?:月|火|水|木|金|土|日)/;
51 2 $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 2 $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 2 $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 2 $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 2 $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 2 $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 2 $DICT =
167 [
168 { name => '大化', period => '飛鳥時代', reading => ['たいか'], start => [645,7,17], end => [650,3,22] }, # 6年 from 645/7/17 until 650/3/22
169 { name => '白雉', period => '飛鳥時代', reading => ['はくち','びゃくち','しらきぎす'], start => [650,3,22], end => [654,11,24] }, # 5年 from 650/3/22 until 654/11/24
170 { name => '', period => '飛鳥時代', reading => [''], start => [654,11,24], end => [686,8,14] }, # 32年 from 654/11/24 until 686/8/14
171 { name => '朱鳥', period => '飛鳥時代', reading => ['しゅちょう','すちょう','あかみとり'], start => [686,8,14], end => [686,10,1] }, # 1年 from 686/8/14 until 686/10/1
172 { name => '', period => '飛鳥時代', reading => [''], start => [686,10,1], end => [701,5,3] }, # 15年 from 686/10/1 until 701/5/3
173 { name => '大宝', period => '飛鳥時代', reading => ['たいほう','だいほう'], start => [701,5,3], end => [704,6,16] }, # 4年 from 701/5/3 until 704/6/16
174 { name => '慶雲', period => '飛鳥時代', reading => ['けいうん','きょううん'], start => [704,6,16], end => [708,2,7] }, # 5年 from 704/6/16 until 708/2/7
175 { name => '和銅', period => '飛鳥時代', reading => ['わどう'], start => [708,2,7], end => [715,10,3] }, # 8年 from 708/2/7 until 715/10/3
176 { name => '霊亀', period => '奈良時代', reading => ['れいき'], start => [715,10,3], end => [717,12,24] }, # 3年 from 715/10/3 until 717/12/24
177 { name => '養老', period => '奈良時代', reading => ['ようろう'], start => [717,12,24], end => [724,3,3] }, # 8年 from 717/12/24 until 724/3/3
178 { name => '神亀', period => '奈良時代', reading => ['じんき'], start => [724,3,3], end => [729,9,2] }, # 6年 from 724/3/3 until 729/9/2
179 { name => '天平', period => '奈良時代', reading => ['てんぴょう'], start => [729,9,2], end => [749,5,4] }, # 21年 from 729/9/2 until 749/5/4
180 { name => '天平感宝', period => '奈良時代', reading => ['てんぴょうかんぽう'], start => [749,5,4], end => [749,8,19] }, # 1年 from 749/5/4 until 749/8/19
181 { name => '天平勝宝', period => '奈良時代', reading => ['てんぴょうしょうほう'], start => [749,8,19], end => [757,9,6] }, # 9年 from 749/8/19 until 757/9/6
182 { name => '天平宝字', period => '奈良時代', reading => ['てんぴょうほうじ'], start => [757,9,6], end => [765,2,1] }, # 9年 from 757/9/6 until 765/2/1
183 { name => '天平神護', period => '奈良時代', reading => ['てんぴょうじんご'], start => [765,2,1], end => [767,9,13] }, # 3年 from 765/2/1 until 767/9/13
184 { name => '神護景雲', period => '奈良時代', reading => ['じんごけいうん'], start => [767,9,13], end => [770,10,23] }, # 4年 from 767/9/13 until 770/10/23
185 { name => '宝亀', period => '奈良時代', reading => ['ほうき'], start => [770,10,23], end => [781,1,30] }, # 12年 from 770/10/23 until 781/1/30
186 { name => '天応', period => '奈良時代', reading => ['てんおう','てんのう'], start => [781,1,30], end => [782,9,30] }, # 2年 from 781/1/30 until 782/9/30
187 { name => '延暦', period => '奈良時代', reading => ['えんりゃく'], start => [782,9,30], end => [806,6,8] }, # 25年 from 782/9/30 until 806/6/8
188 { name => '大同', period => '平安時代', reading => ['だいどう'], start => [806,6,8], end => [810,10,20] }, # 5年 from 806/6/8 until 810/10/20
189 { name => '弘仁', period => '平安時代', reading => ['こうにん'], start => [810,10,20], end => [824,2,8] }, # 15年 from 810/10/20 until 824/2/8
190 { name => '天長', period => '平安時代', reading => ['てんちょう'], start => [824,2,8], end => [834,2,14] }, # 11年 from 824/2/8 until 834/2/14
191 { name => '承和', period => '平安時代', reading => ['じょうわ','しょうわ'], start => [834,2,14], end => [848,7,16] }, # 15年 from 834/2/14 until 848/7/16
192 { name => '嘉祥', period => '平安時代', reading => ['かしょう','かじょう'], start => [848,7,16], end => [851,6,1] }, # 4年 from 848/7/16 until 851/6/1
193 { name => '仁寿', period => '平安時代', reading => ['にんじゅ'], start => [851,6,1], end => [854,12,23] }, # 4年 from 851/6/1 until 854/12/23
194 { name => '斉衡', period => '平安時代', reading => ['さいこう'], start => [854,12,23], end => [857,3,20] }, # 4年 from 854/12/23 until 857/3/20
195 { name => '天安', period => '平安時代', reading => ['てんあん','てんなん'], start => [857,3,20], end => [859,5,20] }, # 3年 from 857/3/20 until 859/5/20
196 { name => '貞観', period => '平安時代', reading => ['じょうがん'], start => [859,5,20], end => [877,6,1] }, # 19年 from 859/5/20 until 877/6/1
197 { name => '元慶', period => '平安時代', reading => ['がんぎょう'], start => [877,6,1], end => [885,3,11] }, # 9年 from 877/6/1 until 885/3/11
198 { name => '仁和', period => '平安時代', reading => ['にんな','にんわ'], start => [885,3,11], end => [889,5,30] }, # 5年 from 885/3/11 until 889/5/30
199 { name => '寛平', period => '平安時代', reading => ['かんぴょう','かんぺい','かんへい'], start => [889,5,30], end => [898,5,20] }, # 10年 from 889/5/30 until 898/5/20
200 { name => '昌泰', period => '平安時代', reading => ['しょうたい'], start => [898,5,20], end => [901,8,31] }, # 4年 from 898/5/20 until 901/8/31
201 { name => '延喜', period => '平安時代', reading => ['えんぎ'], start => [901,8,31], end => [923,5,29] }, # 23年 from 901/8/31 until 923/5/29
202 { name => '延長', period => '平安時代', reading => ['えんちょう'], start => [923,5,29], end => [931,5,16] }, # 9年 from 923/5/29 until 931/5/16
203 { name => '承平', period => '平安時代', reading => ['じょうへい','しょうへい'], start => [931,5,16], end => [938,6,22] }, # 8年 from 931/5/16 until 938/6/22
204 { name => '天慶', period => '平安時代', reading => ['てんぎょう','てんきょう'], start => [938,6,22], end => [947,5,15] }, # 10年 from 938/6/22 until 947/5/15
205 { name => '天暦', period => '平安時代', reading => ['てんりゃく'], start => [947,5,15], end => [957,11,21] }, # 11年 from 947/5/15 until 957/11/21
206 { name => '天徳', period => '平安時代', reading => ['てんとく'], start => [957,11,21], end => [961,3,5] }, # 5年 from 957/11/21 until 961/3/5
207 { name => '応和', period => '平安時代', reading => ['おうわ'], start => [961,3,5], end => [964,8,19] }, # 4年 from 961/3/5 until 964/8/19
208 { name => '康保', period => '平安時代', reading => ['こうほう'], start => [964,8,19], end => [968,9,8] }, # 5年 from 964/8/19 until 968/9/8
209 { name => '安和', period => '平安時代', reading => ['あんな','あんわ'], start => [968,9,8], end => [970,5,3] }, # 3年 from 968/9/8 until 970/5/3
210 { name => '天禄', period => '平安時代', reading => ['てんろく'], start => [970,5,3], end => [974,1,16] }, # 4年 from 970/5/3 until 974/1/16
211 { name => '天延', period => '平安時代', reading => ['てんえん'], start => [974,1,16], end => [976,8,11] }, # 4年 from 974/1/16 until 976/8/11
212 { name => '貞元', period => '平安時代', reading => ['じょうげん'], start => [976,8,11], end => [978,12,31] }, # 3年 from 976/8/11 until 978/12/31
213 { name => '天元', period => '平安時代', reading => ['てんげん'], start => [978,12,31], end => [983,5,29] }, # 6年 from 978/12/31 until 983/5/29
214 { name => '永観', period => '平安時代', reading => ['えいかん'], start => [983,5,29], end => [985,5,19] }, # 3年 from 983/5/29 until 985/5/19
215 { name => '寛和', period => '平安時代', reading => ['かんな','かんわ'], start => [985,5,19], end => [987,5,5] }, # 3年 from 985/5/19 until 987/5/5
216 { name => '永延', period => '平安時代', reading => ['えいえん'], start => [987,5,5], end => [989,9,10] }, # 3年 from 987/5/5 until 989/9/10
217 { name => '永祚', period => '平安時代', reading => ['えいそ'], start => [989,9,10], end => [990,11,26] }, # 2年 from 989/9/10 until 990/11/26
218 { name => '正暦', period => '平安時代', reading => ['しょうりゃく'], start => [990,11,26], end => [995,3,25] }, # 6年 from 990/11/26 until 995/3/25
219 { name => '長徳', period => '平安時代', reading => ['ちょうとく'], start => [995,3,25], end => [999,2,1] }, # 5年 from 995/3/25 until 999/2/1
220 { name => '長保', period => '平安時代', reading => ['ちょうほう'], start => [999,2,1], end => [1004,8,8] }, # 6年 from 999/2/1 until 1004/8/8
221 { name => '寛弘', period => '平安時代', reading => ['かんこう'], start => [1004,8,8], end => [1013,2,8] }, # 9年 from 1004/8/8 until 1013/2/8
222 { name => '長和', period => '平安時代', reading => ['ちょうわ'], start => [1013,2,8], end => [1017,5,21] }, # 6年 from 1013/2/8 until 1017/5/21
223 { name => '寛仁', period => '平安時代', reading => ['かんにん'], start => [1017,5,21], end => [1021,3,17] }, # 5年 from 1017/5/21 until 1021/3/17
224 { name => '治安', period => '平安時代', reading => ['じあん'], start => [1021,3,17], end => [1024,8,19] }, # 4年 from 1021/3/17 until 1024/8/19
225 { name => '万寿', period => '平安時代', reading => ['まんじゅ'], start => [1024,8,19], end => [1028,8,18] }, # 5年 from 1024/8/19 until 1028/8/18
226 { name => '長元', period => '平安時代', reading => ['ちょうげん'], start => [1028,8,18], end => [1037,5,9] }, # 10年 from 1028/8/18 until 1037/5/9
227 { name => '長暦', period => '平安時代', reading => ['ちょうりゃく'], start => [1037,5,9], end => [1040,12,16] }, # 4年 from 1037/5/9 until 1040/12/16
228 { name => '長久', period => '平安時代', reading => ['ちょうきゅう'], start => [1040,12,16], end => [1044,12,16] }, # 5年 from 1040/12/16 until 1044/12/16
229 { name => '寛徳', period => '平安時代', reading => ['かんとく'], start => [1044,12,16], end => [1046,5,22] }, # 3年 from 1044/12/16 until 1046/5/22
230 { name => '永承', period => '平安時代', reading => ['えいしょう','えいじょう'], start => [1046,5,22], end => [1053,2,2] }, # 8年 from 1046/5/22 until 1053/2/2
231 { name => '天喜', period => '平安時代', reading => ['てんぎ','てんき'], start => [1053,2,2], end => [1058,9,19] }, # 6年 from 1053/2/2 until 1058/9/19
232 { name => '康平', period => '平安時代', reading => ['こうへい'], start => [1058,9,19], end => [1065,9,4] }, # 8年 from 1058/9/19 until 1065/9/4
233 { name => '治暦', period => '平安時代', reading => ['じりゃく'], start => [1065,9,4], end => [1069,5,6] }, # 5年 from 1065/9/4 until 1069/5/6
234 { name => '延久', period => '平安時代', reading => ['えんきゅう'], start => [1069,5,6], end => [1074,9,16] }, # 6年 from 1069/5/6 until 1074/9/16
235 { name => '承保', period => '平安時代', reading => ['じょうほう','しょうほう'], start => [1074,9,16], end => [1077,12,5] }, # 4年 from 1074/9/16 until 1077/12/5
236 { name => '承暦', period => '平安時代', reading => ['じょうりゃく','しょうりゃく'], start => [1077,12,5], end => [1081,3,22] }, # 5年 from 1077/12/5 until 1081/3/22
237 { name => '永保', period => '平安時代', reading => ['えいほう'], start => [1081,3,22], end => [1084,3,15] }, # 4年 from 1081/3/22 until 1084/3/15
238 { name => '応徳', period => '平安時代', reading => ['おうとく'], start => [1084,3,15], end => [1087,5,11] }, # 4年 from 1084/3/15 until 1087/5/11
239 { name => '寛治', period => '平安時代', reading => ['かんじ'], start => [1087,5,11], end => [1095,1,23] }, # 8年 from 1087/5/11 until 1095/1/23
240 { name => '嘉保', period => '平安時代', reading => ['かほう'], start => [1095,1,23], end => [1097,1,3] }, # 3年 from 1095/1/23 until 1097/1/3
241 { name => '永長', period => '平安時代', reading => ['えいちょう'], start => [1097,1,3], end => [1097,12,27] }, # 2年 from 1097/1/3 until 1097/12/27
242 { name => '承徳', period => '平安時代', reading => ['じょうとく','しょうとく'], start => [1097,12,27], end => [1099,9,15] }, # 3年 from 1097/12/27 until 1099/9/15
243 { name => '康和', period => '平安時代', reading => ['こうわ'], start => [1099,9,15], end => [1104,3,8] }, # 6年 from 1099/9/15 until 1104/3/8
244 { name => '長治', period => '平安時代', reading => ['ちょうじ'], start => [1104,3,8], end => [1106,5,13] }, # 3年 from 1104/3/8 until 1106/5/13
245 { name => '嘉承', period => '平安時代', reading => ['かしょう','かじょう'], start => [1106,5,13], end => [1108,9,9] }, # 3年 from 1106/5/13 until 1108/9/9
246 { name => '天仁', period => '平安時代', reading => ['てんにん'], start => [1108,9,9], end => [1110,7,31] }, # 3年 from 1108/9/9 until 1110/7/31
247 { name => '天永', period => '平安時代', reading => ['てんえい'], start => [1110,7,31], end => [1113,8,25] }, # 4年 from 1110/7/31 until 1113/8/25
248 { name => '永久', period => '平安時代', reading => ['えいきゅう'], start => [1113,8,25], end => [1118,4,25] }, # 6年 from 1113/8/25 until 1118/4/25
249 { name => '元永', period => '平安時代', reading => ['げんえい'], start => [1118,4,25], end => [1120,5,9] }, # 3年 from 1118/4/25 until 1120/5/9
250 { name => '保安', period => '平安時代', reading => ['ほうあん'], start => [1120,5,9], end => [1124,5,18] }, # 5年 from 1120/5/9 until 1124/5/18
251 { name => '天治', period => '平安時代', reading => ['てんじ'], start => [1124,5,18], end => [1126,2,15] }, # 3年 from 1124/5/18 until 1126/2/15
252 { name => '大治', period => '平安時代', reading => ['だいじ'], start => [1126,2,15], end => [1131,2,28] }, # 6年 from 1126/2/15 until 1131/2/28
253 { name => '天承', period => '平安時代', reading => ['てんしょう','てんじょう'], start => [1131,2,28], end => [1132,9,21] }, # 2年 from 1131/2/28 until 1132/9/21
254 { name => '長承', period => '平安時代', reading => ['ちょうしょう'], start => [1132,9,21], end => [1135,6,10] }, # 4年 from 1132/9/21 until 1135/6/10
255 { name => '保延', period => '平安時代', reading => ['ほうえん'], start => [1135,6,10], end => [1141,8,13] }, # 7年 from 1135/6/10 until 1141/8/13
256 { name => '永治', period => '平安時代', reading => ['えいじ'], start => [1141,8,13], end => [1142,5,25] }, # 2年 from 1141/8/13 until 1142/5/25
257 { name => '康治', period => '平安時代', reading => ['こうじ'], start => [1142,5,25], end => [1144,3,28] }, # 3年 from 1142/5/25 until 1144/3/28
258 { name => '天養', period => '平安時代', reading => ['てんよう'], start => [1144,3,28], end => [1145,8,12] }, # 2年 from 1144/3/28 until 1145/8/12
259 { name => '久安', period => '平安時代', reading => ['きゅうあん'], start => [1145,8,12], end => [1151,2,14] }, # 7年 from 1145/8/12 until 1151/2/14
260 { name => '仁平', period => '平安時代', reading => ['にんぺい','にんぴょう'], start => [1151,2,14], end => [1154,12,4] }, # 4年 from 1151/2/14 until 1154/12/4
261 { name => '久寿', period => '平安時代', reading => ['きゅうじゅ'], start => [1154,12,4], end => [1156,5,18] }, # 3年 from 1154/12/4 until 1156/5/18
262 { name => '保元', period => '平安時代', reading => ['ほうげん'], start => [1156,5,18], end => [1159,5,9] }, # 4年 from 1156/5/18 until 1159/5/9
263 { name => '平治', period => '平安時代', reading => ['へいじ'], start => [1159,5,9], end => [1160,2,18] }, # 2年 from 1159/5/9 until 1160/2/18
264 { name => '永暦', period => '平安時代', reading => ['えいりゃく'], start => [1160,2,18], end => [1161,9,24] }, # 2年 from 1160/2/18 until 1161/9/24
265 { name => '応保', period => '平安時代', reading => ['おうほう','おうほ'], start => [1161,9,24], end => [1163,5,4] }, # 3年 from 1161/9/24 until 1163/5/4
266 { name => '長寛', period => '平安時代', reading => ['ちょうかん'], start => [1163,5,4], end => [1165,7,14] }, # 3年 from 1163/5/4 until 1165/7/14
267 { name => '永万', period => '平安時代', reading => ['えいまん'], start => [1165,7,14], end => [1166,9,23] }, # 2年 from 1165/7/14 until 1166/9/23
268 { name => '仁安', period => '平安時代', reading => ['にんあん'], start => [1166,9,23], end => [1169,5,6] }, # 4年 from 1166/9/23 until 1169/5/6
269 { name => '嘉応', period => '平安時代', reading => ['かおう'], start => [1169,5,6], end => [1171,5,27] }, # 3年 from 1169/5/6 until 1171/5/27
270 { name => '承安', period => '平安時代', reading => ['じょうあん'], start => [1171,5,27], end => [1175,8,16] }, # 5年 from 1171/5/27 until 1175/8/16
271 { name => '安元', period => '平安時代', reading => ['あんげん'], start => [1175,8,16], end => [1177,8,29] }, # 3年 from 1175/8/16 until 1177/8/29
272 { name => '治承', period => '平安時代', reading => ['じしょう'], start => [1177,8,29], end => [1181,8,25] }, # 5年 from 1177/8/29 until 1181/8/25
273 { name => '養和', period => '平安時代', reading => ['ようわ'], start => [1181,8,25], end => [1182,6,29] }, # 2年 from 1181/8/25 until 1182/6/29
274 { name => '寿永', period => '平安時代', reading => ['じゅえい'], start => [1182,6,29], end => [1184,5,27] }, # 3年 from 1182/6/29 until 1184/5/27
275 { name => '元暦', period => '平安時代', reading => ['げんりゃく'], start => [1184,5,27], end => [1185,9,9] }, # 2年 from 1184/5/27 until 1185/9/9
276 { name => '文治', period => '鎌倉時代', reading => ['ぶんじ'], start => [1185,9,9], end => [1190,5,16] }, # 6年 from 1185/9/9 until 1190/5/16
277 { name => '建久', period => '鎌倉時代', reading => ['けんきゅう'], start => [1190,5,16], end => [1199,5,23] }, # 10年 from 1190/5/16 until 1199/5/23
278 { name => '正治', period => '鎌倉時代', reading => ['しょうじ'], start => [1199,5,23], end => [1201,3,19] }, # 3年 from 1199/5/23 until 1201/3/19
279 { name => '建仁', period => '鎌倉時代', reading => ['けんにん'], start => [1201,3,19], end => [1204,3,23] }, # 4年 from 1201/3/19 until 1204/3/23
280 { name => '元久', period => '鎌倉時代', reading => ['げんきゅう'], start => [1204,3,23], end => [1206,6,5] }, # 3年 from 1204/3/23 until 1206/6/5
281 { name => '建永', period => '鎌倉時代', reading => ['けんえい'], start => [1206,6,5], end => [1207,11,16] }, # 2年 from 1206/6/5 until 1207/11/16
282 { name => '承元', period => '鎌倉時代', reading => ['じょうげん'], start => [1207,11,16], end => [1211,4,23] }, # 5年 from 1207/11/16 until 1211/4/23
283 { name => '建暦', period => '鎌倉時代', reading => ['けんりゃく'], start => [1211,4,23], end => [1214,1,18] }, # 3年 from 1211/4/23 until 1214/1/18
284 { name => '建保', period => '鎌倉時代', reading => ['けんぽう'], start => [1214,1,18], end => [1219,5,27] }, # 7年 from 1214/1/18 until 1219/5/27
285 { name => '承久', period => '鎌倉時代', reading => ['じょうきゅう'], start => [1219,5,27], end => [1222,5,25] }, # 4年 from 1219/5/27 until 1222/5/25
286 { name => '貞応', period => '鎌倉時代', reading => ['じょうおう'], start => [1222,5,25], end => [1224,12,31] }, # 3年 from 1222/5/25 until 1224/12/31
287 { name => '元仁', period => '鎌倉時代', reading => ['げんにん'], start => [1224,12,31], end => [1225,5,28] }, # 2年 from 1224/12/31 until 1225/5/28
288 { name => '嘉禄', period => '鎌倉時代', reading => ['かろく'], start => [1225,5,28], end => [1228,1,18] }, # 3年 from 1225/5/28 until 1228/1/18
289 { name => '安貞', period => '鎌倉時代', reading => ['あんてい'], start => [1228,1,18], end => [1229,3,31] }, # 3年 from 1228/1/18 until 1229/3/31
290 { name => '寛喜', period => '鎌倉時代', reading => ['かんぎ'], start => [1229,3,31], end => [1232,4,23] }, # 4年 from 1229/3/31 until 1232/4/23
291 { name => '貞永', period => '鎌倉時代', reading => ['じょうえい'], start => [1232,4,23], end => [1233,5,25] }, # 2年 from 1232/4/23 until 1233/5/25
292 { name => '天福', period => '鎌倉時代', reading => ['てんぷく'], start => [1233,5,25], end => [1234,11,27] }, # 2年 from 1233/5/25 until 1234/11/27
293 { name => '文暦', period => '鎌倉時代', reading => ['ぶんりゃく'], start => [1234,11,27], end => [1235,11,1] }, # 2年 from 1234/11/27 until 1235/11/1
294 { name => '嘉禎', period => '鎌倉時代', reading => ['かてい'], start => [1235,11,1], end => [1238,12,30] }, # 4年 from 1235/11/1 until 1238/12/30
295 { name => '暦仁', period => '鎌倉時代', reading => ['りゃくにん'], start => [1238,12,30], end => [1239,3,13] }, # 2年 from 1238/12/30 until 1239/3/13
296 { name => '延応', period => '鎌倉時代', reading => ['えんおう'], start => [1239,3,13], end => [1240,8,5] }, # 2年 from 1239/3/13 until 1240/8/5
297 { name => '仁治', period => '鎌倉時代', reading => ['にんじ'], start => [1240,8,5], end => [1243,3,18] }, # 4年 from 1240/8/5 until 1243/3/18
298 { name => '寛元', period => '鎌倉時代', reading => ['かんげん'], start => [1243,3,18], end => [1247,4,5] }, # 5年 from 1243/3/18 until 1247/4/5
299 { name => '宝治', period => '鎌倉時代', reading => ['ほうじ'], start => [1247,4,5], end => [1249,5,2] }, # 3年 from 1247/4/5 until 1249/5/2
300 { name => '建長', period => '鎌倉時代', reading => ['けんちょう'], start => [1249,5,2], end => [1256,10,24] }, # 8年 from 1249/5/2 until 1256/10/24
301 { name => '康元', period => '鎌倉時代', reading => ['こうげん'], start => [1256,10,24], end => [1257,3,31] }, # 2年 from 1256/10/24 until 1257/3/31
302 { name => '正嘉', period => '鎌倉時代', reading => ['しょうか'], start => [1257,3,31], end => [1259,4,20] }, # 3年 from 1257/3/31 until 1259/4/20
303 { name => '正元', period => '鎌倉時代', reading => ['しょうげん'], start => [1259,4,20], end => [1260,5,24] }, # 2年 from 1259/4/20 until 1260/5/24
304 { name => '文応', period => '鎌倉時代', reading => ['ぶんおう'], start => [1260,5,24], end => [1261,3,22] }, # 2年 from 1260/5/24 until 1261/3/22
305 { name => '弘長', period => '鎌倉時代', reading => ['こうちょう'], start => [1261,3,22], end => [1264,3,27] }, # 4年 from 1261/3/22 until 1264/3/27
306 { name => '文永', period => '鎌倉時代', reading => ['ぶんえい'], start => [1264,3,27], end => [1275,5,22] }, # 12年 from 1264/3/27 until 1275/5/22
307 { name => '建治', period => '鎌倉時代', reading => ['けんじ'], start => [1275,5,22], end => [1278,3,23] }, # 4年 from 1275/5/22 until 1278/3/23
308 { name => '弘安', period => '鎌倉時代', reading => ['こうあん'], start => [1278,3,23], end => [1288,5,29] }, # 11年 from 1278/3/23 until 1288/5/29
309 { name => '正応', period => '鎌倉時代', reading => ['しょうおう'], start => [1288,5,29], end => [1293,9,6] }, # 6年 from 1288/5/29 until 1293/9/6
310 { name => '永仁', period => '鎌倉時代', reading => ['えいにん'], start => [1293,9,6], end => [1299,5,25] }, # 7年 from 1293/9/6 until 1299/5/25
311 { name => '正安', period => '鎌倉時代', reading => ['しょうあん'], start => [1299,5,25], end => [1302,12,10] }, # 4年 from 1299/5/25 until 1302/12/10
312 { name => '乾元', period => '鎌倉時代', reading => ['けんげん'], start => [1302,12,10], end => [1303,9,16] }, # 2年 from 1302/12/10 until 1303/9/16
313 { name => '嘉元', period => '鎌倉時代', reading => ['かげん'], start => [1303,9,16], end => [1307,1,18] }, # 4年 from 1303/9/16 until 1307/1/18
314 { name => '徳治', period => '鎌倉時代', reading => ['とくじ'], start => [1307,1,18], end => [1308,11,22] }, # 3年 from 1307/1/18 until 1308/11/22
315 { name => '延慶', period => '鎌倉時代', reading => ['えんきょう'], start => [1308,11,22], end => [1311,5,17] }, # 4年 from 1308/11/22 until 1311/5/17
316 { name => '応長', period => '鎌倉時代', reading => ['おうちょう'], start => [1311,5,17], end => [1312,4,27] }, # 2年 from 1311/5/17 until 1312/4/27
317 { name => '正和', period => '鎌倉時代', reading => ['しょうわ'], start => [1312,4,27], end => [1317,3,16] }, # 6年 from 1312/4/27 until 1317/3/16
318 { name => '文保', period => '鎌倉時代', reading => ['ぶんぽう'], start => [1317,3,16], end => [1319,5,18] }, # 3年 from 1317/3/16 until 1319/5/18
319 { name => '元応', period => '鎌倉時代', reading => ['げんおう'], start => [1319,5,18], end => [1321,3,22] }, # 3年 from 1319/5/18 until 1321/3/22
320 { name => '元亨', period => '鎌倉時代', reading => ['げんこう'], start => [1321,3,22], end => [1324,12,25] }, # 4年 from 1321/3/22 until 1324/12/25
321 { name => '正中', period => '鎌倉時代', reading => ['しょうちゅう'], start => [1324,12,25], end => [1326,5,28] }, # 3年 from 1324/12/25 until 1326/5/28
322 { name => '嘉暦', period => '鎌倉時代', reading => ['かりゃく'], start => [1326,5,28], end => [1329,9,22] }, # 4年 from 1326/5/28 until 1329/9/22
323 { name => '元徳', period => '鎌倉時代', reading => ['げんとく'], start => [1329,9,22], end => [1331,9,11] }, # 3年 from 1329/9/22 until 1331/9/11
324 { name => '元弘', period => '大覚寺統', reading => ['げんこう'], start => [1331,9,11], end => [1334,3,5] }, # 4年 from 1331/9/11 until 1334/3/5
325 { name => '正慶', period => '持明院統', reading => ['しょうけい','しょうきょう'], start => [1332,5,23], end => [1333,7,7] }, # 2年 from 1332/5/23 until 1333/7/7
326 { name => '建武', period => '南北朝時代・室町時代', reading => [''], start => [1334,3,5], end => [1338,10,11] }, # 3年 from 1334/3/5 until 1338/10/11
327 { name => '暦応', period => '北朝(持明院統)', reading => ['りゃくおう','れきおう'], start => [1338,10,11], end => [1342,6,1] }, # 5年 from 1338/10/11 until 1342/6/1
328 { name => '康永', period => '北朝(持明院統)', reading => ['こうえい'], start => [1342,6,1], end => [1345,11,15] }, # 4年 from 1342/6/1 until 1345/11/15
329 { name => '貞和', period => '北朝(持明院統)', reading => ['じょうわ','ていわ'], start => [1345,11,15], end => [1350,4,4] }, # 6年 from 1345/11/15 until 1350/4/4
330 { name => '観応', period => '北朝(持明院統)', reading => ['かんのう','かんおう'], start => [1350,4,4], end => [1352,11,4] }, # 3年 from 1350/4/4 until 1352/11/4
331 { name => '文和', period => '北朝(持明院統)', reading => ['ぶんな','ぶんわ'], start => [1352,11,4], end => [1356,4,29] }, # 5年 from 1352/11/4 until 1356/4/29
332 { name => '延文', period => '北朝(持明院統)', reading => ['えんぶん'], start => [1356,4,29], end => [1361,5,4] }, # 6年 from 1356/4/29 until 1361/5/4
333 { name => '康安', period => '北朝(持明院統)', reading => ['こうあん'], start => [1361,5,4], end => [1362,10,11] }, # 2年 from 1361/5/4 until 1362/10/11
334 { name => '貞治', period => '北朝(持明院統)', reading => ['じょうじ','ていじ'], start => [1362,10,11], end => [1368,3,7] }, # 7年 from 1362/10/11 until 1368/3/7
335 { name => '応安', period => '北朝(持明院統)', reading => ['おうあん'], start => [1368,3,7], end => [1375,3,29] }, # 8年 from 1368/3/7 until 1375/3/29
336 { name => '永和', period => '北朝(持明院統)', reading => ['えいわ'], start => [1375,3,29], end => [1379,4,9] }, # 5年 from 1375/3/29 until 1379/4/9
337 { name => '康暦', period => '北朝(持明院統)', reading => ['こうりゃく'], start => [1379,4,9], end => [1381,3,20] }, # 3年 from 1379/4/9 until 1381/3/20
338 { name => '永徳', period => '北朝(持明院統)', reading => ['えいとく'], start => [1381,3,20], end => [1384,3,19] }, # 4年 from 1381/3/20 until 1384/3/19
339 { name => '至徳', period => '北朝(持明院統)', reading => ['しとく'], start => [1384,3,19], end => [1387,10,5] }, # 4年 from 1384/3/19 until 1387/10/5
340 { name => '嘉慶', period => '北朝(持明院統)', reading => ['かけい','かきょう'], start => [1387,10,5], end => [1389,3,7] }, # 3年 from 1387/10/5 until 1389/3/7
341 { name => '康応', period => '北朝(持明院統)', reading => ['こうおう'], start => [1389,3,7], end => [1390,4,12] }, # 2年 from 1389/3/7 until 1390/4/12
342 { name => '明徳', period => '北朝(持明院統)', reading => ['めいとく'], start => [1390,4,12], end => [1394,8,2] }, # 5年 from 1390/4/12 until 1394/8/2
343 { name => '応永', period => '南北朝合一後', reading => ['おうえい'], start => [1394,8,2], end => [1428,6,10] }, # 35年 from 1394/8/2 until 1428/6/10
344 { name => '正長', period => '南北朝合一後', reading => ['しょうちょう'], start => [1428,6,10], end => [1429,10,3] }, # 2年 from 1428/6/10 until 1429/10/3
345 { name => '永享', period => '南北朝合一後', reading => ['えいきょう'], start => [1429,10,3], end => [1441,3,10] }, # 13年 from 1429/10/3 until 1441/3/10
346 { name => '嘉吉', period => '南北朝合一後', reading => ['かきつ'], start => [1441,3,10], end => [1444,2,23] }, # 4年 from 1441/3/10 until 1444/2/23
347 { name => '文安', period => '南北朝合一後', reading => ['ぶんあん'], start => [1444,2,23], end => [1449,8,16] }, # 6年 from 1444/2/23 until 1449/8/16
348 { name => '宝徳', period => '南北朝合一後', reading => ['ほうとく'], start => [1449,8,16], end => [1452,8,10] }, # 4年 from 1449/8/16 until 1452/8/10
349 { name => '享徳', period => '南北朝合一後', reading => ['きょうとく'], start => [1452,8,10], end => [1455,9,6] }, # 4年 from 1452/8/10 until 1455/9/6
350 { name => '康正', period => '南北朝合一後', reading => ['こうしょう'], start => [1455,9,6], end => [1457,10,16] }, # 3年 from 1455/9/6 until 1457/10/16
351 { name => '長禄', period => '南北朝合一後', reading => ['ちょうろく'], start => [1457,10,16], end => [1461,2,1] }, # 4年 from 1457/10/16 until 1461/2/1
352 { name => '寛正', period => '南北朝合一後', reading => ['かんしょう'], start => [1461,2,1], end => [1466,3,14] }, # 7年 from 1461/2/1 until 1466/3/14
353 { name => '文正', period => '南北朝合一後', reading => ['ぶんしょう'], start => [1466,3,14], end => [1467,4,9] }, # 2年 from 1466/3/14 until 1467/4/9
354 { name => '応仁', period => '戦国時代', reading => ['おうにん'], start => [1467,4,9], end => [1469,6,8] }, # 3年 from 1467/4/9 until 1469/6/8
355 { name => '文明', period => '戦国時代', reading => ['ぶんめい'], start => [1469,6,8], end => [1487,8,9] }, # 19年 from 1469/6/8 until 1487/8/9
356 { name => '長享', period => '戦国時代', reading => ['ちょうきょう'], start => [1487,8,9], end => [1489,9,16] }, # 3年 from 1487/8/9 until 1489/9/16
357 { name => '延徳', period => '戦国時代', reading => ['えんとく'], start => [1489,9,16], end => [1492,8,12] }, # 4年 from 1489/9/16 until 1492/8/12
358 { name => '明応', period => '戦国時代', reading => ['めいおう'], start => [1492,8,12], end => [1501,3,18] }, # 10年 from 1492/8/12 until 1501/3/18
359 { name => '文亀', period => '戦国時代', reading => ['ぶんき'], start => [1501,3,18], end => [1504,3,16] }, # 4年 from 1501/3/18 until 1504/3/16
360 { name => '永正', period => '戦国時代', reading => ['えいしょう'], start => [1504,3,16], end => [1521,9,23] }, # 18年 from 1504/3/16 until 1521/9/23
361 { name => '大永', period => '戦国時代', reading => ['たいえい'], start => [1521,9,23], end => [1528,9,3] }, # 8年 from 1521/9/23 until 1528/9/3
362 { name => '享禄', period => '戦国時代', reading => ['きょうろく'], start => [1528,9,3], end => [1532,8,29] }, # 5年 from 1528/9/3 until 1532/8/29
363 { name => '天文', period => '戦国時代', reading => ['てんぶん'], start => [1532,8,29], end => [1555,11,7] }, # 24年 from 1532/8/29 until 1555/11/7
364 { name => '弘治', period => '戦国時代', reading => ['こうじ'], start => [1555,11,7], end => [1558,3,18] }, # 4年 from 1555/11/7 until 1558/3/18
365 { name => '永禄', period => '戦国時代', reading => ['えいろく'], start => [1558,3,18], end => [1570,5,27] }, # 13年 from 1558/3/18 until 1570/5/27
366 { name => '元亀', period => '戦国時代', reading => ['げんき'], start => [1570,5,27], end => [1573,8,25] }, # 4年 from 1570/5/27 until 1573/8/25
367 { name => '天正', period => '安土桃山時代', reading => ['てんしょう'], start => [1573,8,25], end => [1593,1,10] }, # 20年 from 1573/8/25 until 1593/1/10
368 { name => '文禄', period => '安土桃山時代', reading => ['ぶんろく'], start => [1593,1,10], end => [1596,12,16] }, # 5年 from 1593/1/10 until 1596/12/16
369 { name => '慶長', period => '安土桃山時代', reading => ['けいちょう'], start => [1596,12,16], end => [1615,9,5] }, # 20年 from 1596/12/16 until 1615/9/5
370 { name => '元和', period => '江戸時代', reading => ['げんな'], start => [1615,9,5], end => [1624,4,17] }, # 10年 from 1615/9/5 until 1624/4/17
371 { name => '寛永', period => '江戸時代', reading => ['かんえい'], start => [1624,4,17], end => [1645,1,13] }, # 21年 from 1624/4/17 until 1645/1/13
372 { name => '正保', period => '江戸時代', reading => ['しょうほう'], start => [1645,1,13], end => [1648,4,7] }, # 5年 from 1645/1/13 until 1648/4/7
373 { name => '慶安', period => '江戸時代', reading => ['けいあん'], start => [1648,4,7], end => [1652,10,20] }, # 5年 from 1648/4/7 until 1652/10/20
374 { name => '承応', period => '江戸時代', reading => ['じょうおう'], start => [1652,10,20], end => [1655,5,18] }, # 4年 from 1652/10/20 until 1655/5/18
375 { name => '明暦', period => '江戸時代', reading => ['めいれき'], start => [1655,5,18], end => [1658,8,21] }, # 4年 from 1655/5/18 until 1658/8/21
376 { name => '万治', period => '江戸時代', reading => ['まんじ'], start => [1658,8,21], end => [1661,5,23] }, # 4年 from 1658/8/21 until 1661/5/23
377 { name => '寛文', period => '江戸時代', reading => ['かんぶん'], start => [1661,5,23], end => [1673,10,30] }, # 13年 from 1661/5/23 until 1673/10/30
378 { name => '延宝', period => '江戸時代', reading => ['えんぽう'], start => [1673,10,30], end => [1681,11,9] }, # 9年 from 1673/10/30 until 1681/11/9
379 { name => '天和', period => '江戸時代', reading => ['てんな'], start => [1681,11,9], end => [1684,4,5] }, # 4年 from 1681/11/9 until 1684/4/5
380 { name => '貞享', period => '江戸時代', reading => ['じょうきょう'], start => [1684,4,5], end => [1688,10,23] }, # 5年 from 1684/4/5 until 1688/10/23
381 { name => '元禄', period => '江戸時代', reading => ['げんろく'], start => [1688,10,23], end => [1704,4,16] }, # 17年 from 1688/10/23 until 1704/4/16
382 { name => '宝永', period => '江戸時代', reading => ['ほうえい'], start => [1704,4,16], end => [1711,6,11] }, # 8年 from 1704/4/16 until 1711/6/11
383 { name => '正徳', period => '江戸時代', reading => ['しょうとく'], start => [1711,6,11], end => [1716,8,9] }, # 6年 from 1711/6/11 until 1716/8/9
384 { name => '享保', period => '江戸時代', reading => ['きょうほう'], start => [1716,8,9], end => [1736,6,7] }, # 21年 from 1716/8/9 until 1736/6/7
385 { name => '元文', period => '江戸時代', reading => ['げんぶん'], start => [1736,6,7], end => [1741,4,12] }, # 6年 from 1736/6/7 until 1741/4/12
386 { name => '寛保', period => '江戸時代', reading => ['かんぽう'], start => [1741,4,12], end => [1744,4,3] }, # 4年 from 1741/4/12 until 1744/4/3
387 { name => '延享', period => '江戸時代', reading => ['えんきょう'], start => [1744,4,3], end => [1748,8,5] }, # 5年 from 1744/4/3 until 1748/8/5
388 { name => '寛延', period => '江戸時代', reading => ['かんえん'], start => [1748,8,5], end => [1751,12,14] }, # 4年 from 1748/8/5 until 1751/12/14
389 { name => '宝暦', period => '江戸時代', reading => ['ほうれき'], start => [1751,12,14], end => [1764,6,30] }, # 14年 from 1751/12/14 until 1764/6/30
390 { name => '明和', period => '江戸時代', reading => ['めいわ'], start => [1764,6,30], end => [1772,12,10] }, # 9年 from 1764/6/30 until 1772/12/10
391 { name => '安永', period => '江戸時代', reading => ['あんえい'], start => [1772,12,10], end => [1781,4,25] }, # 10年 from 1772/12/10 until 1781/4/25
392 { name => '天明', period => '江戸時代', reading => ['てんめい'], start => [1781,4,25], end => [1789,2,19] }, # 9年 from 1781/4/25 until 1789/2/19
393 { name => '寛政', period => '江戸時代', reading => ['かんせい'], start => [1789,2,19], end => [1801,3,19] }, # 13年 from 1789/2/19 until 1801/3/19
394 { name => '享和', period => '江戸時代', reading => ['きょうわ'], start => [1801,3,19], end => [1804,3,22] }, # 4年 from 1801/3/19 until 1804/3/22
395 { name => '文化', period => '江戸時代', reading => ['ぶんか'], start => [1804,3,22], end => [1818,5,26] }, # 15年 from 1804/3/22 until 1818/5/26
396 { name => '文政', period => '江戸時代', reading => ['ぶんせい'], start => [1818,5,26], end => [1831,1,23] }, # 13年 from 1818/5/26 until 1831/1/23
397 { name => '天保', period => '江戸時代', reading => ['てんぽう'], start => [1831,1,23], end => [1845,1,9] }, # 15年 from 1831/1/23 until 1845/1/9
398 { name => '弘化', period => '江戸時代', reading => ['こうか'], start => [1845,1,9], end => [1848,4,1] }, # 5年 from 1845/1/9 until 1848/4/1
399 { name => '嘉永', period => '江戸時代', reading => ['かえい'], start => [1848,4,1], end => [1855,1,15] }, # 7年 from 1848/4/1 until 1855/1/15
400 { name => '安政', period => '江戸時代', reading => ['あんせい'], start => [1855,1,15], end => [1860,4,8] }, # 7年 from 1855/1/15 until 1860/4/8
401 { name => '万延', period => '江戸時代', reading => ['まんえん'], start => [1860,4,8], end => [1861,3,29] }, # 2年 from 1860/4/8 until 1861/3/29
402 { name => '文久', period => '江戸時代', reading => ['ぶんきゅう'], start => [1861,3,29], end => [1864,3,27] }, # 4年 from 1861/3/29 until 1864/3/27
403 { name => '元治', period => '江戸時代', reading => ['げんじ'], start => [1864,3,27], end => [1865,5,1] }, # 2年 from 1864/3/27 until 1865/5/1
404 { name => '慶応', period => '江戸時代', reading => ['けいおう'], start => [1865,5,1], end => [1868,10,23] }, # 4年 from 1865/5/1 until 1868/10/23
405 { name => '明治', period => '明治以降', reading => ['めいじ'], start => [1868,10,23], end => [1912,7,30] }, # 45年 from 1868/10/23 until 1912/7/30
406 { name => '大正', period => '登極令下', reading => ['たいしょう'], start => [1912,7,30], end => [1926,12,25] }, # 15年 from 1912/7/30 until 1926/12/25
407 { name => '昭和', period => '登極令下', reading => ['しょうわ'], start => [1926,12,25], end => [1989,1,7] }, # 64年 from 1926/12/25 until 1989/1/7
408 { name => '平成', period => '元号法下', reading => ['へいせい'], start => [1989,1,8], end => [2019,4,30] }, # 31年 from 1989/1/8 until 2019/4/30
409 { name => '令和', period => '元号法下', reading => ['れいわ'], start => [2019,5,1], end => [] }, # from 2019/5/1 until
410 ];
411 };
412  
413 sub new
414 85 ▶{
Subroutine new: called CC=6 SCAR=21.6
Pod documented
415 85 my $this = shift( @_ );
416 85 ▶ return( $this->error( "Incorrect parameters provided. You need to provide an hash of values." ) ) if( @_ % 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 85 85
417 85 my $p = { @_ };
418 85 ▶ $p->{debug} //= 0;
Condition50%1/2
$p->{"debug"} //= 0
l!l
850
MC/DC0%0/1
$p->{"debug"} //= 0
$p->{"debug"}
Truth table50%1/2
A
A= $p->{"debug"}
Aresult
11
00
419 # kanji_number
420 # pattern
421 # time_zone
422 # traditional
423 # zenkaku / hankaku
424 85 ▶ if( exists( $p->{hankaku} ) && !exists( $p->{zenkaku} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p->{"hankaku"} and not exists $p->{"zenkaku"}) 0 85 85
Condition33%1/3
exists $p->{"hankaku"} and not exists $p->{"zenkaku"}
!ll&&!rl&&r
8500
MC/DC0%0/2
exists $p->{"hankaku"} and not exists $p->{"zenkaku"}
exists $p->{"hankaku"} not exists $p->{"zenkaku"}
Truth table33%1/3
A and not(B)
A= exists $p->{"hankaku"}B= not exists $p->{"zenkaku"}
ABresult
0X0
100
111
425 {
426 0 $p->{zenkaku} = !$p->{hankaku};
427 }
428 85 ▶ return( bless( $p => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0850
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
429 }
430  
431 sub error
432 0 ▶{
Subroutine error: not called CC=5 SCAR=34.0
Pod documented
433 0 my $self = shift( @_ );
434 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
435 {
436 0 ▶ $self->{error} = $ERROR = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
437 0 ▶ warnings::warn( $ERROR, "\n" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
438 0 return;
439 }
440 0 ▶ return( ref( $self ) ? $self->{error} : $ERROR );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
441 }
442  
443 sub format_datetime
444 83 ▶{
Subroutine format_datetime: called CC=10 SCAR=23.4
Pod documented
445 83 my $self = shift( @_ );
446 83 my $dt = shift( @_ );
447 83 require overload;
448 83 ▶ return( $self->error( "Value provided (", overload::StrVal( $dt ), ") is not a DateTime or DateTime::Lite object or one inheriting from either of them." ) ) if( !ref( $dt ) || ( ref( $dt ) && !$dt->isa( 'DateTime' ) && !$dt->isa( 'DateTime::Lite' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $dt or ref $dt and not $dt->isa("DateTime") and not $dt->isa("DateTime::Lite") 0 83 83
Condition33%3/9
not ref $dt or ref $dt and not $dt->isa("DateTime") and not $dt->isa("DateTime::Lite")
l!l&&r!l&&!r
0083
ref $dt and not $dt->isa("DateTime") and not $dt->isa("DateTime::Lite")
!ll&&!rl&&r
0830
ref $dt and not $dt->isa("DateTime")
!ll&&!rl&&r
0083
MC/DC0%0/4
not ref $dt or ref $dt and not $dt->isa("DateTime") and not $dt->isa("DateTime::Lite")
not ref $dt ref $dt not $dt->isa("DateTime") not $dt->isa("DateTime::Lite")
Truth table20%1/5
not(A) or B and not(C) and not(D)
A= not ref $dtB= ref $dtC= not $dt->isa("DateTime")D= not $dt->isa("DateTime::Lite")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
449 83 my $dt_class = ref( $dt );
450 83 ▶ my $pat = length( $self->{pattern} ) ? $self->{pattern} : '%c';
Branch: 1 branch
BranchTrueFalseTotal
length $self->{'pattern'} ? : 83 0 83
451 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
452
453 my $japanised_value_for = sub
454 48 ▶ {
Subroutine __ANON__: called CC=6 SCAR=17.9
455 48 my $method_name = shift( @_ );
456 48 my $opts = {};
457 48 ▶ $opts = shift( @_ ) if( ref( $_[0] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 3 45 48
458 48 ▶ $opts->{simple_kanji} = 0 if( !exists( $opts->{simple_kanji} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"simple_kanji"} 45 3 48
459 48 my $ref = $dt->can( $method_name );
460 48 my $n = $ref->( $dt );
461 48 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 20 28 48
elsif ($self->{'kanji_number'}) { } 8 20 28
462 {
463 20 $n = $self->romaji_to_zenkaku( $n );
464 }
465 elsif( $self->{kanji_number} )
466 {
467 8 ▶ if( $opts->{simple_kanji} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'simple_kanji'}) { } 1 7 8
468 {
469 1 $n = $self->romaji_to_kanji_simple( $n );
470 }
471 else
472 {
473 7 $n = $self->romaji_to_kanji( $n );
474 }
475 }
476 48 return( $n );
477 83 };
478 my $japanised_strftime = sub
479 9 ▶ {
Subroutine __ANON__: called CC=6 SCAR=18.0
480 9 my $token = shift( @_ );
481 9 my $opts = {};
482 9 ▶ $opts = shift( @_ ) if( ref( $_[0] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 3 6 9
483 9 ▶ $opts->{simple_kanji} = 0 if( !exists( $opts->{simple_kanji} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"simple_kanji"} 6 3 9
484 9 my $n = $dt->strftime( $token );
485 2 ▶ no warnings 'DateTime::Format::JP';
Subroutine BEGIN: called CC=1 SCAR=0.0
486 9 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 4 5 9
elsif ($self->{'kanji_number'}) { } 1 4 5
487 {
488 4 $n = $self->romaji_to_zenkaku( $n );
489 }
490 elsif( $self->{kanji_number} )
491 {
492 1 ▶ if( $opts->{simple_kanji} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'simple_kanji'}) { } 1 0 1
493 {
494 1 $n = $self->romaji_to_kanji_simple( $n );
495 }
496 else
497 {
498 0 $n = $self->romaji_to_kanji( $n );
499 }
500 }
501 9 return( $n );
502 83 };
503
504 my $map =
505 {
506 0 ▶ '%' => sub{ return( ( $self->{traditional} || $self->{zenkaku} || $self->{kanji_number} ) ? '%' : '%' ); },
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
$self->{'traditional'} || $self->{'zenkaku'} || $self->{'kanji_number'} ? : 0 0 0
Condition0%0/6
$self->{"traditional"} or $self->{"zenkaku"} or $self->{"kanji_number"}
l!l&&r!l&&!r
000
$self->{"traditional"} or $self->{"zenkaku"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"traditional"} or $self->{"zenkaku"} or $self->{"kanji_number"}
$self->{"traditional"} $self->{"zenkaku"} $self->{"kanji_number"}
Truth table0%0/4
A or B or C
A= $self->{"traditional"}B= $self->{"zenkaku"}C= $self->{"kanji_number"}
ABCresult
1XX1
01X1
0011
0000
507 # weekday name in abbreviated form
508 'a' => sub
509 1 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
510 1 my $n = $dt->day_of_week - 1;
511 1 return( $WEEKDAYS->[ $n ] );
512 },
513 # weekday name in its long form
514 'A' => sub
515 1 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
516 1 my $n = $dt->day_of_week - 1;
517 1 return( $WEEKDAYS->[ $n ] . '曜日' );
518 },
519 # month name
520 1 ▶ 'b' => sub{ return( sprintf( '%d月', $dt->month ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
521 # month name using full width (全角) digits
522 1 ▶ 'B' => sub{ return( sprintf( '%s月', $self->romaji_to_zenkaku( $dt->month ) ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
523 # month name using kanjis for numbers
524 1 ▶ 'h' => sub{ return( sprintf( '%s月', $self->romaji_to_kanji( $dt->month ) ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
525 # datetime format in the standard most usual form
526 # 令和3年7月12日午後2:17:30
527 # 令和3年7月12日午後2時17分30秒
528 # 令和3年7月12日午後2時17分30秒
529 # 令和3年七月十二日午後二時十七分三十秒
530 'c' => sub
531 5 ▶ {
Subroutine __ANON__: called CC=10 SCAR=23.1
532 5 ▶ my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
Condition50%1/2
$self->lookup_era_by_date($dt) || (return $self->error("Unable to find an era for date '${dt}'"))
l!l
50
MC/DC0%0/1
$self->lookup_era_by_date($dt) || (return $self->error("Unable to find an era for date '${dt}'"))
$self->lookup_era_by_date($dt)
Truth table50%1/2
A
A= $self->lookup_era_by_date($dt)
Aresult
11
00
533 5 my $def =
534 {
535 year => $era->year( $dt ),
536 month => $dt->month,
537 day => $dt->day,
538 hour => $dt->hour_12,
539 minute => $dt->minute,
540 second => $dt->second,
541 };
542 5 foreach( keys( %$def ) )
543 {
544 30 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 12 18 30
elsif ($self->{'kanji_number'}) { } 6 12 18
545 {
546 12 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
547 }
548 elsif( $self->{kanji_number} )
549 {
550 6 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
551 }
552 }
553 5 ▶ if( $self->{traditional} || $self->{kanji_number} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'traditional'} or $self->{'kanji_number'}) { } 3 2 5
Condition100%3/3
$self->{"traditional"} or $self->{"kanji_number"}
l!l&&r!l&&!r
212
MC/DC100%2/2
$self->{"traditional"} or $self->{"kanji_number"}
$self->{"traditional"} $self->{"kanji_number"}
Truth table100%3/3
A or B
A= $self->{"traditional"}B= $self->{"kanji_number"}
ABresult
1X1
011
000
554 {
555 3 $def->{suff_hour} = '時';
556 3 $def->{suff_minute} = '分';
557 3 $def->{suff_second} = '秒';
558 3 ▶ 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 )} ) );
Branch: 1 branch
BranchTrueFalseTotal
$dt->hour > 12 ? : 3 0 3
559 }
560 else
561 {
562 2 ▶ $def->{sep} = $self->{zenkaku} ? ':' : ':';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'zenkaku'} ? : 1 1 2
563 2 ▶ 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 )} ) );
Branch: 1 branch
BranchTrueFalseTotal
$dt->hour > 12 ? : 2 0 2
564 }
565 },
566 # century number (0-99)
567 1 ▶ 'C' => sub{ return( $dt->strftime( '%C' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
568 # day of month
569 6 ▶ 'd' => sub{ return( $japanised_value_for->( 'day' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
570 # Japanese style date including with the leading era name
571 'D' => sub
572 3 ▶ {
Subroutine __ANON__: called CC=5 SCAR=16.1
573 3 ▶ my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
Condition50%1/2
$self->lookup_era_by_date($dt) || (return $self->error("Unable to find an era for date '${dt}'"))
l!l
30
MC/DC0%0/1
$self->lookup_era_by_date($dt) || (return $self->error("Unable to find an era for date '${dt}'"))
$self->lookup_era_by_date($dt)
Truth table50%1/2
A
A= $self->lookup_era_by_date($dt)
Aresult
11
00
574 3 my $def =
575 {
576 year => $era->year( $dt ),
577 month => $dt->month,
578 day => $dt->day,
579 };
580 3 foreach( keys( %$def ) )
581 {
582 9 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 3 6 9
elsif ($self->{'kanji_number'}) { } 3 3 6
583 {
584 3 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
585 }
586 elsif( $self->{kanji_number} )
587 {
588 3 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
589 }
590 }
591 3 return( sprintf( '%s%s年%s月%s日', $era->name, @$def{qw( year month day )} ) );
592 },
593 # Japanese era name
594 'E' => sub
595 1 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.2
596 1 ▶ my $e = $self->lookup_era_by_date( $dt ) || return;
Condition50%1/2
$self->lookup_era_by_date($dt) || (return)
l!l
10
MC/DC0%0/1
$self->lookup_era_by_date($dt) || (return)
$self->lookup_era_by_date($dt)
Truth table50%1/2
A
A= $self->lookup_era_by_date($dt)
Aresult
11
00
597 1 return( $e->name );
598 },
599 # Equivalent to "%Y年%m月%d日"
600 'F' => sub
601 3 ▶ {
Subroutine __ANON__: called CC=6 SCAR=17.9
602 3 my $def =
603 {
604 year => $dt->year,
605 month => $dt->month,
606 day => $dt->day,
607 };
608 3 foreach( qw( month day ) )
609 {
610 6 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 2 4 6
elsif ($self->{'kanji_number'}) { } 2 2 4
611 {
612 2 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
613 }
614 elsif( $self->{kanji_number} )
615 {
616 2 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
617 }
618 }
619
620 3 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 1 2 3
elsif ($self->{'kanji_number'}) { } 1 1 2
621 {
622 1 $def->{year} = $self->romaji_to_zenkaku( $def->{year} );
623 }
624 elsif( $self->{kanji_number} )
625 {
626 1 $def->{year} = $self->romaji_to_kanji_simple( $def->{year} );
627 }
628
629 3 return( sprintf( '%s年%s月%s日', @$def{qw( year month day )} ) );
630 },
631 # year without century
632 1 ▶ 'g' => sub{ return( $dt->strftime( '%g' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
633 # week number 4-digit year
634 1 ▶ 'G' => sub{ return( $dt->strftime( '%G' ) ); },,
Subroutine __ANON__: called CC=1 SCAR=0.0
635 # hour
636 5 ▶ 'H' => sub{ return( $japanised_value_for->( 'hour' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '時' : '' ) ); },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$self->{'traditional'} || $self->{'kanji_number'} ? : 3 2 5
Condition100%3/3
$self->{"traditional"} or $self->{"kanji_number"}
l!l&&r!l&&!r
212
MC/DC100%2/2
$self->{"traditional"} or $self->{"kanji_number"}
$self->{"traditional"} $self->{"kanji_number"}
Truth table100%3/3
A or B
A= $self->{"traditional"}B= $self->{"kanji_number"}
ABresult
1X1
011
000
637 # hour with clock of 12
638 3 ▶ 'I' => sub{ return( $japanised_value_for->( 'hour_12' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
639 # day number in the year
640 1 ▶ 'j' => sub{ return( $dt->strftime( '%j' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
641 # month number
642 3 ▶ 'm' => sub{ return( $japanised_value_for->( 'month' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
643 # minute
644 5 ▶ 'M' => sub{ return( $japanised_value_for->( 'minute' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '分' : '' ) ); },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$self->{'traditional'} || $self->{'kanji_number'} ? : 3 2 5
Condition100%3/3
$self->{"traditional"} or $self->{"kanji_number"}
l!l&&r!l&&!r
212
MC/DC100%2/2
$self->{"traditional"} or $self->{"kanji_number"}
$self->{"traditional"} $self->{"kanji_number"}
Truth table100%3/3
A or B
A= $self->{"traditional"}B= $self->{"kanji_number"}
ABresult
1X1
011
000
645 # space
646 0 ▶ 'n' => sub{ return( $dt->strftime( '%n' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
647 # AM/PM
648 2 ▶ 'p' => sub{ return( $dt->hour > 12 ? '午後' : '午前' ); },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$dt->hour > 12 ? : 2 0 2
649 # Equivalent to "%p%I:%M:%S"
650 2 ▶ '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' ) ) ); },
Subroutine __ANON__: called CC=4 SCAR=14.0
Branch: 3 branches
BranchTrueFalseTotal
$dt->hour > 12 ? : 2 0 2
$self->{'zenkaku'} ? : 1 1 2
$self->{'zenkaku'} ? : 1 1 2
651 # Equivalent to "%H:%M"
652 2 ▶ 'R' => sub{ return( sprintf( '%s%s%s', $japanised_value_for->( 'hour' ), ( $self->{zenkaku} ? ':' : ':' ), $japanised_value_for->( 'minute' ) ) ); },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->{'zenkaku'} ? : 1 1 2
653 # seconds since the Epoch
654 2 ▶ 's' => sub{ return( $self->{zenkaku} ? $self->romaji_to_zenkaku( $dt->strftime( '%s' ) ) : $dt->strftime( '%s' ) ); },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->{'zenkaku'} ? : 1 1 2
655 # seconds
656 5 ▶ 'S' => sub{ return( $japanised_value_for->( 'second' ) . ( ( $self->{traditional} || $self->{kanji_number} ) ? '秒' : '' ) ); },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$self->{'traditional'} || $self->{'kanji_number'} ? : 3 2 5
Condition100%3/3
$self->{"traditional"} or $self->{"kanji_number"}
l!l&&r!l&&!r
212
MC/DC100%2/2
$self->{"traditional"} or $self->{"kanji_number"}
$self->{"traditional"} $self->{"kanji_number"}
Truth table100%3/3
A or B
A= $self->{"traditional"}B= $self->{"kanji_number"}
ABresult
1X1
011
000
657 # space
658 0 ▶ 't' => sub{ return( $dt->strftime( '%t' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
659 # Equivalent to "%H:%M:%S"
660 2 ▶ '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' ) ) ); },
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
$self->{'zenkaku'} ? : 1 1 2
$self->{'zenkaku'} ? : 1 1 2
661 # week number with Sunday first
662 2 ▶ 'U' => sub{ return( $japanised_strftime->( '%U' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
663 # weekday number 1-7
664 2 ▶ 'u' => sub{ return( $japanised_value_for->( 'day_of_week' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
665 # weekday number 0-7 with Sunday first
666 2 ▶ 'w' => sub{ return( $japanised_strftime->( '%w' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
667 # week number with Monday first
668 2 ▶ 'W' => sub{ return( $japanised_strftime->( '%W' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
669 # date format in the standard most usual form
670 # 令和3年7月12日
671 # 令和3年7月12日
672 # 令和3年七月十二日
673 'x' => sub
674 3 ▶ {
Subroutine __ANON__: called CC=5 SCAR=16.1
675 3 ▶ my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
Condition50%1/2
$self->lookup_era_by_date($dt) || (return $self->error("Unable to find an era for date '${dt}'"))
l!l
30
MC/DC0%0/1
$self->lookup_era_by_date($dt) || (return $self->error("Unable to find an era for date '${dt}'"))
$self->lookup_era_by_date($dt)
Truth table50%1/2
A
A= $self->lookup_era_by_date($dt)
Aresult
11
00
676 3 my $def =
677 {
678 year => $era->year( $dt ),
679 month => $dt->month,
680 day => $dt->day,
681 };
682 3 foreach( keys( %$def ) )
683 {
684 9 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 3 6 9
elsif ($self->{'kanji_number'}) { } 3 3 6
685 {
686 3 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
687 }
688 elsif( $self->{kanji_number} )
689 {
690 3 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
691 }
692 }
693 3 return( sprintf( '%s%s年%s月%s日', $era->name, @$def{qw( year month day )} ) );
694 },
695 # time format in the standard most usual form
696 # 午後2:17:30
697 # 午後2時17分30秒
698 # 午後二時十七分三十秒
699 'X' => sub
700 4 ▶ {
Subroutine __ANON__: called CC=10 SCAR=23.0
701 4 my $def =
702 {
703 hour => $dt->hour_12,
704 minute => $dt->minute,
705 second => $dt->second,
706 };
707 4 ▶ $def->{ampm} = $dt->hour > 12 ? '午後' : '午前';
Branch: 1 branch
BranchTrueFalseTotal
$dt->hour > 12 ? : 4 0 4
708 4 $def->{sep1} = $def->{sep2} = ':';
709 4 ▶ if( $self->{traditional} || $self->{kanji_number} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'traditional'} or $self->{'kanji_number'}) { } 2 2 4
elsif ($self->{'zenkaku'}) { } 1 1 2
Condition100%3/3
$self->{"traditional"} or $self->{"kanji_number"}
l!l&&r!l&&!r
112
MC/DC100%2/2
$self->{"traditional"} or $self->{"kanji_number"}
$self->{"traditional"} $self->{"kanji_number"}
Truth table100%3/3
A or B
A= $self->{"traditional"}B= $self->{"kanji_number"}
ABresult
1X1
011
000
710 {
711 2 $def->{suff_hour} = '時';
712 2 $def->{suff_minute} = '分';
713 2 $def->{suff_second} = '秒';
714 2 delete( @$def{qw( sep1 sep2 )} );
715 }
716 elsif( $self->{zenkaku} )
717 {
718 1 $def->{sep1} = $def->{sep2} = ':';
719 }
720
721 4 foreach( qw( hour minute second ) )
722 {
723 12 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 3 9 12
elsif ($self->{'kanji_number'}) { } 3 6 9
724 {
725 3 $def->{ $_ } = $self->romaji_to_zenkaku( $def->{ $_ } );
726 }
727 elsif( $self->{kanji_number} )
728 {
729 3 $def->{ $_ } = $self->romaji_to_kanji( $def->{ $_ } );
730 }
731 }
732
733 4 ▶ if( $self->{traditional} || $self->{kanji_number} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'traditional'} or $self->{'kanji_number'}) { } 2 2 4
Condition100%3/3
$self->{"traditional"} or $self->{"kanji_number"}
l!l&&r!l&&!r
112
MC/DC100%2/2
$self->{"traditional"} or $self->{"kanji_number"}
$self->{"traditional"} $self->{"kanji_number"}
Truth table100%3/3
A or B
A= $self->{"traditional"}B= $self->{"kanji_number"}
ABresult
1X1
011
000
734 {
735 2 return( sprintf( '%s%s%s%s%s%s%s', @$def{qw( ampm hour suff_hour minute suff_minute second suff_second )} ) );
736 }
737 else
738 {
739 2 return( sprintf( '%s%s%s%s%s%s', @$def{qw( ampm hour sep1 minute sep2 second )} ) );
740 }
741 },
742 # year of the era, relative to the start of the era
743 'y' => sub
744 3 ▶ {
Subroutine __ANON__: called CC=4 SCAR=13.9
745 3 ▶ my $era = $self->lookup_era_by_date( $dt ) || return( $self->error( "Unable to find an era for date '$dt'" ) );
Condition50%1/2
$self->lookup_era_by_date($dt) || (return $self->error("Unable to find an era for date '${dt}'"))
l!l
30
MC/DC0%0/1
$self->lookup_era_by_date($dt) || (return $self->error("Unable to find an era for date '${dt}'"))
$self->lookup_era_by_date($dt)
Truth table50%1/2
A
A= $self->lookup_era_by_date($dt)
Aresult
11
00
746 3 my $y = $era->year( $dt );
747 3 ▶ if( $self->{zenkaku} )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'zenkaku'}) { } 1 2 3
elsif ($self->{'kanji_number'}) { } 1 1 2
748 {
749 1 $y = $self->romaji_to_zenkaku( $y );
750 }
751 elsif( $self->{kanji_number} )
752 {
753 1 $y = $self->romaji_to_kanji( $y );
754 }
755 3 return( $y );
756 },
757 # 4-digit year
758 3 ▶ 'Y' => sub{ return( $japanised_value_for->( 'year', { simple_kanji => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
759 # standard time zone specification, such as +0900
760 'z' => sub
761 3 ▶ {
Subroutine __ANON__: called CC=6 SCAR=19.1
762 3 my $rv = $japanised_strftime->( '%z', { simple_kanji => 1 });
763 3 ▶ if( $self->{zenkaku} || $self->{traditional} || $self->{kanji_number} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zenkaku"} or $self->{"traditional"} or $self->{"kanji_number"}) 2 1 3
Condition83%5/6
$self->{"zenkaku"} or $self->{"traditional"} or $self->{"kanji_number"}
l!l&&r!l&&!r
111
$self->{"zenkaku"} or $self->{"traditional"}
l!l&&r!l&&!r
102
MC/DC66%2/3
$self->{"zenkaku"} or $self->{"traditional"} or $self->{"kanji_number"}
$self->{"zenkaku"} $self->{"traditional"} $self->{"kanji_number"}
Truth table75%3/4
A or B or C
A= $self->{"zenkaku"}B= $self->{"traditional"}C= $self->{"kanji_number"}
ABCresult
1XX1
01X1
0011
0000
764 {
765 2 ▶ if( substr( $rv, 0, 1 ) eq '+' )
Branch: 2 branches
BranchTrueFalseTotal
if (substr($rv, 0, 1) eq '+') { } 2 0 2
elsif (substr($rv, 0, 1) eq '-') { } 0 0 0
766 {
767 2 substr( $rv, 0, 1, '+' );
768 }
769 elsif( substr( $rv, 0, 1 ) eq '-' )
770 {
771 0 substr( $rv, 0, 1, 'ー' );
772 }
773 }
774 3 return( $rv );
775 },
776 # timezone name
777 1 ▶ 'Z' => sub{ return( $dt->strftime( '%Z' ) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
778 83 };
779 # Aliases
780 83 $map->{e} = $map->{d};
781 83 $map->{P} = $map->{p};
782 83 $pat =~ s
783 {
784 \%([\%aAbBhcCdeDEFgGHIjmMnNpPrRRsStTUuwWxXyYzZ])
785 }
786 {
787 83 my $token = $1;
788 83 ▶ die( "Missing definition for '$token'\n" ) if( !exists( $map->{ $token } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $map->{$token} 0 83 83
789 83 $map->{ $token }->();
790 }gexs;
791  
792 83 $pat =~ s
793 {
794 \%\{(\w+)\}
795 }
796 {
797 0 my $meth = $1;
798 0 my $code = $dt->can( $meth );
799 0 ▶ if( $code )
Branch: 1 branch
BranchTrueFalseTotal
if ($code) { } 0 0 0
800 {
801 0 $code->( $dt );
802 }
803 else
804 {
805 0 ▶ warnings::warn( "Unsupported ${dt_class} method \"${meth}\" found in pattern.\n" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
806 0 '%{' . $meth . '}';
807 }
808 }gexs;
809
810 83 ▶ if( index( $pat, '%' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($pat, "%") != -1) 0 83 83
811 {
812 0 $pat = $dt->strftime( $pat );
813 }
814 83 return( $pat );
815 }
816  
817 0 ▶sub hankaku { return( shift->_set_get_zenkaku( 'hankaku', @_ ) ); }
Subroutine hankaku: not called CC=1 SCAR=6.9
Pod documented
818  
819 0 ▶sub kanji_number { return( shift->_set_get( 'kanji_number', @_ ) ); }
Subroutine kanji_number: not called CC=1 SCAR=6.9
Pod documented
820  
821 sub kanji_to_romaji
822 116 ▶{
Subroutine kanji_to_romaji: called CC=9 SCAR=23.0
Pod documented
823 116 my $self = shift( @_ );
824 116 my $num = shift( @_ );
825 116 ▶ return( $self->error( "No value provided to transcode from kanji number to roman numerals." ) ) if( !defined( $num ) || !length( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num and length $num 0 116 116
Condition33%1/3
defined $num and length $num
!ll&&!rl&&r
00116
MC/DC0%0/2
defined $num and length $num
defined $num length $num
Truth table33%1/3
A and B
A= defined $numB= length $num
ABresult
0X0
100
111
826 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
827 116 my $rv = 0;
828 116 ▶ if( $num =~ s/^[[:blank:]\h]*([〇一二三四五六七八九])千// )
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ s/^[[:blank:]\h]*([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{5343}//) 10 106 116
829 {
830 10 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
831 10 $rv = $n * 1000;
832 }
833 116 ▶ if( length( $num ) && $num =~ s/^([〇一二三四五六七八九])百// )
Branch: 1 branch
BranchTrueFalseTotal
if (length $num and $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{767e}//) 0 116 116
Condition33%1/3
length $num and $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{767e}//
!ll&&!rl&&r
01160
MC/DC0%0/2
length $num and $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{767e}//
length $num $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{767e}//
Truth table33%1/3
A and B
A= length $numB= $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{767e}//
ABresult
0X0
100
111
834 {
835 0 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
836 0 $rv += ( $n * 100 );
837 }
838 116 ▶ if( length( $num ) && $num =~ s/^([〇一二三四五六七八九])十// )
Branch: 1 branch
BranchTrueFalseTotal
if (length $num and $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{5341}//) 15 101 116
Condition66%2/3
length $num and $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{5341}//
!ll&&!rl&&r
010115
MC/DC50%1/2
length $num and $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{5341}//
length $num $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{5341}//
Truth table66%2/3
A and B
A= length $numB= $num =~ s/^([\x{3007}\x{4e00}\x{4e8c}\x{4e09}\x{56db}\x{4e94}\x{516d}\x{4e03}\x{516b}\x{4e5d}])\x{5341}//
ABresult
0X0
100
111
839 {
840 15 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $1 );
841 15 $rv += ( $n * 10 );
842 }
843 116 ▶ if( length( $num ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $num) 101 15 116
844 {
845 101 my $n = $self->_get_pos_in_array( $KANJI_NUMBERS, $num );
846 101 $rv += $n;
847 }
848 116 return( $rv );
849 }
850  
851 sub lookup_era
852 44 ▶{
Subroutine lookup_era: called CC=4 SCAR=14.2
Pod documented
853 44 my $self = shift( @_ );
854 44 ▶ my $name = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No era name was provided to lookup.'))
l!l
440
MC/DC0%0/1
shift @_ || (return $self->error('No era name was provided to lookup.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
855 return( $self->error( "No era name was provided to lookup." ) );
856 44 foreach my $ref ( @$DICT )
857 {
858 10648 ▶ if( $ref->{name} eq $name )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{"name"} eq $name) 44 10604 10648
859 {
860 44 return( DateTime::Format::JP::Era->new( $ref ) );
861 }
862 }
863 # Nothing found
864 0 return;
865 }
866  
867 sub lookup_era_by_date
868 15 ▶{
Subroutine lookup_era_by_date: called CC=21 SCAR=41.8
Pod documented
869 15 my $self = shift( @_ );
870 15 my $dt = shift( @_ );
871 15 require overload;
872 15 ▶ return( $self->error( "Value provided (", overload::StrVal( $dt ), ") is not a DateTime or DateTime::Lite object or one inheriting from it." ) ) if( !ref( $dt ) || ( ref( $dt ) && !$dt->isa( 'DateTime' ) && !$dt->isa( 'DateTime::Lite' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if not ref $dt or ref $dt and not $dt->isa("DateTime") and not $dt->isa("DateTime::Lite") 0 15 15
Condition33%3/9
not ref $dt or ref $dt and not $dt->isa("DateTime") and not $dt->isa("DateTime::Lite")
l!l&&r!l&&!r
0015
ref $dt and not $dt->isa("DateTime") and not $dt->isa("DateTime::Lite")
!ll&&!rl&&r
0150
ref $dt and not $dt->isa("DateTime")
!ll&&!rl&&r
0015
MC/DC0%0/4
not ref $dt or ref $dt and not $dt->isa("DateTime") and not $dt->isa("DateTime::Lite")
not ref $dt ref $dt not $dt->isa("DateTime") not $dt->isa("DateTime::Lite")
Truth table20%1/5
not(A) or B and not(C) and not(D)
A= not ref $dtB= ref $dtC= not $dt->isa("DateTime")D= not $dt->isa("DateTime::Lite")
ABCDresult
1XXX1
01111
00XX0
010X0
01100
873 15 my( $y, $m, $d ) = unpack( 'A4A2A2', $dt->ymd( '' ) );
874 15 my $era;
875 15 foreach my $def ( @$DICT )
876 {
877 # No need to bother if the current entry has an end and it is lower than our current year
878 3630 ▶ next if( scalar( @{$def->{end}} ) && $y > $def->{end}->[0] );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$def->{"end"};} and $y > $def->{"end"}[0] 3615 15 3630
Condition66%2/3
scalar @{$def->{"end"};} and $y > $def->{"end"}[0]
!ll&&!rl&&r
1503615
MC/DC50%1/2
scalar @{$def->{"end"};} and $y > $def->{"end"}[0]
scalar @{$def->{"end"};} $y > $def->{"end"}[0]
Truth table66%2/3
A and B
A= scalar @{$def->{"end"};}B= $y > $def->{"end"}[0]
ABresult
0X0
100
111
879 15 ▶ if( scalar( @{$def->{start}} ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @{$def->{'start'};} and scalar @{$def->{'end'};} and $y >= $def->{'start'}[0] and $y <= $def->{'end'}[0] and $m >= $def->{'start'}[1] and $m <= $def->{'end'}[1] and $d >= $def->{'start'}[2] and $d < $def->{'end'}[2]) { } 0 15 15
elsif (scalar @{$def->{'start'};} and not scalar @{$def->{'end'};} and $y >= $def->{'start'}[0] and $m >= $def->{'start'}[1] and $d >= $def->{'start'}[2]) { } 15 0 15
Condition35%7/20
scalar @{$def->{"start"};} and scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $y <= $def->{"end"}[0] and $m >= $def->{"start"}[1] and $m <= $def->{"end"}[1] and $d >= $def->{"start"}[2] and $d < $def->{"end"}[2]
!ll&&!rl&&r
1500
scalar @{$def->{"start"};} and scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $y <= $def->{"end"}[0] and $m >= $def->{"start"}[1] and $m <= $def->{"end"}[1] and $d >= $def->{"start"}[2]
!ll&&!rl&&r
1500
scalar @{$def->{"start"};} and scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $y <= $def->{"end"}[0] and $m >= $def->{"start"}[1] and $m <= $def->{"end"}[1]
!ll&&!rl&&r
1500
scalar @{$def->{"start"};} and scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $y <= $def->{"end"}[0] and $m >= $def->{"start"}[1]
!ll&&!rl&&r
1500
scalar @{$def->{"start"};} and scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $y <= $def->{"end"}[0]
!ll&&!rl&&r
1500
scalar @{$def->{"start"};} and scalar @{$def->{"end"};} and $y >= $def->{"start"}[0]
!ll&&!rl&&r
1500
scalar @{$def->{"start"};} and scalar @{$def->{"end"};}
!ll
015
MC/DC0%0/7
scalar @{$def->{"start"};} and scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $y <= $def->{"end"}[0] and $m >= $def->{"start"}[1] and $m <= $def->{"end"}[1] and $d >= $def->{"start"}[2] and $d < $def->{"end"}[2]
scalar @{$def->{"start"};} $y >= $def->{"start"}[0] $y <= $def->{"end"}[0] $m >= $def->{"start"}[1] $m <= $def->{"end"}[1] $d >= $def->{"start"}[2] $d < $def->{"end"}[2]
Truth table0%0/8
A and B and C and D and E and F and G
A= scalar @{$def->{"start"};}B= $y >= $def->{"start"}[0]C= $y <= $def->{"end"}[0]D= $m >= $def->{"start"}[1]E= $m <= $def->{"end"}[1]F= $d >= $def->{"start"}[2]G= $d < $def->{"end"}[2]
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
880 15 scalar( @{$def->{end}} ) &&
881 $y >= $def->{start}->[0] &&
882 $y <= $def->{end}->[0] &&
883 $m >= $def->{start}->[1] &&
884 $m <= $def->{end}->[1] &&
885 $d >= $def->{start}->[2] &&
886 $d < $def->{end}->[2] )
887 {
888 0 $era = DateTime::Format::JP::Era->new( $def );
889 0 last;
890 }
891 # Obviously the current era, i.e. it has no end date
892 15 ▶ elsif( scalar( @{$def->{start}} ) &&
Condition33%4/12
scalar @{$def->{"start"};} and not scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $m >= $def->{"start"}[1] and $d >= $def->{"start"}[2]
!ll&&!rl&&r
0015
scalar @{$def->{"start"};} and not scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $m >= $def->{"start"}[1]
!ll&&!rl&&r
0015
scalar @{$def->{"start"};} and not scalar @{$def->{"end"};} and $y >= $def->{"start"}[0]
!ll&&!rl&&r
0015
scalar @{$def->{"start"};} and not scalar @{$def->{"end"};}
!ll&&!rl&&r
0015
MC/DC0%0/5
scalar @{$def->{"start"};} and not scalar @{$def->{"end"};} and $y >= $def->{"start"}[0] and $m >= $def->{"start"}[1] and $d >= $def->{"start"}[2]
scalar @{$def->{"start"};} not scalar @{$def->{"end"};} $y >= $def->{"start"}[0] $m >= $def->{"start"}[1] $d >= $def->{"start"}[2]
Truth table16%1/6
A and not(B) and C and D and E
A= scalar @{$def->{"start"};}B= not scalar @{$def->{"end"};}C= $y >= $def->{"start"}[0]D= $m >= $def->{"start"}[1]E= $d >= $def->{"start"}[2]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
893 15 !scalar( @{$def->{end}} ) &&
894 $y >= $def->{start}->[0] &&
895 $m >= $def->{start}->[1] &&
896 $d >= $def->{start}->[2] )
897 {
898 15 $era = DateTime::Format::JP::Era->new( $def );
899 15 last;
900 }
901 }
902 15 return( $era );
903 }
904  
905 sub make_datetime
906 78 ▶{
Subroutine make_datetime: called CC=15 SCAR=27.8
Pod documented
907 78 my $self = shift( @_ );
908 78 my $opts = shift( @_ );
909 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
910 78 ▶ return( $self->error( "Parameter provided is not an hash reference." ) ) if( ref( $opts ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts ne "HASH" 0 78 78
911 78 for( qw( year month day ) )
912 {
913 234 ▶ return( $self->error( "Missing the $_ parameter." ) ) if( !length( $opts->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $opts->{$_} 0 234 234
914 }
915 78 ▶ if( length( $opts->{ampm} ) && $opts->{ampm} eq '午後' )
Branch: 1 branch
BranchTrueFalseTotal
if (length $opts->{"ampm"} and $opts->{"ampm"} eq "\x{5348}\x{5f8c}") 15 63 78
Condition100%3/3
length $opts->{"ampm"} and $opts->{"ampm"} eq "\x{5348}\x{5f8c}"
!ll&&!rl&&r
60315
MC/DC100%2/2
length $opts->{"ampm"} and $opts->{"ampm"} eq "\x{5348}\x{5f8c}"
length $opts->{"ampm"} $opts->{"ampm"} eq "\x{5348}\x{5f8c}"
Truth table100%3/3
A and B
A= length $opts->{"ampm"}B= $opts->{"ampm"} eq "\x{5348}\x{5f8c}"
ABresult
0X0
100
111
916 {
917 15 $opts->{hour} += 12;
918 }
919
920 78 local $@;
921 # try-catch
922 my $rv = eval
923 78 {
924 78 my $dt;
925 78 ▶ if( $opts->{era} && ref( $opts->{era} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'era'} and ref $opts->{'era'}) { } 44 34 78
Condition66%2/3
$opts->{"era"} and ref $opts->{"era"}
!ll&&!rl&&r
34044
MC/DC50%1/2
$opts->{"era"} and ref $opts->{"era"}
$opts->{"era"} ref $opts->{"era"}
Truth table66%2/3
A and B
A= $opts->{"era"}B= ref $opts->{"era"}
ABresult
0X0
100
111
926 {
927 44 my $era = $opts->{era};
928 44 $dt = $era->start_datetime;
929 44 ▶ $dt->add( years => ( $opts->{year} - 1 ) ) if( $opts->{year} > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"year"} > 1 44 0 44
930 44 $dt->set_month( $opts->{month} );
931 44 $dt->set_day( $opts->{day} );
932 }
933 else
934 {
935 my $p =
936 {
937 year => $opts->{year},
938 month => $opts->{month},
939 day => $opts->{day},
940 34 };
941 34 ▶ if( length( $opts->{time_zone} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (length $opts->{'time_zone'}) { } 0 34 34
elsif (length $self->{'time_zone'}) { } 0 34 34
942 {
943 0 $p->{time_zone} = $opts->{time_zone};
944 }
945 elsif( length( $self->{time_zone} ) )
946 {
947 0 $p->{time_zone} = $self->{time_zone};
948 }
949
950 34 $dt = DateTime::Lite->new( %$p );
951 };
952 78 ▶ $dt->set_hour( $opts->{hour} ) if( $opts->{hour} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"hour"} 66 12 78
953 78 ▶ $dt->set_minute( $opts->{minute} ) if( $opts->{minute} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"minute"} 47 31 78
954 78 ▶ $dt->set_second( $opts->{second} ) if( $opts->{second} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"second"} 15 63 78
955 78 return( $dt );
956 };
957 78 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 78 78
958 {
959 0 return( $@ );
960 }
961 78 return( $rv );
962 }
963  
964 sub message
965 0 ▶{
Subroutine message: not called CC=4 SCAR=30.0
Pod undocumented
966 0 my $self = shift( @_ );
967 0 my $level = shift( @_ );
968 0 ▶ return(1) if( $self->{debug} < int( $level // 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} < int($level // 0) 0 0 0
Condition0%0/2
$level // 0
l!l
00
MC/DC0%0/1
$level // 0
$level
Truth table0%0/2
A
A= $level
Aresult
11
00
969 0 ▶ my $msg = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
970 0 chomp( $msg );
971 0 print( STDERR "# ", join( "\n# ", split( /\n/, $msg ) ), "\n" );
972 0 return(1);
973 }
974  
975 sub parse_datetime
976 78 ▶{
Subroutine parse_datetime: called CC=22 SCAR=33.8
Pod documented
977 78 my $self = shift( @_ );
978 78 my $str = shift( @_ );
979 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
980 78 ▶ if( $str =~ /$DATETIME_PATTERN_1_RE/ )
Branch: 3 branches
BranchTrueFalseTotal
if ($str =~ /$DateTime::Format::JP::DATETIME_PATTERN_1_RE/x) { } 53 25 78
elsif ($str =~ /$DateTime::Format::JP::DATETIME_PATTERN_2_RE/x) { } 0 25 25
elsif ($str =~ /$DateTime::Format::JP::DATETIME_PATTERN_3_RE/x) { } 25 0 25
981 {
982 53 my $re = { %+ };
983 53 ▶ if( $re->{era} )
Branch: 1 branch
BranchTrueFalseTotal
if ($re->{'era'}) { } 29 24 53
984 {
985 29 ▶ my $era = $self->lookup_era( $re->{era} ) ||
Condition50%1/2
$self->lookup_era($re->{'era'}) || (return $self->error(qq[No era "$re->{'era'}" could be found.]))
l!l
290
MC/DC0%0/1
$self->lookup_era($re->{'era'}) || (return $self->error(qq[No era "$re->{'era'}" could be found.]))
$self->lookup_era($re->{'era'})
Truth table50%1/2
A
A= $self->lookup_era($re->{'era'})
Aresult
11
00
986 return( $self->error( "No era \"$re->{era}\" could be found." ) );
987 29 $re->{era} = $era;
988 }
989 else
990 {
991 24 $re->{year} = delete( $re->{gregorian_year} );
992 }
993 53 for( qw( year month day ) )
994 {
995 159 ▶ next if( $re->{ $_ } =~ /^[0-9]+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $re->{$_} =~ /^[0-9]+$/ 109 50 159
996 50 my $rv = $self->zenkaku_to_romaji( $re->{ $_ } );
997 # Pass on the error, if any
998 50 ▶ return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 50 50
999 50 $re->{ $_ } = $rv;
1000 }
1001 53 for( qw( hour minute second ) )
1002 {
1003 159 ▶ next if( !length( $re->{ $_ } ) || $re->{ $_ } =~ /^[0-9]+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if not length $re->{$_} or $re->{$_} =~ /^[0-9]+$/ 127 32 159
Condition100%3/3
not length $re->{$_} or $re->{$_} =~ /^[0-9]+$/
l!l&&r!l&&!r
725532
MC/DC100%2/2
not length $re->{$_} or $re->{$_} =~ /^[0-9]+$/
not length $re->{$_} $re->{$_} =~ /^[0-9]+$/
Truth table100%3/3
not(A) or B
A= not length $re->{$_}B= $re->{$_} =~ /^[0-9]+$/
ABresult
1X1
011
000
1004 32 my $rv = $self->zenkaku_to_romaji( $re->{ $_ } );
1005 # Pass on the error, if any
1006 32 ▶ return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 32 32
1007 32 $re->{ $_ } = $rv;
1008 }
1009 53 $self->_dump( $re );
1010 53 return( $self->make_datetime( $re ) );
1011 }
1012 # With full width roman number
1013 elsif( $str =~ /$DATETIME_PATTERN_2_RE/ )
1014 {
1015 0 my $re = { %+ };
1016 0 ▶ if( $re->{era} )
Branch: 1 branch
BranchTrueFalseTotal
if ($re->{'era'}) { } 0 0 0
1017 {
1018 0 ▶ my $era = $self->lookup_era( $re->{era} ) ||
Condition0%0/2
$self->lookup_era($re->{'era'}) || (return $self->error(qq[No era "$re->{'era'}" could be found.]))
l!l
00
MC/DC0%0/1
$self->lookup_era($re->{'era'}) || (return $self->error(qq[No era "$re->{'era'}" could be found.]))
$self->lookup_era($re->{'era'})
Truth table0%0/2
A
A= $self->lookup_era($re->{'era'})
Aresult
11
00
1019 return( $self->error( "No era \"$re->{era}\" could be found." ) );
1020 0 $re->{era} = $era;
1021 }
1022 else
1023 {
1024 0 $re->{year} = delete( $re->{gregorian_year} );
1025 }
1026 0 $self->_dump( $re );
1027 0 return( $self->make_datetime( $re ) );
1028 }
1029 # With numbers in Kanji
1030 elsif( $str =~ /$DATETIME_PATTERN_3_RE/ )
1031 {
1032 25 my $re = { %+ };
1033 25 ▶ if( $re->{era} )
Branch: 1 branch
BranchTrueFalseTotal
if ($re->{'era'}) { } 15 10 25
1034 {
1035 15 ▶ my $era = $self->lookup_era( $re->{era} ) ||
Condition50%1/2
$self->lookup_era($re->{'era'}) || (return $self->error(qq[No era "$re->{'era'}" could be found.]))
l!l
150
MC/DC0%0/1
$self->lookup_era($re->{'era'}) || (return $self->error(qq[No era "$re->{'era'}" could be found.]))
$self->lookup_era($re->{'era'})
Truth table50%1/2
A
A= $self->lookup_era($re->{'era'})
Aresult
11
00
1036 return( $self->error( "No era \"$re->{era}\" could be found." ) );
1037 15 $re->{era} = $era;
1038 }
1039 else
1040 {
1041 10 $re->{year} = delete( $re->{gregorian_year} );
1042 }
1043 25 for( qw( year month day ) )
1044 {
1045 75 my $rv = $self->kanji_to_romaji( $re->{ $_ } );
1046 # Pass on the error, if any
1047 75 ▶ return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 75 75
1048 75 $re->{ $_ } = $rv;
1049 }
1050 25 for( qw( hour minute second ) )
1051 {
1052 75 ▶ next if( !length( $re->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $re->{$_} 34 41 75
1053 41 my $rv = $self->kanji_to_romaji( $re->{ $_ } );
1054 # Pass on the error, if any
1055 41 ▶ return( $self->error( "Unable to transcode full width number \"", $re->{ $_ }, "\" in \"$_\" to half width." ) ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 41 41
1056 41 $re->{ $_ } = $rv;
1057 }
1058 25 return( $self->make_datetime( $re ) );
1059 }
1060 else
1061 {
1062 0 return( $self->error( "Unknown datetime pattern \"$str\"" ) );
1063 }
1064 }
1065  
1066 sub romaji_to_kanji
1067 40 ▶{
Subroutine romaji_to_kanji: called CC=16 SCAR=27.9
Pod documented
1068 40 my $self = shift( @_ );
1069 40 my $num = shift( @_ );
1070 40 ▶ return( $num ) if( !defined( $num ) || !length( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num and length $num 0 40 40
Condition33%1/3
defined $num and length $num
!ll&&!rl&&r
0040
MC/DC0%0/2
defined $num and length $num
defined $num length $num
Truth table33%1/3
A and B
A= defined $numB= length $num
ABresult
0X0
100
111
1071 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
1072 40 my $buff = [];
1073 40 $num =~ s/[^0-9]+//g;
1074 40 ▶ if( $num =~ s/^(\d)(\d{3})$/$2/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ s/^(\d)(\d{3})$/$2/) 6 34 40
1075 {
1076 6 ▶ push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '千' );
Branch: 1 branch
BranchTrueFalseTotal
$1 > 1 ? : 5 1 6
1077 }
1078 40 $num =~ s/^0+([1-9][0-9]*)$/$1/;
1079
1080 40 ▶ unless( !length( $num ) || $num =~ /^0+$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless (not length $num or $num =~ /^0+$/) 39 1 40
Condition66%2/3
not length $num or $num =~ /^0+$/
l!l&&r!l&&!r
0139
MC/DC50%1/2
not length $num or $num =~ /^0+$/
not length $num $num =~ /^0+$/
Truth table66%2/3
not(A) or B
A= not length $numB= $num =~ /^0+$/
ABresult
1X1
011
000
1081 {
1082 39 ▶ if( $num =~ s/^(\d)(\d{2})$/$2/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ s/^(\d)(\d{2})$/$2/) 7 32 39
1083 {
1084 7 ▶ push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '百' );
Branch: 1 branch
BranchTrueFalseTotal
$1 > 1 ? : 5 2 7
1085 }
1086 39 $num =~ s/^0+([1-9][0-9]*)$/$1/;
1087
1088 39 ▶ unless( !length( $num ) || $num =~ /^0+$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless (not length $num or $num =~ /^0+$/) 38 1 39
Condition66%2/3
not length $num or $num =~ /^0+$/
l!l&&r!l&&!r
0138
MC/DC50%1/2
not length $num or $num =~ /^0+$/
not length $num $num =~ /^0+$/
Truth table66%2/3
not(A) or B
A= not length $numB= $num =~ /^0+$/
ABresult
1X1
011
000
1089 {
1090 38 ▶ if( $num =~ s/^(\d)(\d)$/$2/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ s/^(\d)(\d)$/$2/) 22 16 38
1091 {
1092 22 ▶ push( @$buff, ( $1 > 1 ? $KANJI_NUMBERS->[ $1 ] : () ), '十' );
Branch: 1 branch
BranchTrueFalseTotal
$1 > 1 ? : 11 11 22
1093 }
1094 38 ▶ $num = '' if( $num == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $num == 0 7 31 38
1095  
1096 38 ▶ unless( !length( $num ) || $num =~ /^0+$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless (not length $num or $num =~ /^0+$/) 31 7 38
Condition66%2/3
not length $num or $num =~ /^0+$/
l!l&&r!l&&!r
7031
MC/DC50%1/2
not length $num or $num =~ /^0+$/
not length $num $num =~ /^0+$/
Truth table66%2/3
not(A) or B
A= not length $numB= $num =~ /^0+$/
ABresult
1X1
011
000
1097 {
1098 31 push( @$buff, $KANJI_NUMBERS->[ $num ] );
1099 }
1100 }
1101 }
1102 40 return( join( '', @$buff ) );
1103 }
1104  
1105 sub romaji_to_kanji_simple
1106 3 ▶{
Subroutine romaji_to_kanji_simple: called CC=5 SCAR=16.4
Pod documented
1107 3 my $self = shift( @_ );
1108 3 my $num = shift( @_ );
1109 3 ▶ return( $num ) if( !defined( $num ) || !length( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num and length $num 0 3 3
Condition33%1/3
defined $num and length $num
!ll&&!rl&&r
003
MC/DC0%0/2
defined $num and length $num
defined $num length $num
Truth table33%1/3
A and B
A= defined $numB= length $num
ABresult
0X0
100
111
1110 3 my $buff = [];
1111 3 foreach( split( //, $num ) )
1112 {
1113 13 ▶ if( $_ !~ /^[0-9]$/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /^[0-9]$/) 1 12 13
1114 {
1115 1 push( @$buff, $_ );
1116 1 next;
1117 }
1118 12 push( @$buff, $KANJI_NUMBERS->[ $_ ] );
1119 }
1120 3 return( join( '', @$buff ) );
1121 }
1122  
1123 sub romaji_to_zenkaku
1124 63 ▶{
Subroutine romaji_to_zenkaku: called CC=6 SCAR=18.3
Pod documented
1125 63 my $self = shift( @_ );
1126 63 my $num = shift( @_ );
1127 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
1128 # Already done
1129 63 ▶ return( $num ) if( $num =~ /^[0123456789]+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $num =~ /^[\x{ff10}\x{ff11}\x{ff12}\x{ff13}\x{ff14}\x{ff15}\x{ff16}\x{ff17}\x{ff18}\x{ff19}]+$/ 0 63 63
1130 63 my $buff = [];
1131 63 for( split( //, $num ) )
1132 {
1133 135 ▶ if( /^[0123456789]$/ )
Branch: 2 branches
BranchTrueFalseTotal
if (/^[\x{ff10}\x{ff11}\x{ff12}\x{ff13}\x{ff14}\x{ff15}\x{ff16}\x{ff17}\x{ff18}\x{ff19}]$/) { } 0 135 135
elsif (/^[0-9]$/) { } 134 1 135
1134 {
1135 0 push( @$buff, $_ );
1136 }
1137 elsif( /^[0-9]$/ )
1138 {
1139 134 push( @$buff, $ZENKAKU_NUMBERS->[ $_ ] );
1140 }
1141 else
1142 {
1143 1 ▶ warnings::warn( "Unknown character \"$_\" in number \"$num\" to be cnverted into full width.\n" ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 1 1
1144 1 push( @$buff, $_ );
1145 }
1146 }
1147 63 return( join( '', @$buff ) );
1148 }
1149  
1150 0 ▶sub time_zone { return( shift->_set_get( 'time_zone', @_ ) ); }
Subroutine time_zone: not called CC=1 SCAR=6.9
Pod documented
1151  
1152 0 ▶sub traditional { return( shift->_set_get( 'traditional', @_ ) ); }
Subroutine traditional: not called CC=1 SCAR=6.9
Pod documented
1153  
1154 0 ▶sub zenkaku { return( shift->_set_get_zenkaku( 'zenkaku', @_ ) ); }
Subroutine zenkaku: not called CC=1 SCAR=6.9
Pod documented
1155  
1156 82 ▶sub zenkaku_to_romaji { return( shift->_get_pos_in_array( $ZENKAKU_NUMBERS, @_ ) ); }
Subroutine zenkaku_to_romaji: called CC=1 SCAR=0.0
Pod documented
1157  
1158 sub _dump
1159 53 ▶{
Subroutine _dump: called CC=3 SCAR=15.1
1160 53 my $self = shift( @_ );
1161 53 my $ref = shift( @_ );
1162 53 ▶ return(1) if( !$self->{debug} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug"} 53 0 53
1163 0 foreach my $k ( sort( keys( %$ref ) ) )
1164 {
1165 0 printf( STDERR "%-12s: %s\n", $k, $ref->{ $k } );
1166 }
1167 0 print( STDERR "-" x 20, "\n" );
1168 0 return(1);
1169 }
1170  
1171 sub _get_pos_in_array
1172 208 ▶{
Subroutine _get_pos_in_array: called CC=9 SCAR=23.5
1173 208 my $self = shift( @_ );
1174 208 my $array = shift( @_ );
1175 208 my $num = shift( @_ );
1176 208 ▶ return( $self->error( "I was expecting an array reference, but I got \"$array\"." ) ) if( ref( $array ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $array ne "ARRAY" 0 208 208
1177 208 ▶ return( $self->error( "Array provided is empty!" ) ) if( !scalar( @$array ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$array 0 208 208
1178 208 ▶ return( $self->error( "No value provided to transcode!" ) ) if( !defined( $num ) || !length( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num and length $num 0 208 208
Condition33%1/3
defined $num and length $num
!ll&&!rl&&r
00208
MC/DC0%0/2
defined $num and length $num
defined $num length $num
Truth table33%1/3
A and B
A= defined $numB= length $num
ABresult
0X0
100
111
1179 208 my $buff = [];
1180 208 my( $index1 ) = grep{ $num eq $array->[$_] } 0..$#$array;
1181 208 ▶ return( $index1 ) if( length( $index1 ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $index1 168 40 208
1182
1183 40 for my $c ( split( //, $num ) )
1184 {
1185 80 ▶ if( $c =~ /^[0-9]$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /^[0-9]$/) 0 80 80
1186 {
1187 0 push( @$buff, $c );
1188 0 next;
1189 }
1190 80 my( $index ) = grep{ $c eq $array->[$_] } 0..$#$array;
1191 80 ▶ return( $self->error( "Failed to find the corresponding entry for \"$c\"." ) ) if( !length( $index ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $index 0 80 80
1192 80 push( @$buff, $index );
1193 }
1194 40 return( join( '', @$buff ) );
1195 }
1196  
1197 sub _set_get
1198 0 ▶{
Subroutine _set_get: not called CC=2 SCAR=17.9
1199 0 my $self = shift( @_ );
1200 0 my $field = shift( @_ );
1201 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1202 {
1203 0 $self->{ $field } = shift( @_ );
1204 }
1205 0 return( $self->{ $field } );
1206 }
1207  
1208 sub _set_get_zenkaku
1209 0 ▶{
Subroutine _set_get_zenkaku: not called CC=4 SCAR=30.0
1210 0 my $self = shift( @_ );
1211 0 my $field = shift( @_ );
1212 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1213 {
1214 0 my $v = shift( @_ );
1215 0 $self->{ $field } = $v;
1216 0 ▶ if( $field eq 'zenkaku' )
Branch: 2 branches
BranchTrueFalseTotal
if ($field eq 'zenkaku') { } 0 0 0
elsif ($field eq 'hankaku') { } 0 0 0
1217 {
1218 0 $self->{hankaku} = !$v;
1219 }
1220 elsif( $field eq 'hankaku' )
1221 {
1222 0 $self->{zenkaku} = !$v;
1223 }
1224 }
1225 0 return( $self->{ $field } );
1226 }
1227  
1228 # NOTE: DateTime::Format::JP::Era class
1229 {
1230 package
1231 DateTime::Format::JP::Era;
1232 BEGIN
1233 {
1234 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1235 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1236 2 ▶ use parent qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
1237 2 ▶ use vars qw( $ERROR );
Subroutine BEGIN: called CC=1 SCAR=0.0
1238 2 ▶ use DateTime::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
1239 2 ▶ use DateTime::Lite::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
1240 2 ▶ use constant HAS_LOCAL_TZ => ( eval( qq{DateTime::Lite::TimeZone->new( name => 'local' );} ) ? 1 : 0 );
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
eval q[DateTime::Lite::TimeZone->new( name => 'local' );] ? : 0 2 2
1241 };
1242  
1243 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1244 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1245
1246 # my $era = DateTime::Format::JP::Era->new( $era_dictionary_hash_ref );
1247 59 ▶ sub new { return( bless( $_[1] => ( ref( $_[0] ) || $_[0] ) ) ); }
Subroutine new: called CC=2 SCAR=9.2
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
0590
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
1248
1249 sub error
1250 0 ▶ {
Subroutine error: not called CC=5 SCAR=34.0
1251 0 my $self = shift( @_ );
1252 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1253 {
1254 0 ▶ $self->{error} = $ERROR = join( '', map( ( ref( $_ ) eq 'CODE' ) ? $_->() : $_, @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'CODE' ? : 0 0 0
1255 0 ▶ warnings::warn( $ERROR, "\n" ) if( warnings::enabled( 'DateTime::Format::JP' ) );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled("DateTime::Format::JP") 0 0 0
1256 0 return;
1257 }
1258 0 ▶ return( ref( $self ) ? $self->{error} : $ERROR );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
1259 }
1260  
1261 0 ▶ sub end { return( [@{shift->{end}}] ); }
Subroutine end: not called CC=1 SCAR=6.9
1262  
1263 0 ▶ sub end_datetime { return( shift->_get_datetime( 'end' ) ); }
Subroutine end_datetime: not called CC=1 SCAR=6.9
1264
1265 12 ▶ sub name { return( shift->{name} ); }
Subroutine name: called CC=1 SCAR=0.0
1266
1267 0 ▶ sub period { return( shift->{period} ); }
Subroutine period: not called CC=1 SCAR=6.9
1268
1269 0 ▶ sub reading { return( [@{shift->{reading}}] ); }
Subroutine reading: not called CC=1 SCAR=6.9
1270  
1271 0 ▶ sub start { return( [@{shift->{start}}] ); }
Subroutine start: not called CC=1 SCAR=6.9
1272
1273 44 ▶ sub start_datetime { return( shift->_get_datetime( 'start' ) ); }
Subroutine start_datetime: called CC=1 SCAR=0.0
1274
1275 sub year
1276 14 ▶ {
Subroutine year: called CC=1 SCAR=0.0
1277 14 my( $self, $dt ) = @_;
1278 # First year is Year 1 of an era no matter when it starts in that year
1279 14 return( ( $dt->year + 1 ) - $self->{start}->[0] );
1280 }
1281
1282 sub _get_datetime
1283 44 ▶ {
Subroutine _get_datetime: called CC=4 SCAR=14.6
1284 44 my $self = shift( @_ );
1285 44 my $field = shift( @_ );
1286 44 my $ref = $self->{ $field };
1287 44 local $@;
1288 # try-catch
1289 my $rv = eval
1290 44 {
1291 44 ▶ if( ref( $ref ) eq 'ARRAY' && scalar( @$ref ) == 3 )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref eq 'ARRAY' and scalar @$ref == 3) { } 44 0 44
Condition33%1/3
ref $ref eq "ARRAY" and scalar @$ref == 3
!ll&&!rl&&r
0044
MC/DC0%0/2
ref $ref eq "ARRAY" and scalar @$ref == 3
ref $ref eq "ARRAY" scalar @$ref == 3
Truth table33%1/3
A and B
A= ref $ref eq "ARRAY"B= scalar @$ref == 3
ABresult
0X0
100
111
1292 {
1293 44 my $opts = {};
1294 44 @$opts{qw( year month day )} = @$ref;
1295 44 @$opts{qw( hour minute second )} = (0,0,0);
1296 44 $opts->{time_zone} = ( HAS_LOCAL_TZ ? 'local' : 'UTC' );
1297 44 return( DateTime::Lite->new( %$opts ) );
1298 }
1299 else
1300 {
1301 0 return( DateTime::Lite->now( time_zone => ( HAS_LOCAL_TZ ? 'local' : 'UTC' ) ) );
1302 }
1303 };
1304 44 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 44 44
1305 {
1306 0 return( $self->error( $@ ) );
1307 }
1308 44 return( $rv );
1309 }
1310 }
1311  
1312 2 1;
1313 # NOTE: POD
1314 __END__
↑ Summary