: 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}
? $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}