« Data/Sah/Coerce/perl/To_int/From_str/convert_en_dow_name_to_num.pm
↑ Summary
Sah/Schema/date/day.pm »
| 1 | package Data::Sah::Coerce::perl::To_int::From_str::convert_en_month_name_to_num; | ||
| 2 | |||
| 3 | 2 | ▶ | use 5.010001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |
| 8 | 2 | our $DATE = '2023-12-09'; # DATE | |
| 9 | 2 | our $DIST = 'Sah-Schemas-Date'; # DIST | |
| 10 | 2 | our $VERSION = '0.019'; # VERSION | |
| 11 | |||
| 12 | 1 | ▶ | sub meta { |
|
Subroutine
meta: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 13 | +{ | ||
| 14 | 1 | v => 4, | |
| 15 | summary => 'Convert English month name (e.g. Dec, april) to number (1-12)', | ||
| 16 | prio => 50, | ||
| 17 | }; | ||
| 18 | } | ||
| 19 | |||
| 20 | 1 | ▶ | sub coerce { |
|
Subroutine
coerce: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 21 | 1 | my %args = @_; | |
| 22 | |||
| 23 | 1 | my $dt = $args{data_term}; | |
| 24 | |||
| 25 | 1 | my $res = {}; | |
| 26 | 1 | my $pkg = __PACKAGE__; | |
| 27 | |||
| 28 | 1 | $res->{expr_match} = "!ref($dt)"; | |
| 29 | 1 | $res->{expr_coerce} = join( | |
| 30 | "", | ||
| 31 | "do { ", | ||
| 32 | |||
| 33 | # since this is a small translation table we put it inline, but for | ||
| 34 | # larger translation table we should move it to a separate perl module | ||
| 35 | "\$$pkg\::month_nums ||= {", | ||
| 36 | " jan=>1, january=>1, ", | ||
| 37 | " feb=>2, february=>2, ", | ||
| 38 | " mar=>3, march=>3, ", | ||
| 39 | " apr=>4, april=>4, ", | ||
| 40 | " may=>5, ", | ||
| 41 | " jun=>6, june=>6, ", | ||
| 42 | " jul=>7, july=>7, ", | ||
| 43 | " aug=>8, august=>8, ", | ||
| 44 | " sep=>9, sept=>9, september=>9, ", | ||
| 45 | " oct=>10, october=>10, ", | ||
| 46 | " nov=>11, november=>11, ", | ||
| 47 | " dec=>12, december=>12, ", | ||
| 48 | "}; ", | ||
| 49 | "\$$pkg\::month_nums->{lc $dt} || $dt; ", | ||
| 50 | "}", | ||
| 51 | ); | ||
| 52 | |||
| 53 | 1 | $res; | |
| 54 | } | ||
| 55 | |||
| 56 | 2 | 1; | |
| 57 | # ABSTRACT: Convert English month name (e.g. Dec, april) to number (1-12) | ||
| 58 | |||
| 59 | __END__ | ||