Lines 235-241
sub update {
Link Here
|
235 |
my $filtered_objects = $objects->filter_by_last_update({ |
235 |
my $filtered_objects = $objects->filter_by_last_update({ |
236 |
from => $date1, to => $date2, |
236 |
from => $date1, to => $date2, |
237 |
days|older_than => $days, min_days => $days, younger_than => $days, |
237 |
days|older_than => $days, min_days => $days, younger_than => $days, |
238 |
datetime => 1, |
|
|
239 |
}); |
238 |
}); |
240 |
|
239 |
|
241 |
You should pass at least one of the parameters: from, to, days|older_than, |
240 |
You should pass at least one of the parameters: from, to, days|older_than, |
Lines 243-249
min_days or younger_than. Make sure that they do not conflict with each other
Link Here
|
243 |
to get meaningful results. |
242 |
to get meaningful results. |
244 |
Note: from, to and min_days are inclusive! And by nature days|older_than |
243 |
Note: from, to and min_days are inclusive! And by nature days|older_than |
245 |
and younger_than are exclusive. |
244 |
and younger_than are exclusive. |
246 |
The optional parameter datetime allows datetime comparison. |
|
|
247 |
|
245 |
|
248 |
The from and to parameters can be DateTime objects or date strings. |
246 |
The from and to parameters can be DateTime objects or date strings. |
249 |
|
247 |
|
Lines 257-276
sub filter_by_last_update {
Link Here
|
257 |
unless grep { exists $params->{$_} } qw/days from to older_than younger_than min_days/; |
255 |
unless grep { exists $params->{$_} } qw/days from to older_than younger_than min_days/; |
258 |
|
256 |
|
259 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
257 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
260 |
my $method = $params->{datetime} ? 'format_datetime' : 'format_date'; |
|
|
261 |
foreach my $p ( qw/days older_than younger_than min_days/ ) { |
258 |
foreach my $p ( qw/days older_than younger_than min_days/ ) { |
262 |
next if !exists $params->{$p}; |
259 |
next if !exists $params->{$p}; |
263 |
my $dt = Koha::DateUtils::dt_from_string(); |
260 |
my $dt = Koha::DateUtils::dt_from_string(); |
264 |
my $operator = { days => '<', older_than => '<', min_days => '<=' }->{$p} // '>'; |
261 |
my $operator = { days => '<', older_than => '<', min_days => '<=' }->{$p} // '>'; |
265 |
$conditions->{$operator} = $dtf->$method( $dt->subtract( days => $params->{$p} ) ); |
262 |
$dt->subtract( days => $params->{$p} )->set( hour => 0, minute => 0, second => 0 ); |
|
|
263 |
$conditions->{$operator} = $dtf->format_datetime( $dt ); |
266 |
} |
264 |
} |
267 |
if ( exists $params->{from} ) { |
265 |
if ( exists $params->{from} ) { |
268 |
my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from}); |
266 |
my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from}); |
269 |
$conditions->{'>='} = $dtf->$method( $from ); |
267 |
$conditions->{'>='} = $dtf->format_datetime( $from ); |
270 |
} |
268 |
} |
271 |
if ( exists $params->{to} ) { |
269 |
if ( exists $params->{to} ) { |
272 |
my $to = ref($params->{to}) ? $params->{to} : dt_from_string($params->{to}); |
270 |
my $to = ref($params->{to}) ? $params->{to} : dt_from_string($params->{to}); |
273 |
$conditions->{'<='} = $dtf->$method( $to ); |
271 |
$conditions->{'<='} = $dtf->format_datetime( $to ); |
274 |
} |
272 |
} |
275 |
|
273 |
|
276 |
return $self->search( |
274 |
return $self->search( |