File Coverage

blib/lib/DateTime/Format/Alami/ID.pm
Criterion Covered Total %
statement 24 54 44.4
branch n/a
condition n/a
subroutine 15 45 33.3
pod 0 38 0.0
total 39 137 28.4


line stmt bran cond sub pod time code
1             package DateTime::Format::Alami::ID;
2              
3             our $DATE = '2016-06-30'; # DATE
4             our $VERSION = '0.13'; # VERSION
5              
6 3     3   1187 use 5.014000;
  3         7  
7 3     3   15 use strict;
  3         4  
  3         73  
8 3     3   12 use warnings;
  3         3  
  3         96  
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   1442 use Parse::Number::ID qw(parse_number_id);
  3         1970  
  3         2193  
15              
16 3     3 0 8 sub o_num { $Parse::Number::ID::Pat }
17 31     31   62 sub _parse_num { parse_number_id(text => $_[1]) }
18 6     6 0 17 sub w_year { ["tahun", "thn", "th"] }
19 6     6 0 15 sub w_month { ["bulan", "bul", "bln", "bl"] }
20 6     6 0 14 sub w_week { ["minggu", "mgg", "mg"] }
21 6     6 0 16 sub w_day { ["hari", "hr", "h"] }
22 6     6 0 14 sub w_hour { ["jam", "j"] }
23 6     6 0 15 sub w_minute { ["menit", "mnt"] }
24 6     6 0 28 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             '(?: (?:\s+|-|/)? | (?:\s+|-|/)\b )',
60             '(?: \s*[,/-]?\s* (?{ 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_dur_ago { " \\s+ (?:(?:(?:yang|yg) \\s+)?lalu|tadi|td|yll?)" }
65 0     0 0   sub p_dur_later { " \\s+ (?:(?:(?:yang|yg) \\s+)?akan \\s+ (?:datang|dtg)|yad|lagi|lg)" }
66              
67 0     0 0   sub p_which_dow { join(
68             "",
69             '(?{ $DateTime::Format::Alami::_offset = 0 })',
70             "(?:",
71             ' ',
72             ' (?: (?:\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)?)',
73             ")",
74             '(?{ $DateTime::Format::Alami::m->{offset} = $DateTime::Format::Alami::_offset })',
75             )}
76              
77 0     0 0   sub o_date { "(?: ||||)" }
78 0     0 0   sub p_time { "(?: [:.](?: [:.])?)" }
79 0     0 0   sub p_date_time { "(?: \\s+ (?:(?:pada \\s+)? (jam|j|pukul|pkl?)\\s*)? )" }
80              
81             # the ordering is a bit weird because: we need to apply role at compile-time
82             # before the precomputed $RE mentions $o & $m thus creating the package
83             # DateTime::Format::Alami and this makes Role::Tiny::With complains that DT:F:A
84             # is not a role. then, if we are to apply the role, we need to already declare
85             # the methods required by the role.
86              
87 3     3   1431 use Role::Tiny::With;
  3         8176  
  3         158  
88 3     3   9 BEGIN { with 'DateTime::Format::Alami' };
89              
90             our $RE_DT = qr((?&top)(?(DEFINE)(?(?&p_dur_ago)|(?&p_date_time)|(?&p_dur_later)|(?&p_time)|(?&p_which_dow)|(?&p_today)|(?&p_tomorrow)|(?&p_yesterday)|(?&p_dateymd)|(?&p_now))(? (\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) }))(? (\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) }))(? (\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) }))(? ((?: (?&p_which_dow)|(?&p_today)|(?&p_tomorrow)|(?&p_yesterday)|(?&p_dateymd)))(?{ $DateTime::Format::Alami::m->{o_date} = $^N }))(? (\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) }))(? ((?:((?:[+-]?(?:\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 }))(? (\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) }))(? (\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) }))(? (\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) }))(? (\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) }))(? (\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) }))(? ((?:[0-9][0-9]?))(?{ $DateTime::Format::Alami::m->{o_hour} = $^N }))(? ((?:[0-9][0-9]?))(?{ $DateTime::Format::Alami::m->{o_minute} = $^N }))(? ((?:[0-9][0-9]?))(?{ $DateTime::Format::Alami::m->{o_second} = $^N }))(? ((?:senin|sen|selasa|sel|rabu|rab|kamis|kam|jumat|jum'at|jum|sabtu|sab|minggu|min))(?{ $DateTime::Format::Alami::m->{o_dow} = $^N }))(? ((?: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 }))(? ((?:[12][0-9]|3[01]|0?[1-9]))(?{ $DateTime::Format::Alami::m->{o_dayint} = $^N }))(? ((?:0?[1-9]|1[012]))(?{ $DateTime::Format::Alami::m->{o_monthint} = $^N }))(? ((?:[0-9]{4}|[0-9]{2}))(?{ $DateTime::Format::Alami::m->{o_yearint} = $^N }))(? ((?:((?:[+-]?(?:\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 }))(? (\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) }))(? ((?:[+-]?(?:\d{1,2}(?:[.]\d{3})*(?:[,]\d*)?|\d{1,2}(?:[,]\d{3})*(?:[.]\d*)?|[,.]\d+|\d+)(?:[Ee][+-]?\d+)?))(?{ $DateTime::Format::Alami::m->{o_num} = $^N }))(? ((?: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 }))(? ((?: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 }
91             our $RE_DUR = qr((?&top)(?(DEFINE)(?(?&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) }))(? ((?:((?:[+-]?(?:\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 }
92             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 }
93              
94             1;
95             # ABSTRACT: Parse human date/time/duration expression (Indonesian)
96              
97             __END__