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:58 -0700 |
commit | 19cae13fbfa17207f58c2ad44cb94f57caf64356 (patch) | |
tree | 1a1b123426e4c557e4204549759460858fb83b4c /rt/lib/RTx/Calendar.pm | |
parent | 3f20bec8cc551e82274aa79bf1eb6ad8464e1558 (diff) |
weekly view for RTx::Calendar, RT#16584
Diffstat (limited to 'rt/lib/RTx/Calendar.pm')
-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 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 { |