X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Flib%2FRTx%2FCalendar.pm;h=88cfecd144f30000983d6aa2782476c9817b28e1;hp=be127072c0b8067071e8776fa9f1ad5cd236381f;hb=19cae13fbfa17207f58c2ad44cb94f57caf64356;hpb=3f20bec8cc551e82274aa79bf1eb6ad8464e1558 diff --git a/rt/lib/RTx/Calendar.pm b/rt/lib/RTx/Calendar.pm index be127072c..88cfecd14 100644 --- a/rt/lib/RTx/Calendar.pm +++ b/rt/lib/RTx/Calendar.pm @@ -10,7 +10,7 @@ our $VERSION = "0.17"; RT->AddStyleSheets('calendar.css') if RT->can('AddStyleSheets'); -our @EXPORT_OK = qw( FirstDay LastDay ); +our @EXPORT_OK = qw( FirstDay LastDay LastDayOfWeek ); sub FirstDay { my ($year, $month, $matchday) = @_; @@ -37,6 +37,19 @@ sub LastDay { $day; } +sub LastDayOfWeek { + my ($year, $month, $day, $matchday) = @_; + my $set = DateTime::Set->from_recurrence( + next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) } + ); + + my $day = DateTime->new( year => $year, month => $month, day => $day ); + + $day = $set->next($day) while $day->day_of_week != $matchday; + $day; + +} + # we can't use RT::Date::Date because it uses gmtime # and we need localtime sub LocalDate {