Today's addition is a fast DateConverter. the Date class can be used for conversion, usually by creating an object and then getting values, eg.
my $date = BOHdb::Date->new({ 'name' => 'id', 'values' => 283});
my $month = $date->get_month_num();
my $day = $date->get_standard_day();
However if that's the only reason to create the Date object, it's sorta inefficient to hit the DB in order to convert a date. For simple conversion between day_id (1-365) and month/day numbers the DateConverter class is MUCH faster. It's had the three relevant columns of the DB turned into big perl arrays and coded into the class directly, so a conversion is simply an array lookup. There are also the 2 functions in there to generate the static arrays, in case the backed data ever changes, the class is easy to update. The user only uses the 2 get functions, get_date_by_id and get_date_by_month_day. Both return a little hash with all the relevant data
{
'month' => 'October',
'day' => '10',
'id' => '283',
'month_num' => '10'
},
A quick timing test:
ok 1 - get_date_by_id returns a hashref in 0.000009 seconds
...
ok 5 - BOHdb::Date created in 0.027421 seconds
Comments