- foreach my $param ( keys %{$filtered_params} ) {
- if ( $match eq 'contains' ) {
- $params->{$param} =
- { like => '%' . $filtered_params->{$param} . '%' };
- }
- elsif ( $match eq 'starts_with' ) {
- $params->{$param} = { like => $filtered_params->{$param} . '%' };
- }
- elsif ( $match eq 'ends_with' ) {
- $params->{$param} = { like => '%' . $filtered_params->{$param} };
- }
- elsif ( $match eq 'exact' ) {
- $params->{$param} = $filtered_params->{$param};
- }
- else {
- Koha::Exceptions::WrongParameter->throw(
- "Invalid value for _match param ($match)");
- }
+my $filtered_objects = $objects->filter_by_last_update
+
+days exclusive by default (will be inclusive if days_inclusive is passed and set)
+from inclusive
+to inclusive
+
+=cut
+
+sub filter_by_last_update {
+ my ( $self, $params ) = @_;
+ my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp';
+ my $days_inclusive = $params->{days_inclusive} || 0;
+ my $conditions;
+ Koha::Exceptions::MissingParameter->throw(
+ "Missing mandatory parameter: days or from or to")
+ unless exists $params->{days}
+ or exists $params->{from}
+ or exists $params->{to};
+
+ my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+ if ( exists $params->{days} ) {
+ my $dt = Koha::DateUtils::dt_from_string();
+ my $operator = $days_inclusive ? '<=' : '<';
+ $conditions->{$operator} = $dtf->format_date( $dt->subtract( days => $params->{days} ) );
+ }
+ if ( exists $params->{from} ) {
+ my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from});
+ $conditions->{'>='} = $dtf->format_date( $from );
+ }
+ if ( exists $params->{to} ) {
+ my $to = ref($params->{to}) ? $params->{to} : dt_from_string($params->{to});
+ $conditions->{'<='} = $dtf->format_date( $to );