File Coverage

blib/lib/DateTime/Format/Alami/ID.pm
Criterion Covered Total %
statement 24 55 43.6
branch n/a
condition n/a
subroutine 15 46 32.6
pod 0 39 0.0
total 39 140 27.8


line stmt bran cond sub pod time code
1             package DateTime::Format::Alami::ID;
2              
3             our $DATE = '2017-07-10'; # DATE
4             our $VERSION = '0.16'; # VERSION
5              
6 3     3   2352 use 5.014000;
  3         14  
7 3     3   22 use strict;
  3         18  
  3         770  
8 3     3   21 use warnings;
  3         9  
  3         106  
9              
10             # XXX holidays -> christmas | new year | ...
11             # XXX WIB in time, e.g. 13.00 WIB
12             # XXX *se*minggu (instead of 1 minggu), etc
13              
14 3     3   2235 use Parse::Number::ID qw(parse_number_id);
  3         4134  
  3         2491  
15              
16 3     3 0 11 sub o_num { $Parse::Number::ID::Pat }
17 31     31   112 sub _parse_num { parse_number_id(text => $_[1]) }
18 6     6 0 35 sub w_year { ["tahun", "thn", "th"] }
19 6     6 0 25 sub w_month { ["bulan", "bul", "bln", "bl"] }
20 6     6 0 28 sub w_week { ["minggu", "mgg", "mg"] }
21 6     6 0 26 sub w_day { ["hari", "hr", "h"] }
22 6     6 0 23 sub w_hour { ["jam", "j"] }
23 6     6 0 23 sub w_minute { ["menit", "mnt"] }
24 6     6 0 44 sub w_second { ["detik", "det", "dtk", "dt"] }
25              
26 0     0 0   sub w_jan { ["januari", "jan"] }
27 0     0 0   sub w_feb { ["februari", "pebruari", "feb", "peb"] }
28 0     0 0   sub w_mar { ["maret", "mar"] }
29 0     0 0   sub w_apr { ["april", "apr"] }
30 0     0 0   sub w_may { ["mei"] }
31 0     0 0   sub w_jun { ["juni", "jun"] }
32 0     0 0   sub w_jul { ["juli", "jul"] }
33 0     0 0   sub w_aug { ["agustus", "agu", "agt"] }
34 0     0 0   sub w_sep { ["september", "sept", "sep"] }
35 0     0 0   sub w_oct { ["oktober", "okt"] }
36 0     0 0   sub w_nov { ["november", "nopember", "nov", "nop"] }
37 0     0 0   sub w_dec { ["desember", "des"] }
38              
39 0     0 0   sub w_monday { ["senin", "sen"] }
40 0     0 0   sub w_tuesday { ["selasa", "sel"] }
41 0     0 0   sub w_wednesday { ["rabu", "rab"] }
42 0     0 0   sub w_thursday { ["kamis", "kam"] }
43 0     0 0   sub w_friday { ["jumat", "jum'at", "jum"] }
44 0     0 0   sub w_saturday { ["sabtu", "sab"] }
45 0     0 0   sub w_sunday { ["minggu", "min"] }
46              
47 0     0 0   sub p_now { "(?:saat \\s+ ini|sekarang|skrg?)" }
48 0     0 0   sub p_today { "(?:hari \\s+ ini)" }
49 0     0 0   sub p_tomorrow { "(?:b?esok|bsk)" }
50 0     0 0   sub p_yesterday { "(?:kemar[ei]n|kmrn)" }
51 0     0 0   sub p_dateymd { join(
52             # we use the 'local' trick here in embedded code (see perlre) to be
53             # backtrack-safe. we want to unset $m->{o_yearint} when date does not
54             # contain year. $m->{o_yearint} might be set when we try the patterns but
55             # might end up needing to be unset if the matching pattern ends up not
56             # having year.
57             "",
58             '(?{ $DateTime::Format::Alami::_has_year = 0 })',
59             '(?: <o_dayint>(?:\s+|-|/)?<o_monthname> | <o_dayint>(?:\s+|-|/)<o_monthint>\b )',
60             '(?: \s*[,/-]?\s* <o_yearint> (?{ local $DateTime::Format::Alami::_has_year = $DateTime::Format::Alami::_has_year + 1 }))?',
61             '(?{ delete $DateTime::Format::Alami::m->{o_yearint} unless $DateTime::Format::Alami::_has_year })',
62             )}
63              
64 0     0 0   sub p_dateym { join(
65             "",
66             '(?: <o_monthname> )',
67             '(?: (?:\s*[,/-]?\s* <o_year4int> | \s*\'<o_year2int>\\b) (?{ local $DateTime::Format::Alami::_has_year = $DateTime::Format::Alami::_has_year + 1 }) )',
68             )}
69              
70 0     0 0   sub p_dur_ago { "<o_dur> \\s+ (?:(?:(?:yang|yg) \\s+)?lalu|tadi|td|yll?)" }
71 0     0 0   sub p_dur_later { "<o_dur> \\s+ (?:(?:(?:yang|yg) \\s+)?akan \\s+ (?:datang|dtg)|yad|lagi|lg)" }
72              
73 0     0 0   sub p_which_dow { join(
74             "",
75             '(?{ $DateTime::Format::Alami::_offset = 0 })',
76             "(?:",
77             ' <o_dow>',
78             ' (?: (?:\s+ (?:(?:minggu|mgg|mg)\s+)? (?:lalu))(?{ local $DateTime::Format::Alami::_offset = -1 }) | (?:\s+ (?:(?:minggu|mgg|mg)\s+)? (?:depan|dpn))(?{ local $DateTime::Format::Alami::_offset = 1 }) | (?:\s+ (?:(?:minggu|mgg|mg)\s+)? ini)?)',
79             ")",
80             '(?{ $DateTime::Format::Alami::m->{offset} = $DateTime::Format::Alami::_offset })',
81             )}
82              
83 0     0 0   sub o_date { "(?: <p_which_dow>|<p_today>|<p_tomorrow>|<p_yesterday>|<p_dateymd>)" }
84 0     0 0   sub p_time { "(?: <o_hour>[:.]<o_minute>(?: [:.]<o_second>)?)" }
85 0     0 0   sub p_date_time { "(?:<o_date> \\s+ (?:(?:pada \\s+)? (jam|j|pukul|pkl?)\\s*)? <p_time>)" }
86              
87             # the ordering is a bit weird because: we need to apply role at compile-time
88             # before the precomputed $RE mentions $o & $m thus creating the package
89             # DateTime::Format::Alami and this makes Role::Tiny::With complains that DT:F:A
90             # is not a role. then, if we are to apply the role, we need to already declare
91             # the methods required by the role.
92              
93 3     3   734 use Role::Tiny::With;
  3         6316  
  3         177  
