File Coverage

blib/lib/DateTime/Format/Flexible/lang/es.pm
Criterion Covered Total %
statement 20 29 68.9
branch n/a
condition n/a
subroutine 14 21 66.6
pod 11 11 100.0
total 45 61 73.7


line stmt bran cond sub pod time code
1             package DateTime::Format::Flexible::lang::es;
2              
3 17     17   13871 use strict;
  17         106  
  17         523  
4 17     17   123 use warnings;
  17         38  
  17         22903  
5              
6             sub new
7             {
8 0     0 1 0 my ( $class , %params ) = @_;
9 0         0 my $self = bless \%params , $class;
10 0         0 return $self;
11             }
12              
13             sub months
14             {
15             # http://llts.stanford.edu/months.html
16             # http://www.tarver-genealogy.net/aids/spanish/sp_dates_num.html#days
17             return (
18 7338     7338 1 106455 qr{enero|enro|eno}i => 1,
19             qr{febr(?:ero)?|febo}i => 2,
20             qr{marzo|mzo}i => 3,
21             qr{abr(?:il)?|abl}i => 4,
22             qr{\bmayo\b}i => 5,
23             qr{jun(?:io)?}i => 6,
24             qr{jul(?:io)?}i => 7,
25             qr{agosto|agto}i => 8,
26             qr{sept(?:iembre)}i => 9,
27             qr{septe|set}i => 9,
28             qr{oct(?:ubre)?}i => 10,
29             qr{nov(?:iembre)?}i => 11,
30             qr{novbre}i => 11,
31             qr{dic(?:iembre)?}i => 12,
32             qr{dice}i => 12,
33             );
34             }
35              
36             sub days
37             {
38             # http://www.tarver-genealogy.net/aids/spanish/sp_dates_num.html#days
39             return (
40 7338     7338 1 60895 qr{\blunes\b} => 1, # Monday
41             qr{\bmartes\b} => 2, # Tuesday
42             qr{\bmiércoles\b} => 3, # Wednesday
43             qr{\bjueves\b} => 4, # Thursday
44             qr{\bviernes\b} => 5, # Friday
45             qr{\bsábado\b} => 6, # Saturday
46             qr{\bdomingo\b} => 7, # Sunday
47             );
48             }
49              
50             sub day_numbers
51             {
52             # http://www.tarver-genealogy.net/aids/spanish/sp_dates_num.html#days
53             return (
54 3669     3669 1 127701 qr{primero} => 1, # first
55             qr{segundo} => 2, # second
56             qr{tercero} => 3, # third
57             qr{cuarto} => 4, # fourth
58             qr{quinto} => 5, # fifth
59             qr{sexto} => 6, # sixth
60             qr{septimo} => 7, # seventh
61             qr{octavo} => 8, # eighth
62             qr{nono|noveno} => 9, # ninth
63             qr{decimo} => 10, # tenth
64             qr{undecimo|decimoprimero} => 11, # eleventh
65             qr{duodecimo|decimosegundo} => 12, # twelfth
66             qr{decimotercero} => 13, # thirteenth
67             qr{decimocuarto} => 14, # fourteenth
68             qr{decimoquinto} => 15, # fifteenth
69             qr{decimosexto} => 16, # sixteenth
70             qr{decimo\sseptimo} => 17, # seventeenth
71             qr{decimoctavo} => 18, # eithteenth
72             qr{decimonono} => 19, # ninteenth
73             qr{vigesimo} => 20, # twentieth
74             qr{vigesimo\sprimero} => 21, # twenty first
75             qr{vigesimo\ssegundo} => 22, # twenty second
76             qr{vigesimo\stercero} => 23, # twenty third
77             qr{vigesimo\scuarto} => 24, # twenty fourth
78             qr{veinticuatro} => 24, # twenty four
79             qr{vigesimo\squinto} => 25, # twenty fifth
80             qr{vigesimo\ssexto} => 26, # twenty sixth
81             qr{vigesimo\sseptimo} => 27, # twenty seventh
82             qr{vigesimo\soctavo} => 28, # twenty eighth
83             qr{vigesimo\snono} => 29, # twenty ninth
84             qr{trigesimo} => 30, # thirtieth
85             qr{trigesimo\sprimero} => 31, # thirty first
86             );
87             }
88              
89             sub hours
90             {
91             return (
92 3669     3669 1 13840 mediodia => '12:00:00', # noon
93             medianoche => '00:00:00', # midnight
94             );
95             }
96              
97             sub remove_strings
98             {
99             return (
100 3669     3669 1 12066 qr{\bde\b}i, # remove ' de ' as in '29 de febrero de 1996'
101             );
102             }
103              
104             sub parse_time
105             {
106 3669     3669 1 8242 my ( $self, $date ) = @_;
107 3669         7946 return $date;
108             }
109              
110             sub string_dates
111             {
112 3669     3669 1 10425 my $base_dt = DateTime::Format::Flexible->base;
113             return (
114 0     0   0 ahora => sub { return $base_dt->datetime }, # now
115 0     0   0 hoy => sub { return $base_dt->clone->truncate( to => 'day' )->ymd } , # today
116 0     0   0 manana => sub { return $base_dt->clone->truncate( to => 'day' )->add( days => 1 )->ymd }, # tomorrow
117 0     0   0 ayer => sub { return $base_dt->clone->truncate( to => 'day' )->subtract( days => 1 )->ymd }, # yesterday
118 0     0   0 'pasado manana' => sub { return DateTime->today->add( days => 2 )->ymd }, # overmorrow (the day after tomorrow)
119 1     1   7 epoca => sub { return DateTime->from_epoch( epoch => 0 ) },
120 0     0   0 '-infinito' => sub { return '-infinity' },
121 2     2   5 infinito => sub { return 'infinity' },
122 3669         975173 );
123             }
124              
125             sub relative
126             {
127             return (
128             # as in 3 years ago, -3 years
129 3669     3669 1 25258 ago => qr{\bhace\b|\A\-}i,
130             # as in 3 years from now, +3 years
131             from => qr{\ba\b\s\bpartir\b\s\bde\b\s\bahora\b|\A\+}i,
132             # as in next Monday
133             next => qr{\bsiguiente\b}i,
134             # as in last Monday
135             last => qr{\bpasado\b}i,
136             );
137             }
138              
139             sub math_strings
140             {
141             return (
142 1     1 1 15 ano => 'years' ,
143             anos => 'years' ,
144             'años' => 'years' ,
145             mes => 'months' ,
146             meses => 'months' ,
147             dia => 'days' ,
148             dias => 'days' ,
149             hora => 'hours' ,
150             horas => 'hours' ,
151             minuto => 'minutes' ,
152             minutos => 'minutes' ,
153             semana => 'weeks',
154             semanas => 'weeks',
155             );
156             }
157              
158             sub timezone_map
159             {
160             # http://home.tiscali.nl/~t876506/TZworld.html
161             return (
162 3669     3669 1 22401 CET => 'Europe/Madrid',
163             CEST => 'Europe/Madrid',
164             CST => 'America/Cancun',
165             CDT => 'America/Cancun',
166             MST => 'America/Chihuahua',
167             MDT => 'America/Chihuahua',
168             PST => 'America/Tijuana',
169             PDT => 'America/Tijuana',
170             );
171             }
172              
173             1;
174             __END__
175              
176             =encoding utf-8
177              
178             =head1 NAME
179              
180             DateTime::Format::Flexible::lang::es - spanish language plugin
181              
182             =head1 DESCRIPTION
183              
184             You should not need to use this module directly.
185              
186             If you only want to use one language, specify the lang property when parsing a date.
187              
188             example:
189              
190             my $dt = DateTime::Format::Flexible->parse_datetime(
191             '29 de febrero de 1996' ,
192             lang => ['es']
193             );
194             # $dt is now 1996-02-29T00:00:00
195              
196             Note that this is not required, by default ALL languages are scanned when trying to parse a date.
197              
198             =head2 new
199              
200             Instantiate a new instance of this module.
201              
202             =head2 months
203              
204             month name regular expressions along with the month numbers (enero|enro|eno => 1)
205              
206             =head2 days
207              
208             day name regular expressions along the the day numbers (lunes => 1)
209              
210             =head2 day_numbers
211              
212             maps day of month names to the corresponding numbers (primero => 01)
213              
214             =head2 hours
215              
216             maps hour names to numbers (ediodia => 12:00:00)
217              
218             =head2 remove_strings
219              
220             strings to remove from the date (de as in cinco de mayo)
221              
222             =head2 parse_time
223              
224             currently does nothing
225              
226             =head2 string_dates
227              
228             maps string names to real dates (ahora => DateTime->now)
229              
230             =head2 relative
231              
232             parse relative dates (ago => hace, from => a partir de ahora, next => siguiente, last => pasado)
233              
234             =head2 math_strings
235              
236             useful strings when doing datetime math
237              
238             =head2 timezone_map
239              
240             maps unofficial timezones to official timezones for this language (PDT => America/Tijuana)
241              
242             =head1 AUTHOR
243              
244             Tom Heady
245             CPAN ID: thinc
246             Punch, Inc.
247             cpan@punch.net
248             http://www.punch.net/
249              
250             =head1 COPYRIGHT & LICENSE
251              
252             Copyright 2011 Tom Heady.
253              
254             This program is free software; you can redistribute it and/or
255             modify it under the terms of either:
256              
257             =over 4
258              
259             =item * the GNU General Public License as published by the Free
260             Software Foundation; either version 1, or (at your option) any
261             later version, or
262              
263             =item * the Artistic License.
264              
265             =back
266              
267             =head1 SEE ALSO
268              
269             F<DateTime::Format::Flexible>
270              
271             =cut