From 90ffea3e1048f6f75c9342c8469130ce525f2118 Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Wed, 30 Apr 2014 18:45:01 +0200 Subject: [PATCH] fix date day focus --- events.pm | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/events.pm b/events.pm index 2820c60..6cc233c 100644 --- a/events.pm +++ b/events.pm @@ -519,22 +519,35 @@ sub preprocess (@) { : gettext('Agenda'); } - my %focus_set; - if (defined $params{day} and $params{day} =~ m/^(\d+)$/) { - my ($day) = ($1); - $focus_set{day} = $day; + my %focus_set = + ( day => $params{focus}->day() + , month => $params{focus}->month() + , year => $params{focus}->year() + ); + if (defined $params{year} and $params{year} =~ m/^(\d+)$/) { + my ($year) = ($1); + $focus_set{year} = $year; } - if (defined $params{month} and $params{month} =~ m/^(\d+)$/) { + if (defined $params{month} and $params{month} =~ m/^(\d+)$/ and ($params{type} eq 'month' or $params{type} eq 'day')) { my ($month) = ($1); $focus_set{month} = $month; } - if (defined $params{year} and $params{year} =~ m/^(\d+)$/) { - my ($year) = ($1); - $focus_set{year} = $year; + if (defined $params{day} and $params{day} =~ m/^(\d+)$/ and $params{type} eq 'day') { + my ($day) = ($1); + $focus_set{day} = $day; + } + if (not defined $focus_set{day}) { + $focus_set{day} = 1; + } + else { + my $month = DateTime->new(year => $focus_set{year}, month => $focus_set{month}, day => 1); + my $last_day_of_month = $month->add(months => 1)->subtract(days => 1)->day(); + $focus_set{day} = $last_day_of_month + if $focus_set{day} > $last_day_of_month; } $params{focus}->set(%focus_set); - if (defined $params{day} and $params{day} =~ m/^([+-])(\d+)$/) { + if (defined $params{day} and $params{day} =~ m/^([+-])(\d+)$/ and $params{type} eq 'day') { my ($sign, $days) = ($1, $2); my $duration = DateTime::Duration->new(days => $days, end_of_month => 'limit'); $params{focus} @@ -542,7 +555,7 @@ sub preprocess (@) { ? $params{focus}->add_duration($duration) : $params{focus}->subtract_duration($duration); } - if (defined $params{month} and $params{month} =~ m/^([+-])(\d+)$/) { + if (defined $params{month} and $params{month} =~ m/^([+-])(\d+)$/ and ($params{type} eq 'month' or $params{type} eq 'day')) { my ($sign, $months) = ($1, $2); my $duration = DateTime::Duration->new(months => $months, end_of_month => 'limit'); $params{focus} -- 2.20.1