94 3     3   19 BEGIN { with 'DateTime::Format::Alami' };
95              
96             our $RE_DT = qr((?&top)(?(DEFINE)(?<top>(?&p_dur_ago)|(?&p_date_time)|(?&p_dateym)|(?&p_dur_later)|(?&p_time)|(?&p_which_dow)|(?&p_today)|(?&p_tomorrow)|(?&p_yesterday)|(?&p_dateymd)|(?&p_now))(?<p_dur_ago> (\b (?&o_dur) \s+ (?:(?:(?:yang|yg) \s+)?lalu|tadi|td|yll?) \b)(?{ $DateTime::Format::Alami::m->{p_dur_ago} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_dur_ago"; $DateTime::Format::Alami::o->a_dur_ago($DateTime::Format::Alami::m) }))(?<p_date_time> (\b (?:(?&o_date) \s+ (?:(?:pada \s+)? (jam|j|pukul|pkl?)\s*)? (?&p_time)) \b)(?{ $DateTime::Format::Alami::m->{p_date_time} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_date_time"; $DateTime::Format::Alami::o->a_date_time($DateTime::Format::Alami::m) }))(?<p_dateym> (\b (?: (?&o_monthname) )(?: (?:\s*[,/-]?\s* (?&o_year4int) | \s*'(?&o_year2int)\b) (?{ local $DateTime::Format::Alami::_has_year = $DateTime::Format::Alami::_has_year + 1 }) ) \b)(?{ $DateTime::Format::Alami::m->{p_dateym} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_dateym"; $DateTime::Format::Alami::o->a_dateym($DateTime::Format::Alami::m) }))(?<p_dur_later> (\b (?&o_dur) \s+ (?:(?:(?:yang|yg) \s+)?akan \s+ (?:datang|dtg)|yad|lagi|lg) \b)(?{ $DateTime::Format::Alami::m->{p_dur_later} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_dur_later"; $DateTime::Format::Alami::o->a_dur_later($DateTime::Format::Alami::m) }))(?<o_date> ((?: (?&p_which_dow)|(?&p_today)|(?&p_tomorrow)|(?&p_yesterday)|(?&p_dateymd)))(?{ $DateTime::Format::Alami::m->{o_date} = $^N }))(?<p_time> (\b (?: (?&o_hour)[:.](?&o_minute)(?: [:.](?&o_second))?) \b)(?{ $DateTime::Format::Alami::m->{p_time} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_time"; $DateTime::Format::Alami::o->a_time($DateTime::Format::Alami::m) }))(?<o_year4int> ((?:[0-9]{4}))(?{ $DateTime::Format::Alami::m->{o_year4int} = $^N }))(?<o_year2int> ((?:[0-9]{2}))(?{ $DateTime::Format::Alami::m->{o_year2int} = $^N }))(?<o_dur> ((?:((?:[+-]?(?:\d{1,2}(?:[.]\d{3})*(?:[,]\d*)?|\d{1,2}(?:[,]\d{3})*(?:[.]\d*)?|[,.]\d+|\d+)(?:[Ee][+-]?\d+)?)\s*(?:tahun|thn|th|bulan|bul|bln|bl|minggu|mgg|mg|hari|hr|h|jam|j|menit|mnt|detik|det|dtk|dt)\s*(?:,\s*)?)+))(?{ $DateTime::Format::Alami::m->{o_dur} = $^N }))(?<p_which_dow> (\b (?{ $DateTime::Format::Alami::_offset = 0 })(?: (?&o_dow) (?: (?:\s+ (?:(?:minggu|mgg|mg)\s+)? (?:lalu))(?{ local $DateTime::Format::Alami::_offset = -1 }) | (?:\s+ (?:(?:minggu|mgg|mg)\s+)? (?:depan|dpn))(?{ local $DateTime::Format::Alami::_offset = 1 }) | (?:\s+ (?:(?:minggu|mgg|mg)\s+)? ini)?))(?{ $DateTime::Format::Alami::m->{offset} = $DateTime::Format::Alami::_offset }) \b)(?{ $DateTime::Format::Alami::m->{p_which_dow} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_which_dow"; $DateTime::Format::Alami::o->a_which_dow($DateTime::Format::Alami::m) }))(?<p_today> (\b (?:hari \s+ ini) \b)(?{ $DateTime::Format::Alami::m->{p_today} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_today"; $DateTime::Format::Alami::o->a_today($DateTime::Format::Alami::m) }))(?<p_tomorrow> (\b (?:b?esok|bsk) \b)(?{ $DateTime::Format::Alami::m->{p_tomorrow} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_tomorrow"; $DateTime::Format::Alami::o->a_tomorrow($DateTime::Format::Alami::m) }))(?<p_yesterday> (\b (?:kemar[ei]n|kmrn) \b)(?{ $DateTime::Format::Alami::m->{p_yesterday} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_yesterday"; $DateTime::Format::Alami::o->a_yesterday($DateTime::Format::Alami::m) }))(?<p_dateymd> (\b (?{ $DateTime::Format::Alami::_has_year = 0 })(?: (?&o_dayint)(?:\s+|-|/)?(?&o_monthname) | (?&o_dayint)(?:\s+|-|/)(?&o_monthint)\b )(?: \s*[,/-]?\s* (?&o_yearint) (?{ local $DateTime::Format::Alami::_has_year = $DateTime::Format::Alami::_has_year + 1 }))?(?{ delete $DateTime::Format::Alami::m->{o_yearint} unless $DateTime::Format::Alami::_has_year }) \b)(?{ $DateTime::Format::Alami::m->{p_dateymd} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_dateymd"; $DateTime::Format::Alami::o->a_dateymd($DateTime::Format::Alami::m) }))(?<o_hour> ((?:[0-9][0-9]?))(?{ $DateTime::Format::Alami::m->{o_hour} = $^N }))(?<o_minute> ((?:[0-9][0-9]?))(?{ $DateTime::Format::Alami::m->{o_minute} = $^N }))(?<o_second> ((?:[0-9][0-9]?))(?{ $DateTime::Format::Alami::m->{o_second} = $^N }))(?<o_dow> ((?:senin|sen|selasa|sel|rabu|rab|kamis|kam|jumat|jum'at|jum|sabtu|sab|minggu|min))(?{ $DateTime::Format::Alami::m->{o_dow} = $^N }))(?<o_monthname> ((?:januari|jan|februari|pebruari|feb|peb|maret|mar|april|apr|mei|juni|jun|juli|jul|agustus|agu|agt|september|sept|sep|oktober|okt|november|nopember|nov|nop|desember|des))(?{ $DateTime::Format::Alami::m->{o_monthname} = $^N }))(?<o_dayint> ((?:[12][0-9]|3[01]|0?[1-9]))(?{ $DateTime::Format::Alami::m->{o_dayint} = $^N }))(?<o_monthint> ((?:0?[1-9]|1[012]))(?{ $DateTime::Format::Alami::m->{o_monthint} = $^N }))(?<o_yearint> ((?:[0-9]{4}|[0-9]{2}))(?{ $DateTime::Format::Alami::m->{o_yearint} = $^N }))(?<o_timedur> ((?:((?:[+-]?(?:\d{1,2}(?:[.]\d{3})*(?:[,]\d*)?|\d{1,2}(?:[,]\d{3})*(?:[.]\d*)?|[,.]\d+|\d+)(?:[Ee][+-]?\d+)?)\s*(?:jam|j|menit|mnt|detik|det|dtk|dt)\s*(?:,\s*)?)+))(?{ $DateTime::Format::Alami::m->{o_timedur} = $^N }))(?<p_now> (\b (?:saat \s+ ini|sekarang|skrg?) \b)(?{ $DateTime::Format::Alami::m->{p_now} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "p_now"; $DateTime::Format::Alami::o->a_now($DateTime::Format::Alami::m) }))(?<o_num> ((?:[+-]?(?:\d{1,2}(?:[.]\d{3})*(?:[,]\d*)?|\d{1,2}(?:[,]\d{3})*(?:[.]\d*)?|[,.]\d+|\d+)(?:[Ee][+-]?\d+)?))(?{ $DateTime::Format::Alami::m->{o_num} = $^N }))(?<o_durwords> ((?:tahun|thn|th|bulan|bul|bln|bl|minggu|mgg|mg|hari|hr|h|jam|j|menit|mnt|detik|det|dtk|dt))(?{ $DateTime::Format::Alami::m->{o_durwords} = $^N }))(?<o_timedurwords> ((?:jam|j|menit|mnt|detik|det|dtk|dt))(?{ $DateTime::Format::Alami::m->{o_timedurwords} = $^N }))))ix; # PRECOMPUTED FROM: do { DateTime::Format::Alami::ID->new; $DateTime::Format::Alami::ID::RE_DT }
97             our $RE_DUR = qr((?&top)(?(DEFINE)(?<top>(?&pdur_dur))(?<pdur_dur> (\b (?:(?&odur_dur)) \b)(?{ $DateTime::Format::Alami::m->{pdur_dur} = $^N })(?{ $DateTime::Format::Alami::o->{_pat} = "pdur_dur"; $DateTime::Format::Alami::o->adur_dur($DateTime::Format::Alami::m) }))(?<odur_dur> ((?:((?:[+-]?(?:\d{1,2}(?:[.]\d{3})*(?:[,]\d*)?|\d{1,2}(?:[,]\d{3})*(?:[.]\d*)?|[,.]\d+|\d+)(?:[Ee][+-]?\d+)?)\s*(?:tahun|thn|th|bulan|bul|bln|bl|minggu|mgg|mg|hari|hr|h|jam|j|menit|mnt|detik|det|dtk|dt)\s*(?:,\s*)?)+))(?{ $DateTime::Format::Alami::m->{odur_dur} = $^N }))))ix; # PRECOMPUTED FROM: do { DateTime::Format::Alami::ID->new; $DateTime::Format::Alami::ID::RE_DUR }
98             our $MAPS = {dow=>{jum=>5,"jum'at"=>5,jumat=>5,kam=>4,kamis=>4,min=>7,minggu=>7,rab=>3,rabu=>3,sab=>6,sabtu=>6,sel=>2,selasa=>2,sen=>1,senin=>1},months=>{agt=>8,agu=>8,agustus=>8,apr=>4,april=>4,des=>12,desember=>12,feb=>2,februari=>2,jan=>1,januari=>1,jul=>7,juli=>7,jun=>6,juni=>6,mar=>3,maret=>3,mei=>5,nop=>11,nopember=>11,nov=>11,november=>11,okt=>10,oktober=>10,peb=>2,pebruari=>2,sep=>9,sept=>9,september=>9}}; # PRECOMPUTED FROM: do { DateTime::Format::Alami::ID->new; $DateTime::Format::Alami::ID::MAPS }
99              
100             1;
101             # ABSTRACT: Parse human date/time/duration expression (Indonesian)
102              
103             __END__
104              
105             =pod
106              
107             =encoding UTF-8
108              
109             =head1 NAME
110              
111             DateTime::Format::Alami::ID - Parse human date/time/duration expression (Indonesian)
112              
113             =head1 VERSION
114              
115             This document describes version 0.16 of DateTime::Format::Alami::ID (from Perl distribution DateTime-Format-Alami), released on 2017-07-10.
116              
117             =head1 DESCRIPTION
118              
119             List of known date/time expressions:
120              
121             # p_now
122             sekarang
123             saat ini
124              
125             # p_today
126             hari ini
127              
128             # p_tomorrow
129             besok
130              
131             # p_yesterday
132             kemarin
133              
134             # p_dur_ago, p_dur_later
135             1 tahun 2 bulan 3 minggu 4 hari 5 jam 6 menit 7 detik (lalu|lagi|nanti|yang akan datang)
136              
137             # p_dateymd
138             28 mei
139             28/5
140             28 mei 2016
141             28-5-2016
142             28-5-16
143              
144             # p_dateym
145             apr 2017
146             mei-2018
147             jun '17
148              
149             # p_which_dow
150             senin (minggu|mgg)? (ini|lalu|depan)
151              
152             # p_time
153             (pukul|jam)? 10.00
154             23:05:44
155              
156             # p_date_time
157             24 juni pk 13.00
158             24 juni 2015 13:00
159              
160             List of known duration expressions:
161              
162             # pdur_dur
163             1 tahun 2 bulan 3 minggu 4 hari 5 jam 6 menit 7 detik
164              
165             =for Pod::Coverage ^((adur|a|pdur|p|odur|o|w)_.+)$
166              
167             =head1 HOMEPAGE
168              
169             Please visit the project's homepage at L<https://metacpan.org/release/DateTime-Format-Alami>.
170              
171             =head1 SOURCE
172              
173             Source repository is at L<https://github.com/perlancar/perl-DateTime-Format-Alami>.
174              
175             =head1 BUGS
176              
177             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=DateTime-Format-Alami>
178              
179             When submitting a bug or request, please include a test-file or a
180             patch to an existing test-file that illustrates the bug or desired
181             feature.
182              
183             =head1 SEE ALSO
184              
185             L<DateTime::Format::Indonesian>
186              
187             L<Date::Extract::ID>
188              
189             =head1 AUTHOR
190              
191             perlancar <perlancar@cpan.org>
192              
193             =head1 COPYRIGHT AND LICENSE
194              
195             This software is copyright (c) 2017, 2016, 2014 by perlancar@cpan.org.
196              
197             This is free software; you can redistribute it and/or modify it under
198             the same terms as the Perl 5 programming language system itself.
199              
200             =cut