| 1 | package DateTime::Format::Flexible::lang::en; | ||||||||||||
| 2 | |||||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | sub new | ||||||||||||
| 7 | { | ||||||||||||
| 8 | 0 | ▶ | my ( $class , %params ) = @_; | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 9 | 0 | my $self = bless \%params , $class; | |||||||||||
| 10 | 0 | return $self; | |||||||||||
| 11 | } | ||||||||||||
| 12 | |||||||||||||
| 13 | sub months | ||||||||||||
| 14 | { | ||||||||||||
| 15 | return ( | ||||||||||||
| 16 | 7578 | ▶ | qr{Jan(?:uary)?}i => 1, | ||||||||||
|
Subroutine
months: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 17 | qr{Feb(?:ruary)?}i => 2, | ||||||||||||
| 18 | qr{Mar(?:ch)?}i => 3, | ||||||||||||
| 19 | qr{Apr(?:il)?}i => 4, | ||||||||||||
| 20 | qr{May}i => 5, | ||||||||||||
| 21 | qr{Jun(?:e)?}i => 6, | ||||||||||||
| 22 | qr{Jul(?:y)?}i => 7, | ||||||||||||
| 23 | qr{Aug(?:ust)?}i => 8, | ||||||||||||
| 24 | qr{Sep(?:t)?(?:ember)?}i => 9, | ||||||||||||
| 25 | qr{Oct(?:ober)?}i => 10, | ||||||||||||
| 26 | qr{Nov(?:ember)?}i => 11, | ||||||||||||
| 27 | qr{Dec(?:ember)?}i => 12, | ||||||||||||
| 28 | ); | ||||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | sub days | ||||||||||||
| 32 | { | ||||||||||||
| 33 | # order is important here, otherwise | ||||||||||||
| 34 | # we end up removing "Mon" and leaving "day" | ||||||||||||
| 35 | return [ | ||||||||||||
| 36 | 7559 | ▶ | {Monday => 1}, | ||||||||||
|
Subroutine
days: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 37 | {Mon => 1}, | ||||||||||||
| 38 | {Tuesday => 2}, | ||||||||||||
| 39 | {Tue => 2}, | ||||||||||||
| 40 | {Wednesday => 3}, | ||||||||||||
| 41 | {Wed => 3}, | ||||||||||||
| 42 | {Thursday => 4}, | ||||||||||||
| 43 | {Thurs => 4}, | ||||||||||||
| 44 | {Thu => 4}, | ||||||||||||
| 45 | {Friday => 5}, | ||||||||||||
| 46 | {Fri => 5}, | ||||||||||||
| 47 | {Saturday => 6}, | ||||||||||||
| 48 | {Sat => 6}, | ||||||||||||
| 49 | {Sunday => 7}, | ||||||||||||
| 50 | {Sun => 7}, | ||||||||||||
| 51 | ]; | ||||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | sub day_numbers | ||||||||||||
| 55 | { | ||||||||||||
| 56 | return ( | ||||||||||||
| 57 | 3765 | ▶ | q{first} => 1, | ||||||||||
|
Subroutine
day_numbers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 58 | q{second} => 2, | ||||||||||||
| 59 | q{third} => 3, | ||||||||||||
| 60 | q{fourth} => 4, | ||||||||||||
| 61 | q{fifth} => 5, | ||||||||||||
| 62 | q{sixth} => 6, | ||||||||||||
| 63 | q{seventh} => 7, | ||||||||||||
| 64 | q{eighth} => 8, | ||||||||||||
| 65 | q{ninth} => 9, | ||||||||||||
| 66 | q{tenth} => 10, | ||||||||||||
| 67 | q{eleventh} => 11, | ||||||||||||
| 68 | q{twelfth} => 12, | ||||||||||||
| 69 | q{thirteenth} => 13, | ||||||||||||
| 70 | q{fourteenth} => 14, | ||||||||||||
| 71 | q{fifteenth} => 15, | ||||||||||||
| 72 | q{sixteenth} => 16, | ||||||||||||
| 73 | q{seventeenth} => 17, | ||||||||||||
| 74 | q{eithteenth} => 18, | ||||||||||||
| 75 | q{ninteenth} => 19, | ||||||||||||
| 76 | q{twentieth} => 20, | ||||||||||||
| 77 | q{twentyfirst} => 21, | ||||||||||||
| 78 | q{twenty first} => 21, | ||||||||||||
| 79 | q{twentysecond} => 22, | ||||||||||||
| 80 | q{twenty second} => 22, | ||||||||||||
| 81 | q{twentythird} => 23, | ||||||||||||
| 82 | q{twenty third} => 23, | ||||||||||||
| 83 | q{twentyfourth} => 24, | ||||||||||||
| 84 | q{twenty fourth} => 24, | ||||||||||||
| 85 | q{twentyfifth} => 25, | ||||||||||||
| 86 | q{twenty fifth} => 25, | ||||||||||||
| 87 | q{twentysixth} => 26, | ||||||||||||
| 88 | q{twenty sixth} => 26, | ||||||||||||
| 89 | q{twentyseventh} => 27, | ||||||||||||
| 90 | q{twenty seventh} => 27, | ||||||||||||
| 91 | q{twentyninth} => 29, | ||||||||||||
| 92 | q{twenty ninth} => 29, | ||||||||||||
| 93 | q{thirtieth} => 30, | ||||||||||||
| 94 | q{thirtyfirst} => 31, | ||||||||||||
| 95 | q{thirty first} => 31, | ||||||||||||
| 96 | ); | ||||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | sub hours | ||||||||||||
| 100 | { | ||||||||||||
| 101 | return ( | ||||||||||||
| 102 | 3765 | ▶ | noon => '12:00:00', | ||||||||||
|
Subroutine
hours: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 103 | midnight => '00:00:00', | ||||||||||||
| 104 | one => '01:00:00', | ||||||||||||
| 105 | two => '02:00:00', | ||||||||||||
| 106 | three => '03:00:00', | ||||||||||||
| 107 | four => '04:00:00', | ||||||||||||
| 108 | five => '05:00:00', | ||||||||||||
| 109 | six => '06:00:00', | ||||||||||||
| 110 | seven => '07:00:00', | ||||||||||||
| 111 | eight => '08:00:00', | ||||||||||||
| 112 | nine => '09:00:00', | ||||||||||||
| 113 | ten => '10:00:00', | ||||||||||||
| 114 | eleven => '11:00:00', | ||||||||||||
| 115 | twelve => '12:00:00', | ||||||||||||
| 116 | ); | ||||||||||||
| 117 | } | ||||||||||||
| 118 | |||||||||||||
| 119 | sub remove_strings | ||||||||||||
| 120 | { | ||||||||||||
| 121 | return ( | ||||||||||||
| 122 | # remove ' of ' as in '16th of November 2003' | ||||||||||||
| 123 | 3765 | ▶ | qr{\bof\b}i, | ||||||||||
|
Subroutine
remove_strings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 124 | # remove number extensions. 1st, etc | ||||||||||||
| 125 | # these must be following a digit, which | ||||||||||||
| 126 | # is not captured. | ||||||||||||
| 127 | qr{(?<=\d)(?:st|nd|rd|th)\b,?}i, | ||||||||||||
| 128 | # next sunday | ||||||||||||
| 129 | qr{\bnext\b}i, | ||||||||||||
| 130 | ); | ||||||||||||
| 131 | } | ||||||||||||
| 132 | |||||||||||||
| 133 | sub parse_time | ||||||||||||
| 134 | { | ||||||||||||
| 135 | 3765 | ▶ | my ( $self, $date ) = @_; | ||||||||||
|
Subroutine
parse_time: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||
| 136 | |||||||||||||
| 137 | 3765 | ▶ | return $date if ( not $date =~ m{\s?at\s?}mx ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 138 | |||||||||||||
| 139 | 60 | my ( $pre, $time, $post ) = $date =~ m{\A(.+)?\s?at\s?([\d\.:]+)(.+)?\z}mx; | |||||||||||
| 140 | |||||||||||||
| 141 | # this will remove warnings if we don't have values for some of the variables | ||||||||||||
| 142 | # eg: not a date matches on the 'at' in date | ||||||||||||
| 143 | 60 | ▶ | $pre ||= q{}; | ||||||||||
|
Condition100%2/2
$pre ||= ""
MC/DC100%1/1
$pre ||= ""
$pre
Truth table100%2/2
A
A= $pre
| |||||||||||||
| 144 | 60 | ▶ | $time ||= q{}; | ||||||||||
|
Condition100%2/2
$time ||= ""
MC/DC100%1/1
$time ||= ""
$time
Truth table100%2/2
A
A= $time
| |||||||||||||
| 145 | 60 | ▶ | $post ||= q{}; | ||||||||||
|
Condition100%2/2
$post ||= ""
MC/DC100%1/1
$post ||= ""
$post
Truth table100%2/2
A
A= $post
| |||||||||||||
| 146 | |||||||||||||
| 147 | # if there is an 'at' string, we want to remove any time that was set on the date by default | ||||||||||||
| 148 | # 20050612T12:13:14 <-- T12:13:14 | ||||||||||||
| 149 | 60 | $pre =~ s{T[^\s]+}{}; | |||||||||||
| 150 | |||||||||||||
| 151 | 60 | $date = $pre . 'T' . $time . 'T' . $post; | |||||||||||
| 152 | 60 | return $date; | |||||||||||
| 153 | } | ||||||||||||
| 154 | |||||||||||||
| 155 | sub string_dates | ||||||||||||
| 156 | { | ||||||||||||
| 157 | 3765 | ▶ | my $base_dt = DateTime::Format::Flexible->base; | ||||||||||
|
Subroutine
string_dates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 158 | |||||||||||||
| 159 | return ( | ||||||||||||
| 160 | 7 | ▶ | now => sub { return $base_dt->datetime } , | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 161 | 19 | ▶ | today => sub { return $base_dt->clone->truncate( to => 'day' )->ymd } , | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 162 | 4 | ▶ | tomorrow => sub { return $base_dt->clone->truncate( to => 'day' )->add( days => 1 )->ymd }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 163 | 2 | ▶ | yesterday => sub { return $base_dt->clone->truncate( to => 'day' )->subtract( days => 1 )->ymd }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 164 | 2 | ▶ | overmorrow => sub { return $base_dt->clone->truncate( to => 'day' )->add( days => 2 )->ymd }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 165 | 1 | ▶ | allballs => sub { return $base_dt->clone->truncate( to => 'day' ) }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 166 | |||||||||||||
| 167 | 1 | ▶ | epoch => sub { return DateTime->from_epoch( epoch => 0 ) }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 168 | 0 | ▶ | '-infinity' => sub { '-infinity' }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 169 | 4 | ▶ | infinity => sub { 'infinity' }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 170 | 3765 | ); | |||||||||||
| 171 | } | ||||||||||||
| 172 | |||||||||||||
| 173 | sub relative | ||||||||||||
| 174 | { | ||||||||||||
| 175 | return ( | ||||||||||||
| 176 | # as in 3 years ago, -3 years | ||||||||||||
| 177 | 3765 | ▶ | ago => qr{\bago\b|\A\-}i, | ||||||||||
|
Subroutine
relative: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 178 | # as in 3 years from now, +3 years | ||||||||||||
| 179 | from => qr{\bfrom\b\s\bnow\b|\A\+}i, | ||||||||||||
| 180 | # as in next Monday | ||||||||||||
| 181 | next => qr{\bnext\b}i, | ||||||||||||
| 182 | # as in last Monday | ||||||||||||
| 183 | last => qr{\blast\b}i, | ||||||||||||
| 184 | ); | ||||||||||||
| 185 | } | ||||||||||||
| 186 | |||||||||||||
| 187 | sub math_strings | ||||||||||||
| 188 | { | ||||||||||||
| 189 | return ( | ||||||||||||
| 190 | 19 | ▶ | year => 'years' , | ||||||||||
|
Subroutine
math_strings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 191 | years => 'years' , | ||||||||||||
| 192 | month => 'months' , | ||||||||||||
| 193 | months => 'months' , | ||||||||||||
| 194 | day => 'days' , | ||||||||||||
| 195 | days => 'days' , | ||||||||||||
| 196 | hour => 'hours' , | ||||||||||||
| 197 | hours => 'hours' , | ||||||||||||
| 198 | minute => 'minutes' , | ||||||||||||
| 199 | minutes => 'minutes' , | ||||||||||||
| 200 | week => 'weeks', | ||||||||||||
| 201 | weeks => 'weeks', | ||||||||||||
| 202 | ); | ||||||||||||
| 203 | } | ||||||||||||
| 204 | |||||||||||||
| 205 | sub timezone_map | ||||||||||||
| 206 | { | ||||||||||||
| 207 | # http://home.tiscali.nl/~t876506/TZworld.html | ||||||||||||
| 208 | return ( | ||||||||||||
| 209 | 3765 | ▶ | EST => 'America/New_York', | ||||||||||
|
Subroutine
timezone_map: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 210 | EDT => 'America/New_York', | ||||||||||||
| 211 | CST => 'America/Chicago', | ||||||||||||
| 212 | CDT => 'America/Chicago', | ||||||||||||
| 213 | MST => 'America/Denver', | ||||||||||||
| 214 | MDT => 'America/Denver', | ||||||||||||
| 215 | PST => 'America/Los_Angeles', | ||||||||||||
| 216 | PDT => 'America/Los_Angeles', | ||||||||||||
| 217 | AKST => 'America/Juneau', | ||||||||||||
| 218 | AKDT => 'America/Juneau', | ||||||||||||
| 219 | HAST => 'America/Adak', | ||||||||||||
| 220 | HADT => 'America/Adak', | ||||||||||||
| 221 | HST => 'Pacific/Honolulu', | ||||||||||||
| 222 | ); | ||||||||||||
| 223 | } | ||||||||||||
| 224 | |||||||||||||
| 225 | 20 | 1; | |||||||||||
| 226 | __END__ | ||||||||||||
| 227 | |||||||||||||
| 228 | =encoding utf-8 | ||||||||||||
| 229 | |||||||||||||
| 230 | =head1 NAME | ||||||||||||
| 231 | |||||||||||||
| 232 | DateTime::Format::Flexible::lang::en - the english language plugin | ||||||||||||
| 233 | |||||||||||||
| 234 | =head1 DESCRIPTION | ||||||||||||
| 235 | |||||||||||||
| 236 | You should not need to use this module directly. | ||||||||||||
| 237 | |||||||||||||
| 238 | If you only want to use one language, specify the lang property when parsing a date. | ||||||||||||
| 239 | |||||||||||||
| 240 | example: | ||||||||||||
| 241 | |||||||||||||
| 242 | my $dt = DateTime::Format::Flexible->parse_datetime( | ||||||||||||
| 243 | 'Wed, Jun 10, 2009' , | ||||||||||||
| 244 | lang => ['en'] | ||||||||||||
| 245 | ); | ||||||||||||
| 246 | # $dt is now 2009-06-10T00:00:00 | ||||||||||||
| 247 | |||||||||||||
| 248 | Note that this is not required, by default ALL languages are scanned when trying to parse a date. | ||||||||||||
| 249 | |||||||||||||
| 250 | =head2 new | ||||||||||||
| 251 | |||||||||||||
| 252 | Instantiate a new instance of this module. | ||||||||||||
| 253 | |||||||||||||
| 254 | =head2 months | ||||||||||||
| 255 | |||||||||||||
| 256 | month name regular expressions along with the month numbers (Jan(?:uary)? => 1) | ||||||||||||
| 257 | |||||||||||||
| 258 | =head2 days | ||||||||||||
| 259 | |||||||||||||
| 260 | day name regular expressions along the the day numbers (Mon(?:day)? => 1) | ||||||||||||
| 261 | |||||||||||||
| 262 | =head2 day_numbers | ||||||||||||
| 263 | |||||||||||||
| 264 | maps day of month names to the corresponding numbers (first => 01) | ||||||||||||
| 265 | |||||||||||||
| 266 | =head2 hours | ||||||||||||
| 267 | |||||||||||||
| 268 | maps hour names to numbers (noon => 12:00:00) | ||||||||||||
| 269 | |||||||||||||
| 270 | =head2 remove_strings | ||||||||||||
| 271 | |||||||||||||
| 272 | strings to remove from the date (rd as in 3rd) | ||||||||||||
| 273 | |||||||||||||
| 274 | =head2 parse_time | ||||||||||||
| 275 | |||||||||||||
| 276 | searches for the string 'at' to help determine a time substring (sunday at 3:00) | ||||||||||||
| 277 | |||||||||||||
| 278 | =head2 string_dates | ||||||||||||
| 279 | |||||||||||||
| 280 | maps string names to real dates (now => DateTime->now) | ||||||||||||
| 281 | |||||||||||||
| 282 | =head2 relative | ||||||||||||
| 283 | |||||||||||||
| 284 | parse relative dates (ago => ago, from => from now, next => next, last => last) | ||||||||||||
| 285 | |||||||||||||
| 286 | =head2 math_strings | ||||||||||||
| 287 | |||||||||||||
| 288 | useful strings when doing datetime math | ||||||||||||
| 289 | |||||||||||||
| 290 | =head2 timezone_map | ||||||||||||
| 291 | |||||||||||||
| 292 | maps unofficial timezones to official timezones for this language (CST => America/Chicago) | ||||||||||||
| 293 | |||||||||||||
| 294 | |||||||||||||
| 295 | =head1 AUTHOR | ||||||||||||
| 296 | |||||||||||||
| 297 | Tom Heady | ||||||||||||
| 298 | CPAN ID: thinc | ||||||||||||
| 299 | Punch, Inc. | ||||||||||||
| 300 | cpan@punch.net | ||||||||||||
| 301 | http://www.punch.net/ | ||||||||||||
| 302 | |||||||||||||
| 303 | =head1 COPYRIGHT & LICENSE | ||||||||||||
| 304 | |||||||||||||
| 305 | Copyright 2011 Tom Heady. | ||||||||||||
| 306 | |||||||||||||
| 307 | This program is free software; you can redistribute it and/or | ||||||||||||
| 308 | modify it under the terms of either: | ||||||||||||
| 309 | |||||||||||||
| 310 | =over 4 | ||||||||||||
| 311 | |||||||||||||
| 312 | =item * the GNU General Public License as published by the Free | ||||||||||||
| 313 | Software Foundation; either version 1, or (at your option) any | ||||||||||||
| 314 | later version, or | ||||||||||||
| 315 | |||||||||||||
| 316 | =item * the Artistic License. | ||||||||||||
| 317 | |||||||||||||
| 318 | =back | ||||||||||||
| 319 | |||||||||||||
| 320 | =head1 SEE ALSO | ||||||||||||
| 321 | |||||||||||||
| 322 | F<DateTime::Format::Flexible> | ||||||||||||
| 323 | |||||||||||||
| 324 | =cut | ||||||||||||