There is some math in DateTime::Event::Recurrence
that could be moved into a DateTime::Util::* module.
Most of this math is related to "week of year" and
"week of month".
I'd like to know if anyone can see some use for these
subroutines outside of DateTime::Event::Recurrence:
as_number( $datetime, unit => 'week' )
Returns an integer, just like 'epoch', but you
can select the unit of measure.
$year = as_number( $today, unit => 'year' )
# 2005
$month = as_number( $today, unit => 'month' )
# 2005*12+1
Besides the common units, it can calculate
'year_weekly' and 'month_weekly' (week of year,
week of month).
The subroutine accepts an iCal specification to
select the week algorithm. It defaults to the ISO
recommendation (week_start_day => 'mo').
$year = as_number( $today,
unit => 'year_weekly',
week_start_day => '1su' );
truncate( $datetime, to => 'year' )
Just like the DateTime->truncate method,
but this one can accept 'year_weekly' and
'month_weekly' parameters, and an optional
'week_start_day'.
round_up( $datetime, to => 'year' )
Just like "truncate", but it rounds up.
This is roughly the same as
truncate( $dt, to => 'year' )->add( years => 1 )
except that it also works with 'year_weekly' and
'month_weekly' parameters.
- Flavio S. Glock