Browse Source

Bug 28585: Use the datetime_parser for handling API dates

This patchset takes the GET /patrons route as a sample usage for filtering
on date and date-time (including timestamp) fields.

It then makes Koha::Object->attributes_from_api use the DB storage
datetime parser for format the parameters correctly.

To test:

1. Apply the regression tests
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/patrons.t
=> FAIL: It doesn't find the patron when filtering by date
3. Apply this patch
4. Repeat 2
=> SUCCESS: It works now!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
master
Tomas Cohen Arazi 3 months ago
committed by Jonathan Druart
parent
commit
2e266f35f9
  1. 8
      Koha/Object.pm

8
Koha/Object.pm

@ -694,6 +694,7 @@ sub attributes_from_api {
my $params;
my $columns_info = $self->_result->result_source->columns_info;
my $dtf = $self->_result->result_source->storage->datetime_parser;
while (my ($key, $value) = each %{ $from_api_params } ) {
my $koha_field_name =
@ -708,7 +709,12 @@ sub attributes_from_api {
}
elsif ( _date_or_datetime_column_type( $columns_info->{$koha_field_name}->{data_type} ) ) {
try {
$value = dt_from_string($value, 'rfc3339');
if ( $columns_info->{$koha_field_name}->{data_type} eq 'date' ) {
$value = $dtf->format_date(dt_from_string($value, 'rfc3339'));
}
else {
$value = $dtf->format_datetime(dt_from_string($value, 'rfc3339'));
}
}
catch {
Koha::Exceptions::BadParameter->throw( parameter => $key );

Loading…
Cancel
Save