diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-04-05 20:46:31 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-04-05 20:46:31 -0700 |
commit | b7e8cfa78c29c9cc561cafa07dbcd82ff58acb50 (patch) | |
tree | bac96851036bcd897c73fcdd30f627ebadce6163 /rt/lib | |
parent | 58c47a18e6a3cff2fe4032c08f74c922966f3f40 (diff) |
weekly view for RTx::Calendar, RT#16584
Diffstat (limited to 'rt/lib')
-rw-r--r-- | rt/lib/RTx/Calendar.pm | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/rt/lib/RTx/Calendar.pm b/rt/lib/RTx/Calendar.pm index be12707..88cfecd 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 { |